2 # Filename: terminalserver-config
3 # Purpose: configuration program for grml-terminalserver
4 # Authors: grml-team (grml.org), (c) Michael Gebetsroither <gebi@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
14 #. /etc/grml/sysexits-sh
24 # this file holds all variable definitions
25 SHARED_PROG_VARS_="/usr/share/grml-terminalserver/shared_prog_vars"
26 isExistent $SHARED_PROG_VARS_ die
29 # variables used in the config file for grml-terminalserver
50 Usage: "$PROG_NAME__" [OPTIONS] <command>
52 $PROG_NAME__ is the config program for the terminalserver coming with grml.
57 interactive Interactive Configuration of the grml-terminalserver
58 initrd Only create the initrd
59 clean Remove all configfiles created during user configuration
60 <default> interactive mode
63 -v verbose (show what is going on, v++)
74 if [ -f $CONF_FILE_ ]; then
75 mv -fb $CONF_FILE_ ${CONF_FILE_}-old
79 cat <<EOT > $CONF_FILE_
80 # GRML TERMINAL-SERVER CONFIG
82 INTERFACE_="$INTERFACE_"
87 NAMESERVERS_="$NAMESERVERS_"
88 IPRANGE_FROM_="$IPRANGE_FROM_"
89 IPRANGE_TO_="$IPRANGE_TO_"
91 BOOT_ARGS_="$BOOT_ARGS_"
92 NAT_INTERFACE_="$NAT_INTERFACE_"
95 notice "config successfully safed to \"$CONF_FILE_\""
99 # AUTOMATIC CONFIGURATION {{{
100 function checkParamArg
102 local param_name="$1"
105 #eval "echo $`echo $test`"
106 echo $arg |grep "^[-|+]" &>/dev/null || return
108 die "Argument from $param_name looks like another parameter \"$arg\"" 1
111 function actionAutoconf
113 checkParamArg "-i" "$interface_"
118 function actionMkInitrd
121 echo "Installing initrd $PATH_/minirt26.gz:"
122 if isExistent "$PATH_/minirt26.gz" ; then
124 echo "$PATH_/minirt26.gz exists already, nothing to do"
128 # until we have a stable file location API let's use
129 # an according heuristic
130 for file in "$(find /live/image/boot -name initrd.gz)"; do
131 dir="$(dirname $file)"
132 if file "$dir"/linux26 | grep -q "$(uname -r)" ; then
133 cp "$dir"/initrd.gz "$PATH_"/minirt26.gz
142 # INTERACTIVE CONFIGURATION {{{
144 function actionInteractive
148 dprint "running in interactive mode"
150 local card_title_="Choose network device connected to client network"
151 local card_message_="Available network devices:"
152 local iprange_title_="IP Address range for clients"
153 local iprange_message_="
154 Please enter the desired IP-Range of addresses that should be allocated by clients, separated by a single space.
157 192.168.0.101 192.168.0.200
159 for addresses from 192.168.0.101 to (and including) 192.168.0.200.
162 local runconfig_title_="Networkcard config"
163 local runconfig_message_="Would you like to configure your interfaces now?"
165 # on witch interfaces should we listen
166 local netdevices_="$(grep -ve 'lo:' -ve 'Inter-|' -ve 'face |bytes' /proc/net/dev | awk -F: '{print $1}')"
167 local device_list_=""
168 for INTERFACE_ in $netdevices_; do device_list_="$device_list_ ${INTERFACE_} Networkcard_${INTERFACE_##eth}"; done
170 $DIALOG_ --backtitle "$BACK_TITLE_" --title "$card_title_" --menu "$card_message_" \
171 0 0 18 $device_list_ 2>"$TMP_" || warn "could not get network-interface"
172 INTERFACE_="$(<$TMP_)" ; echo -n "" >"$TMP_"
175 IP_=`netGetIp "$INTERFACE_" warn`
176 NETMASK_=`netGetNetmask "$INTERFACE_" warn`
177 netValidIp "$IP_" warn && break
178 $DIALOG_ --backtitle "$BACK_TITLE_" --title "$runconfig_title_" --yesno "$runconfig_message_" 18 45 && \
179 netcardconfig || die "Could not get interface" $?
182 IPRANGE_FROM_=`execute "ipcalc -nb $IP_/$NETMASK_" warn |awk '/HostMin/{print $2}'`
183 IPRANGE_TO_=`execute "ipcalc -nb $IP_/$NETMASK_" warn |awk '/HostMax/{print $2}'`
184 NETWORK_=`execute "ipcalc -nb $IP_/$NETMASK_" warn |awk '/Network:/{print $2}'`
185 NETWORK_=${NETWORK_%/*}
187 while [ -z "$IPRANGE_FROM_" -o -z "$IPRANGE_TO_" -o -z "$iprange_" ]; do
188 iprange_="$IPRANGE_FROM_ $IPRANGE_TO_"
190 $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$iprange_title_ ($INTERFACE_=$IP_/$NETMASK_)" \
191 --inputbox "$iprange_message_" 18 75 "$iprange_" 2>"$TMP_" || die "problems getting network range" $?
194 IPRANGE_FROM_="${iprange_%% *}"
195 IPRANGE_TO_="${iprange_##* }"
197 for i in "$IPRANGE_FROM_" "$IPRANGE_TO_"; do
198 netValidIp "$i" warn || iprange_=""
202 NAMESERVERS_=`netGetNameservers warn`
203 GW_=`netGetDefaultGateway warn`
204 GW_DEV_=`/sbin/ip route get "$GW_" | awk '{ print $3; exit; }'`
205 if [ "$GW_DEV_" != "$INTERFACE_" ] && [ "$GW_DEV_" != "" ]; then
206 # GW_DEV_ of server is not the same device as the one serviced by dhcpd
207 # so it doesn't make sense to provide the GW_ address to the clients
209 local do_nat_title_="Network Address Translation"
210 local do_nat_message_="
211 Do you want to set up NAT so that clients booting from this
212 grml-terminalserver can use this machine also as gateway to
215 $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$do_nat_title_" --yesno "$do_nat_message_" 15 75 || \
217 if [ "$do_nat_" = "YES" ]; then
218 # user wants NAT, we give the clients the server address as
221 NAT_INTERFACE_="$GW_DEV_"
223 # no NAT, no sensible gateway
230 #local OPT_IPTABLES_="yes"
231 #local OPT_SSH_="yes"
232 #local OPT_DISTCC_="yes"
235 local OPTIONS_TITLE_="Options"
236 local OPTIONS_MESSAGE_="Please give the appropriate options you want the clients to use:
238 grml2hd - Make a non-interactive remote installation
243 # local OPTIONS_MESSAGE_="Please give the appropriate options you want the clients to use:
245 #iptables - Only the server should be able to access the clients
246 #ssh - A ssh-key will be created on the server and distributed to the clients
247 #distcc - You want to use the clients as compile-farm (ssh options recommned)
251 local OPT_IPTABLES_DESC_="Start iptables on the clients"
252 local OPT_SSH_DESC_="Start ssh on the clients"
253 local OPT_DISTCC_DESC_="Start distcc on the clients"
254 local OPT_GRML2HD_DESC_="Remote install grml on the network clients"
255 # dialog options (enable if implemented)
256 #iptables "$OPT_IPTABLES_DESC_" off \
257 #ssh "$OPT_SSH_DESC_" off \
258 #distcc "$OPT_DISTCC_DESC_" off \
260 $DIALOG_ --clear --separate-output --backtitle "$BACK_TITLE_" --title "$OPTIONS_TITLE_" --checklist "$OPTIONS_MESSAGE_" 25 80 10 \
261 grml2hd "$OPT_GRML2HD_DESC_" off \
262 2>$TMP_ || die "could not get terminalserver options" $?
263 while read tmp_option_; do
264 OPTIONS_="$OPTIONS_ $tmp_option_"
268 for i in $OPTIONS_; do
270 grml2hd) optGrml2Hd || return 1 ;;
275 local OPTIONS_BOOTARG_MESSAGE_="Here you can add additional boot arguments for the clients seperated by spaces:
277 Quite usefull examples:
279 ssh=<pw> - Start ssh server and set password of user grml to pw
280 services=<1,2,3> - Execute /etc/init.d/{1,2,3} start
281 console=ttyS0,9600n8 - Initialise serial console
286 $DIALOG_ --clear --no-collapse --backtitle "$BACK_TITLE_" --title "$OPTIONS_TITLE_" --inputbox "$OPTIONS_BOOTARG_MESSAGE_" 0 0\
287 2>$TMP_ || die "problems getting additional boot arguments"
288 BOOT_ARGS_="$BOOT_ARGS_ $(<$TMP_)"
292 notice "GRML terminalserver successfully configured"
296 # OPTIONS GETTING DIALOG {{{
299 local GRML2HD_TITLE_='Grml2hd options dialog'
301 local options_='BOOT_IMAGE=grml2hd'
303 # get partition to install grml2hd on
304 OPTIONS_PARTITION_MSG_='Please specify the target partition where to install grml'
305 PARTITION_TITLE_='Partition selection'
307 $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$PARTITION_TITLE_" --inputbox \
308 "$OPTIONS_PARTITION_MSG_" 0 75 '/dev/hda1' 2>$TMP_ || die "problems getting partition"
309 tmp_="partition=$(<$TMP_)"
310 options_="$options_ $tmp_"
312 # get filesystem type
313 OPTION_FS_TYPE_='Please specify the filesystem type'
314 FS_TITLE_='Filesystem selection'
316 $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$FS_TITLE_" --inputbox \
317 "$OPTION_FS_TYPE_" 0 75 'ext3' 2>$TMP_ || die "problems getting filesystem type"
318 tmp_="filesystem=$(<$TMP_)"
319 options_="$options_ $tmp_"
321 # get where to save mbr
322 OPTION_MBR_='Please specify the location where to save the mbr'
323 MBR_TITLE_='Select location of mbr'
325 $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$MBR_TITLE_" --inputbox \
326 "$OPTION_MBR_" 0 75 '/dev/hda' 2>$TMP_ || die "problems getting location where to write mbr"
328 options_="$options_ $tmp_"
331 OPTION_USER_='Who should be the first user on the system'
332 USER_TITLE_='User selection'
334 $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$USER_TITLE_" --inputbox \
335 "$OPTION_USER_" 0 75 'grml' 2>$TMP_ || die "problems getting first user of system"
336 tmp_="user=$(<$TMP_)"
337 options_="$options_ $tmp_"
339 BOOT_ARGS_="$options_"
344 function removeTmpFiles
346 execute "rm -f $TMP_" warn
351 for i in dhcpd.conf minirt26.gz; do
352 execute "rm -f $PATH_/$i*"
355 for i in $CARDS_DETECTED_BY_DISCOVER $CONF_FILE_; do
366 while getopts "i:hv" opt; do
368 i) interface_=$OPTARG ;;
369 h) printUsage; exit ;;
370 v) let verbose_=$verbose_+1 ;;
371 ?) printUsage; exit 64 ;;
374 shift $(($OPTIND - 1)) # set ARGV to the first not parsed commandline parameter
378 help) printUsage; exit 0 ;;
381 checkRoot die 'You have to be root to use this program'
384 execute "mkdir -p $PATH_" die
386 TMP_=`mktemp -t grml-terminalserver-config.XXXXXX` || die "Could not create tmpfile" $?
387 setExitFunction 'removeTmpFiles'
394 # MODULES_PATH_ROOT_DIFF_
397 if [[ $MODULES_PATH_ == "" || $KERNEL_VERSION_ == "" || $ORIGINAL_INITRD_ == "" ]]; then
398 warn "MODULES_PATH_=\"$MODULES_PATH_\" \
399 KERNEL_VERSION_=\"$KERNEL_VERSION_\" \
400 ORIGINAL_INITRD_=\"$ORIGINAL_INITRD_\""
401 die "False configuration, please update $CONFIG_"
406 interactive) actionInteractive ;;
407 initrd) actionMkInitrd ;;
408 clean) actionClean ;;
409 *) actionInteractive ;;
414 ################################################################################
415 # vim:foldmethod=marker tabstop=2 expandtab shiftwidth=2