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