grml-terminalserver-config: fix problem with unclosed ]
[grml-terminalserver.git] / grml-terminalserver-config
1 #!/bin/sh
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 # Latest change: Die Mär 27 13:34:47 CEST 2007 [mika]
8 ################################################################################
9
10
11 ###
12 ### __INCLUDES
13 ###
14 . /etc/grml/sh-lib
15 #. /etc/grml/sysexits-sh
16
17
18
19 ###
20 ### __VARIABLES
21 ###
22
23 verbose_=0
24
25 # this file holds all variable definitions
26 SHARED_PROG_VARS_="/usr/share/grml-terminalserver/shared_prog_vars"
27 isExistent $SHARED_PROG_VARS_ die
28 . $SHARED_PROG_VARS_
29
30 # variables used in the config file for grml-terminalserver
31 INTERFACE_=""
32 IP_=""
33 NETMASK_=""
34 GW_=""
35 NAMESERVERS_=""
36 IPRANGE_FROM_=""
37 IPRANGE_TO_=""
38 NETWORK_=""
39 OPTIONS_=""
40 BOOT_ARGS_=""
41 NAT_INTERFACE_=""
42
43
44 ###
45 ### __FUNCTIONS
46 ###
47
48 function printUsage
49 {
50   cat <<EOT
51 Usage: "$PROG_NAME__" [OPTIONS] <command>
52
53 $PROG_NAME__ is the config program for the terminalserver coming with grml.
54
55 COMMANDS:
56
57    help             This help text
58    interactive      Interactive Configuration of the grml-terminalserver
59    grubConf <file>  Configure grub and create boot-image (for non-PXE NICs)
60                       Read modules for grub from file if given.
61    grubConfWrite    Configure grub and write image to floppy disk
62    grubWrite        Write compiled grub-image to floppy disk
63    grubMultiWrite   batchwrite grub-image to floppy disk
64    initrd           Only create the initrd
65    clean            Remove all configfiles created during user configuration
66    <default>        interactive mode
67
68 OPTIONS:
69    -v               verbose (show what is going on, v++)
70    -h               this help text
71
72 EOT
73 }
74
75
76 function writeConfig
77 {
78   local date_=""
79
80   if [ -f $CONF_FILE_ ]; then
81     mv -fb $CONF_FILE_ ${CONF_FILE_}-old
82   fi
83
84   date_=`date`
85   cat <<EOT > $CONF_FILE_
86 # GRML TERMINAL-SERVER CONFIG
87 # created on "$date_"
88 INTERFACE_="$INTERFACE_"
89 IP_="$IP_"
90 NETWORK_="$NETWORK_"
91 NETMASK_="$NETMASK_"
92 GW_="$GW_"
93 NAMESERVERS_="$NAMESERVERS_"
94 IPRANGE_FROM_="$IPRANGE_FROM_"
95 IPRANGE_TO_="$IPRANGE_TO_"
96 OPTIONS_="$OPTIONS_"
97 BOOT_ARGS_="$BOOT_ARGS_"
98 NAT_INTERFACE_="$NAT_INTERFACE_"
99
100 EOT
101   notice "config successfully safed to \"$CONF_FILE_\""
102 }
103
104
105 # AUTOMATIC CONFIGURATION  {{{
106 function checkParamArg
107 {
108   local param_name="$1"
109   local arg="$2"
110
111   #eval "echo $`echo $test`"
112   echo $arg |grep "^[-|+]" &>/dev/null || return
113
114   die "Argument from $param_name looks like another parameter \"$arg\"" 1
115 }
116
117 function actionAutoconf
118 {
119   checkParamArg "-i" "$interface_"
120 }
121 # }}}
122
123
124 # INITRD {{{
125 function actionMkInitrd
126 {
127   echo -n "Creating initrd $PATH_/minirt26.gz: "
128   isExistent "$PATH_/minirt26.gz" && echo && echo "$PATH_/minirt26.gz exists already, skipping initrd creation" && return 0
129   if [ -e '/live/cow' ]; then
130     mkInitrdNew
131   else
132     mkInitrd
133   fi
134   echo done
135 }
136
137 function mkInitrdNew
138 {
139   set -e
140   local cfg_="/etc/initramfs-tools/initramfs.conf"
141   local tmp_="`mktemp -t terminalserver__initramfsbk.XXXXXX`"
142   cp $cfg_ $tmp_
143   sed -i 's/^MODULES=.*/MODULES=netboot/' $cfg_
144   update-initramfs -u -t
145   mv $tmp_ $cfg_
146
147   local initrd_="/boot/initrd.img-$KERNEL_VERSION_"
148   mv $initrd_ $PATH_/minirt26.gz
149   mv ${initrd_}.bak $initrd_
150   set +e
151 }
152
153 function mkInitrd
154 {
155   TMP_DIR_=`mktemp -td terminalserver_initrd.XXXXXX`
156   local i=''
157   local tmp_loopname=''
158
159   # copying original initrd into $INITRD
160   execute "rm -r $INITRD_" 2>/dev/null
161   execute "cp $ORIGINAL_INITRD_ $TMP_DIR_/minirt26.gz" warn || return 1
162   execute "mkdir -p $INITRD_" warn || return 1
163   execute "mkdir -p $PATH_/mini-root.orig" warn || return 1
164   execute "gunzip $TMP_DIR_/minirt26.gz" warn || return 1
165   tmp_loopname=`findNextFreeLoop die`
166   execute "mount -o loop=$tmp_loopname $TMP_DIR_/minirt26 $PATH_/mini-root.orig " warn || return 1
167   execute "cp -a $PATH_/mini-root.orig/* $INITRD_" warn || return 1
168   execute "umount $PATH_/mini-root.orig" warn || return 1
169   losetup -d $tmp_loopname &>/dev/null
170   tmp_loopname=''
171   execute "rmdir $PATH_/mini-root.orig" warn || return 1
172   execute "rm $TMP_DIR_/minirt26" warn || return 1
173
174   # implanting my initrd changes into the original initrd
175
176   # copy programs, check if there are already links with this name to busybox
177   for i in $USR_SHARE_/timeout $USR_SHARE_/udhcp-config.sh $USR_SHARE_/cdir $USR_SHARE_/rdir; do
178     tmp_name_="${i##*/}"
179     isNotExistent "$INITRD_/static/$tmp_name_" eprint || execute "rm $INITRD_/static/$tmp_name_"
180     cp $i "$INITRD_/static/$tmp_name_"
181   done
182   cp $USR_SHARE_/linuxrc $INITRD_/
183   mkdir -p $INITRD_/mylib
184   mkdir -p $INITRD_/myusr
185
186   #
187   # which modules should i put into the ramdisk
188   #
189
190   # find *all* network drivers, but do not include wlan/pcmcia/... related ones
191   # blacklist: proteon and depca as they seem to cause problems with udevsettle
192   find ${MODULES_PATH_}/${KERNEL_VERSION_}/kernel/drivers/net/ -name \*.ko | \
193     grep -v 'wireless\|wan\|hamradio\|wlan\|ppp\|irda\|pcmcia\|depca\|proteon' | \
194       sed 's#.*./## ; s#\.ko##' | sort | uniq > $CARDS_DETECTED_BY_DISCOVER
195
196   local modules="`cat $CARDS_DETECTED_BY_DISCOVER |xargs` af_packet"
197   local modules_dep=""
198
199   # get paths of modules + paths of all dependent modules
200   echo -n "" >"$TMP_"
201   for i in $modules; do
202     tmp_=`awk -F: '{if($1~/'"$i".ko'/) {print $0}}' $MODULES_PATH_/$KERNEL_VERSION_/modules.dep`
203     echo "${tmp_%%:*}"
204     # FIXME ugly sed hack :(
205     echo "${tmp_#*:}" | xargs -n1 echo | sed 's/://'
206   done \
207   | sort | uniq | while read module relax; do
208     if [ -n "$module" ]; then
209       echo "$module" >> $TMP_
210     fi
211   done
212
213   # copy modules + dependend modules into ramdisk
214   local mod_path_="$INITRD_/mylib/modules/$KERNEL_VERSION_"
215   local tmp_dst_path_="$mod_path_/kernel"
216   mkdir -p $tmp_dst_path_
217   cat $TMP_ |sort |uniq |while read module; do
218     local tmp_path=${module#*/kernel/}
219     tmp_path=$tmp_dst_path_/${tmp_path%/*.ko}
220     local module_path=$tmp_path/${module##/*/}
221
222     isNotExistent "$tmp_path" dprint && mkdir -p "$tmp_path"
223     isNotExistent "$module_path" dprint && cp "$MODULES_PATH_ROOT_DIFF_/$module" "$module_path"
224   done
225
226   # copying additional modules
227   for i in fs/nfs/nfs.ko net/sunrpc/sunrpc.ko fs/lockd/lockd.ko net/packet/af_packet.ko; do
228     local tmp_path="$tmp_dst_path_/${i%/*}"
229     mkdir -p $tmp_path
230     cp $MODULES_PATH_/$KERNEL_VERSION_/kernel/$i "$tmp_path"
231   done
232
233   # copying modules.*
234   cp $MODULES_PATH_/$KERNEL_VERSION_/modules.dep $mod_path_
235   cp $MODULES_PATH_/$KERNEL_VERSION_/modules.alias $mod_path_
236   #grep "^\/lib\/modules\/$KERNEL_VERSION_\/kernel\/" $MODULES_PATH_/$KERNEL_VERSION_/modules.dep |\
237   #  sed "s/\/lib\/modules\/$KERNEL_VERSION_\/kernel\//\/modules\//g" > $mod_path_/modules.dep
238
239   # put everything into the new initrd
240   local tmp_size=`du -s $INITRD_ |awk '{print $1}'`   # in kB
241   let tmp_size=$tmp_size+1000
242   local max_size=24000
243   if (( $tmp_size >= $max_size )); then
244     warn "Your initrd is $tmp_size kByte large => TOO BIG (should be <= ${max_size}kB)"
245     warn "Please remove a few modules from $CARDS_DETECTED_BY_DISCOVER or edit $INITRD_ manually"
246     return 1
247   fi
248
249   execute "dd if=/dev/zero of=$TMP_DIR_/minirt26 bs=${tmp_size}k count=1 &>/dev/null" warn || \
250     warn "could not create filesystem image"
251
252   tmp_loopname=`findNextFreeLoop die`
253   execute "losetup $tmp_loopname $TMP_DIR_/minirt26" die
254   execute "mke2fs -L \"GRML NETINIT\" -b 1024 -N 8192 -O none -F -q -m 0 $tmp_loopname" warn
255
256   execute "mkdir $PATH_/minirt26_mountp" warn
257   execute "mount $tmp_loopname $PATH_/minirt26_mountp" warn
258   execute "cp -a $INITRD_/* $PATH_/minirt26_mountp" warn
259   execute "umount $PATH_/minirt26_mountp" warn
260   execute "losetup -d $tmp_loopname &>/dev/null" warn
261   execute "rmdir $PATH_/minirt26_mountp" warn
262   execute "gzip -9 $TMP_DIR_/minirt26" warn
263   execute "rm -r $INITRD_" warn
264   execute "mv $TMP_DIR_/minirt26.gz $PATH_"
265   execute "rm -fr $TMP_DIR_"
266 }
267 # }}}
268
269
270 # INTERACTIVE CONFIGURATION  {{{
271
272 function actionInteractive
273 {
274   local i=""
275
276   dprint "running in interactive mode"
277
278   local card_title_="Choose network device connected to client network"
279   local card_message_="Available network devices:"
280   local iprange_title_="IP Address range for clients"
281 local iprange_message_="
282 Please enter the desired IP-Range of addresses that should be allocated by clients, separated by a single space.
283
284 Example:
285           192.168.0.101 192.168.0.200
286
287 for addresses from 192.168.0.101 to (and including) 192.168.0.200.
288
289 "
290   local runconfig_title_="Networkcard config"
291   local runconfig_message_="Would you like to configure your interfaces now?"
292   local grub_title_="Grub configuration"
293   local grub_message_="Do you have any NON-PXE network cards you would like to boot from?"
294
295   # on witch interfaces should we listen
296   local netdevices_="$(grep -ve 'lo:' -ve 'Inter-|' -ve 'face |bytes' /proc/net/dev | awk -F: '{print $1}')"
297   local device_list_=""
298   for INTERFACE_ in $netdevices_; do device_list_="$device_list_ ${INTERFACE_} Networkcard_${INTERFACE_##eth}"; done
299     echo -n "" >"$TMP_"
300     $DIALOG_ --backtitle "$BACK_TITLE_" --title "$card_title_" --menu "$card_message_" \
301       0 0 18 $device_list_ 2>"$TMP_" || warn "could not get network-interface"
302   INTERFACE_="$(<$TMP_)" ; echo -n "" >"$TMP_"
303
304   while true; do
305     IP_=`netGetIp "$INTERFACE_" warn`
306     NETMASK_=`netGetNetmask "$INTERFACE_" warn`
307     netValidIp "$IP_" warn && break
308     $DIALOG_ --backtitle "$BACK_TITLE_" --title "$runconfig_title_" --yesno "$runconfig_message_" 18 45 && \
309       netcardconfig || die "Could not get interface" $?
310   done
311
312   IPRANGE_FROM_=`execute "ipcalc -nb $IP_/$NETMASK_" warn |awk '/HostMin/{print $2}'`
313   IPRANGE_TO_=`execute "ipcalc -nb $IP_/$NETMASK_" warn |awk '/HostMax/{print $2}'`
314   NETWORK_=`execute "ipcalc -nb $IP_/$NETMASK_" warn |awk '/Network:/{print $2}'`
315   NETWORK_=${NETWORK_%/*}
316   local iprange_=""
317   while [ -z "$IPRANGE_FROM_" -o -z "$IPRANGE_TO_" -o -z "$iprange_" ]; do
318     iprange_="$IPRANGE_FROM_ $IPRANGE_TO_"
319     echo -n "" >"$TMP_"
320     $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$iprange_title_ ($INTERFACE_=$IP_/$NETMASK_)" \
321       --inputbox "$iprange_message_" 18 75 "$iprange_" 2>"$TMP_" || die "problems getting network range" $?
322
323     iprange_="$(<$TMP_)"
324     IPRANGE_FROM_="${iprange_%% *}"
325     IPRANGE_TO_="${iprange_##* }"
326
327     for i in "$IPRANGE_FROM_" "$IPRANGE_TO_"; do
328       netValidIp "$i" warn || iprange_=""
329     done
330   done
331
332   NAMESERVERS_=`netGetNameservers warn`
333   GW_=`netGetDefaultGateway warn`
334   GW_DEV_=`/sbin/ip route get "$GW_" | awk '{ print $3; exit; }'`
335   if [ "$GW_DEV_" != "$INTERFACE_" ] && [ "$GW_DEV_" != "" ]; then
336     # GW_DEV_ of server is not the same device as the one serviced by dhcpd
337     # so it doesn't make sense to provide the GW_ address to the clients
338     local do_nat_="YES"
339     local do_nat_title_="Network Address Translation"
340     local do_nat_message_="
341 Do you want to set up NAT so that clients booting from this
342 grml-terminalserver can use this machine also as gateway to
343 the internet?"
344
345     $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$do_nat_title_" --yesno "$do_nat_message_" 15 75 || \
346       do_nat_="NO"
347     if [ "$do_nat_" = "YES" ]; then
348       # user wants NAT, we give the clients the server address as
349       # gateway as well
350       GW_="$IP_"
351       NAT_INTERFACE_="$GW_DEV_"
352     else
353       # no NAT, no sensible gateway
354       GW_=""
355       NAT_INTERFACE_=""
356     fi
357   fi
358
359
360   # grub
361   echo -n "" >"$TMP_"
362   local grub_write_="YES"
363   $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$grub_title_" --yesno "$grub_message_" 5 75 && \
364     grubConfig || grub_write_="NO"
365
366
367   # get options
368   #local OPT_IPTABLES_="yes"
369   #local OPT_SSH_="yes"
370   #local OPT_DISTCC_="yes"
371   #local OPT_SQUID_=""
372
373   local OPTIONS_TITLE_="Options"
374   local OPTIONS_MESSAGE_="Please give the appropriate options you want the clients to use:
375
376 grml2hd   - Make a non-interactive remote installation
377
378
379
380 "
381 #  local OPTIONS_MESSAGE_="Please give the appropriate options you want the clients to use:
382 #
383 #iptables  - Only the server should be able to access the clients
384 #ssh       - A ssh-key will be created on the server and distributed to the clients
385 #distcc    - You want to use the clients as compile-farm (ssh options recommned)
386 #
387 #"
388
389   local OPT_IPTABLES_DESC_="Start iptables on the clients"
390   local OPT_SSH_DESC_="Start ssh on the clients"
391   local OPT_DISTCC_DESC_="Start distcc on the clients"
392   local OPT_GRML2HD_DESC_="Remote install grml on the network clients"
393   # dialog options (enable if implemented)
394   #iptables "$OPT_IPTABLES_DESC_" off \
395   #ssh "$OPT_SSH_DESC_" off \
396   #distcc "$OPT_DISTCC_DESC_" off \
397   echo -n "" >"$TMP_"
398   $DIALOG_ --clear --separate-output --backtitle "$BACK_TITLE_" --title "$OPTIONS_TITLE_" --checklist "$OPTIONS_MESSAGE_" 25 80 10 \
399   grml2hd "$OPT_GRML2HD_DESC_" off \
400     2>$TMP_ || die "could not get terminalserver options" $?
401   while read tmp_option_; do
402     OPTIONS_="$OPTIONS_ $tmp_option_"
403   done <$TMP_
404
405   # parse options
406   for i in $OPTIONS_; do
407     case "$i" in
408       grml2hd)  optGrml2Hd || return 1 ;;
409     esac
410   done
411
412   echo -n "" >"$TMP_"
413   local OPTIONS_BOOTARG_MESSAGE_="Here you can add additional boot arguments for the clients seperated by spaces:
414
415 Quite usefull examples:
416
417 ssh=<pw>              - Start ssh server and set password of user grml to pw
418 services=<1,2,3>      - Execute /etc/init.d/{1,2,3} start
419 console=ttyS0,9600n8  - Initialise serial console
420 startx                - Boot into X
421
422
423 "
424   $DIALOG_ --clear --no-collapse --backtitle "$BACK_TITLE_" --title "$OPTIONS_TITLE_" --inputbox "$OPTIONS_BOOTARG_MESSAGE_" 0 0\
425     2>$TMP_ || die "problems getting additional boot arguments"
426   BOOT_ARGS_="$BOOT_ARGS_ $(<$TMP_)"
427
428   writeConfig
429   if [ $grub_write_ == "YES" ]; then
430     grubWrite
431   fi
432   actionMkInitrd
433   notice "GRML terminalserver successfully configured"
434 }
435 # }}}
436
437 # OPTIONS GETTING DIALOG {{{
438 function optGrml2Hd
439 {
440   local GRML2HD_TITLE_='Grml2hd options dialog'
441   local tmp_=''
442   local options_='BOOT_IMAGE=grml2hd'
443
444   # get partition to install grml2hd on
445   OPTIONS_PARTITION_MSG_='Please give me the target partition where to install grml'
446   PARTITION_TITLE_='Partition selection'
447   echo -n "" >"$TMP_"
448   $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$PARTITION_TITLE_" --inputbox \
449     "$OPTIONS_PARTITION_MSG_" 0 75 '/dev/hda1' 2>$TMP_ || die "problems getting partition"
450   tmp_="partition=$(<$TMP_)"
451   options_="$options_ $tmp_"
452
453   # get filesystem type
454   OPTION_FS_TYPE_='Please give me the filesystem type'
455   FS_TITLE_='Filesystem selection'
456   echo -n "" >"$TMP_"
457   $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$FS_TITLE_" --inputbox \
458   "$OPTION_FS_TYPE_" 0 75 'ext3' 2>$TMP_ || die "problems getting filesystem type"
459   tmp_="filesystem=$(<$TMP_)"
460   options_="$options_ $tmp_"
461
462   # get where to save mbr
463   OPTION_MBR_='Please give me the location where to save the mbr'
464   MBR_TITLE_='Select location of mbr'
465   echo -n "" >"$TMP_"
466   $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$MBR_TITLE_" --inputbox \
467     "$OPTION_MBR_" 0 75 '/dev/hda' 2>$TMP_ || die "problems getting location where to write mbr"
468   tmp_="mbr=$(<$TMP_)"
469   options_="$options_ $tmp_"
470
471   # get first user
472   OPTION_USER_='Who should be the first user on the system'
473   USER_TITLE_='User selection'
474   echo -n "" >"$TMP_"
475   $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$USER_TITLE_" --inputbox \
476     "$OPTION_USER_" 0 75 'grml' 2>$TMP_ || die "problems getting first user of system"
477   tmp_="user=$(<$TMP_)"
478   options_="$options_ $tmp_"
479
480   BOOT_ARGS_="$options_"
481 }
482 #}}}
483
484 # GRUB CONFIG  {{{
485 function grubConfig
486 {
487   local tmp_=`mktemp -td terminalserver_grub.XXXXXX` || warn "could not create tmp file for grubConfig"
488   if [ -z "$tmp_" ]; then return 1; fi
489
490   grubConfigWork "$tmp_" "$1"
491   local ret_=$?
492   execute "rm -rf $tmp_" warn
493
494   return $ret_
495 }
496
497 function grubConfigWork
498 {
499   local tmp_="$1"
500
501   local grub_title_="Grub configuration"
502   local grub_nic_message_="
503 Give me the types of network cards you would want to boot from.
504 If you networkcard is already listed press <OK>!
505
506 WARNING: DON't add all NIC's, grub could possibly stop working!!"
507   local nics_=""
508
509   if [[ $2 == "" ]]; then
510     while read module_ desc_ mode_; do
511       nics_="$nics_ $module_ $desc_ $mode_"
512     done < $GRUB_NIC_CONF_
513
514     echo -n "" >$TMP_
515     local cmd_line_=""
516     $DIALOG_ --clear --separate-output --backtitle "$BACK_TITLE_" --title "$grub_title_" --checklist \
517       "$grub_nic_message_" 10 70 0 $nics_ 2>$TMP_
518     local ret_=$?
519     if [[ $ret_ -ne 0 || `wc -l <$TMP_` -eq 0 ]]; then
520       echo $ret_
521       warn "you should give me your specified NICs but didn't => DEFAULT will be used"
522       awk '/ on$/{print $1}' $GRUB_NIC_CONF_ >$TMP_
523     fi
524   else
525     cat $2 >$TMP_
526   fi
527   while read module_; do
528     cmd_line_="$cmd_line_ --enable-$module_"
529   done < $TMP_
530
531   echo "\"$cmd_line_\""
532
533   execute "tar xzf $GRUB_SOURCE_ -C $tmp_" warn || return 1
534   execute "cd $tmp_/grub*" warn || return 1
535 cat >preset-menu <<EOT
536 # Set up the serial terminal, first of all.
537 #serial --unit=0 --speed=19200
538 #terminal --timeout=0 serial
539
540 # Initialize the network.
541 #dhcp --with-configfile
542 #bootp --with-configfile
543 dhcp
544 default 0
545 timeout 0
546 title Load config from Tftp server
547   configfile (nd)/menu.lst
548 EOT
549
550   CC='gcc'
551   test -r /lib64 && export CC="$CC -m32"
552
553   CC="$CC" execute "./configure --enable-preset-menu=./preset-menu $cmd_line_" warn || read
554   CC="$CC" execute "make -j2" warn || read #return 1
555
556   local st1_="stage1/stage1"
557   local st2_="stage2/stage2"
558   isExistent $st1_ warn || return 1
559   isExistent $st2_ warn || return 1
560
561   execute "mv -fb $PATH_/grub.img $PATH_/grub.img.old"
562   execute "cat $st1_ $st2_ > $PATH_/grub.img" warn || return 1
563   return 0
564 }
565
566 function grubWrite
567 {
568   local grub_title_="Grub configuration"
569   $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$grub_title_" --yesno \
570     "Do you want to write your grub image to /dev/fd0" 5 75 || return 1
571
572   execute "dd if=$PATH_/grub.img of=/dev/fd0" warn || return 0
573   return 1
574 }
575
576 function grubMultiWrite
577 {
578   local target_=${1:-'/dev/fd0'}
579
580   isExistent "$PATH_/grub.img" die "you must give me an image or run \"$PROG_NAME__ grubconf\""
581   isExistent "$target_" die "$target_ is not a valied"
582   while true; do
583     echo -n "Please insert disk into $target_ and press <ENTER> (STRG-C for end)"
584     read
585     dd if=$PATH_/grub.img of="$target_"
586   done
587 }
588 # }}}
589
590
591 function removeTmpFiles
592 {
593   execute "rm -f $TMP_" warn
594 }
595
596 function actionClean
597 {
598   for i in dhcpd.conf grub.img minirt26.gz; do
599     execute "rm -f $PATH_/$i*"
600   done
601
602   for i in $CARDS_DETECTED_BY_DISCOVER $CONF_FILE_; do
603     execute "rm -f $i"
604   done
605
606 }
607
608
609 ###
610 ### __MAIN
611 ###
612
613 while getopts "i:hv" opt; do
614   case "$opt" in
615     i) interface_=$OPTARG ;;
616     h) printUsage; exit ;;
617     v) let verbose_=$verbose_+1 ;;
618     ?) printUsage; exit 64 ;;
619   esac
620 done
621 shift $(($OPTIND - 1))  # set ARGV to the first not parsed commandline parameter
622 setVerbose $verbose_
623
624 case "$1" in
625   help)   printUsage; exit 0 ;;
626 esac
627
628 checkRoot die 'You have to be root to use this program'
629 disableSyslog
630
631 execute "mkdir -p $PATH_" die
632
633 TMP_=`mktemp -t grml-terminalserver-config.XXXXXX` || die "Could not create tmpfile" $?
634 setExitFunction 'removeTmpFiles'
635
636
637 . $DEFAULT_CONFIG_
638 . $CONFIG_
639 # used config vars:
640 # MODULES_PATH_
641 # MODULES_PATH_ROOT_DIFF_
642 # KERNEL_VERSION_
643 # ORIGINAL_INITRD_
644 if [[ $MODULES_PATH_ == "" || $KERNEL_VERSION_ == "" || $ORIGINAL_INITRD_ == "" ]]; then
645   warn "MODULES_PATH_=\"$MODULES_PATH_\" \
646 KERNEL_VERSION_=\"$KERNEL_VERSION_\" \
647 ORIGINAL_INITRD_=\"$ORIGINAL_INITRD_\""
648   die "False configuration, please update $CONFIG_"
649 fi
650
651
652 case "$1" in
653   interactive)  actionInteractive ;;
654   grubConf)   grubConfig "$2" ;;
655   grubConfWrite)  grubConfig && grubWrite ;;
656   grubWrite)    grubWrite ;;
657   grubMultiWrite)   grubMultiWrite "$2" ;;
658   initrd) actionMkInitrd ;;
659   clean)  actionClean ;;
660   *)    actionInteractive ;;
661 esac
662
663 removeTmpFiles
664 # END OF FILE
665 ################################################################################
666 # vim:foldmethod=marker tabstop=2 expandtab shiftwidth=2