2 # Filename: terminalserver
3 # Purpose: Program to do something
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: Sat Aug 06 14:14:40 CEST 2005
8 ################################################################################
15 #. /etc/grml/sysexits-sh
26 # this file holds all variable definitions
27 SHARED_PROG_VARS_="/usr/share/grml-terminalserver/shared_prog_vars"
28 isExistent $SHARED_PROG_VARS_ die
39 Usage: "$PROG_NAME__" [OPTIONS] <command>
41 $PROG_NAME__ is the config program for the terminalserver
46 start <service> Start services (if all services are started, configs will be updated)
47 stop <service> Stop services
48 config <service> Update config of given service (or from all if no services given)
49 clean Stop all + remove config and boot files from services
55 nfs All necessary nfs daemons
59 -v verbose (show what is going on, v++)
66 function killPortmapper
68 /etc/init.d/portmap stop >/dev/null &>/dev/null
69 killall -9 portmap &>/dev/null
73 function createDhcpConf
75 if [ -e "$DHCPD_CONFIG_FILE_" ]; then
76 if grep $CONFIG_PATTERN_ $DHCPD_CONFIG_FILE_ &>/dev/null; then
77 execute "mv -fb \"$DHCPD_CONFIG_FILE_\" \"$DHCPD_CONFIG_FILE_.old\"" eprint &>/dev/null
78 execute "source $TEMPLATE_CONFIG_DIR_/dhcpd_config" die
80 if [[ $FORCE_ == "true" ]]; then
81 execute "mv -fb \"$DHCPD_CONFIG_FILE_\" \"$DHCPD_CONFIG_FILE_.old\"" eprint &>/dev/null
82 execute "source $TEMPLATE_CONFIG_DIR_/dhcpd_config" die
84 warn "Not updating user edited configfile $DHCPD_CONFIG_FILE_, user -f to override"
88 execute "source $TEMPLATE_CONFIG_DIR_/dhcpd_config" die
92 function removeDhcpConf
94 if [ -e "$DHCPD_CONFIG_FILE_" ]; then
95 if grep $CONFIG_PATTERN_ $DHCPD_CONFIG_FILE_ &>/dev/null; then
96 rm -f "$DHCPD_CONFIG_FILE_"
98 if [[ $FORCE_ == "true" ]]; then
99 rm -f "$DHCPD_CONFIG_FILE_"
101 warn "Not deleting user edited configfile $DHCPD_CONFIG_FILE_, user -f to override"
110 start-stop-daemon --stop --quiet --pidfile "$DHCPD_PID_"
112 rm -f /var/lib/dhcp3/dhcpd.leases* 2>/dev/null #FIXME
113 touch /var/lib/dhcp3/dhcpd.leases
118 local conf_file_="$DHCPD_CONFIG_FILE_"
120 test -f $DHCPD_BIN_ || die "could not find dhcpd \"$DHCPD_BIN_\""
121 start-stop-daemon --start --quiet --pidfile "$DHCPD_PID_" \
122 --exec "$DHCPD_BIN_" -- -cf "$conf_file_" -q "$INTERFACE_" || warn "problems starting dhcpd"
127 isExistent "$DHCPD_CONFIG_FILE_" || \
128 warn "no config for dhcpd: \"$DHCPD_CONFIG_FILE_\" => not starting dhcpd" || return 1
135 # make sure tcp/113 is rejected
138 if [ -x /sbin/iptables ] ; then
139 # something keeps answering all tftp requests with auth requests (SYN
140 # packets to the client tcp/113). Since the PXE client doesn't answer with
141 # RST, the auth query has to wait until it times out. Forbidding the
142 # terminalserver to send out packets to tcp/113 via iptables _greatly_
143 # speeds up the process. But of course the real fix would be to have grml
144 # stop sending out auth queries to tftp clients. according to netstat, it
145 # is in.tftpd itself sending out the auth queries.
146 # Thanks to Marc Haber and Wolfgang Karall for noticing and current fix.
147 if iptables -L | grep -q '^REJECT.*tcp dpt:auth reject-with tcp-reset' ; then
148 echo "Rule for tcp/113 already present, nothing to be done."
150 echo "Rejecting tcp/113 via iptables to speed up booting via PXE, running:"
151 echo -n '* iptables -A OUTPUT -p tcp --dport 113 -j REJECT --reject-with tcp-reset'
152 iptables -A OUTPUT -p tcp --dport 113 -j REJECT --reject-with tcp-reset && echo done || echo failed
154 # deactivate Multicast-DNS
155 if iptables -L | grep -q '^REJECT.*dpt:mdns reject-with icmp-port-unreachable' ; then
156 echo "Rule for udp/5353 already present, nothing to be done."
158 echo "Rejecting udp/5353 via iptables for deactivating Multicast-DNS, running:"
159 echo -n '* iptables -A OUTPUT -p udp -d 224.0.0.0/8 --dport 5353 -j REJECT'
160 iptables -A OUTPUT -p udp -d 224.0.0.0/8 --dport 5353 -j REJECT && echo done || echo failed
163 warn "iptables executable not avilable"
169 function removeTftpConf
171 rm -rf $TFTPD_DATA_DIR_/*
173 function createTftpConf
177 execute "mkdir $TFTPD_DATA_DIR_/pxelinux.cfg" die
178 execute "install -m 644 /usr/lib/syslinux/pxelinux.0 $TFTPD_DATA_DIR_" die
179 execute "install -m 644 $PATH_/minirt26.gz $TFTPD_DATA_DIR_" die
180 execute "install -m 644 $KERNEL_IMAGE_ $TFTPD_DATA_DIR_/linux26" die
181 execute "install -m 644 $MEMTEST_IMAGE_ $TFTPD_DATA_DIR_/memtest" die
182 execute "install -m 644 $PXE_BOOT_MSG_ $TFTPD_DATA_DIR_" die
183 execute "install -m 644 $PXE_BOOT_LOGO_ $TFTPD_DATA_DIR_" die
185 execute "source $TEMPLATE_CONFIG_DIR_/grub-pxelinux_config" die
190 start-stop-daemon --stop --quiet --name "${TFTPD_BIN_##*/}"
194 test -f $TFTPD_BIN_ || die "could not find \"$TFTPD_BIN_\""
195 start-stop-daemon --start --quiet --exec "$TFTPD_BIN_" -- -l -a "$IP_" -s "$TFTPD_DATA_DIR_" || \
196 warn "problems starting tftpd server"
208 function createNfsConfig
210 execute "exportfs -o ro,no_root_squash,async,nohide $NETWORK_/$NETMASK_:$MOUNT_POINT_" warn
213 function removeNfsConfig
215 execute "exportfs -u -o ro,no_root_squash,async,nohide $NETWORK_/$NETMASK_:$MOUNT_POINT_" warn
220 /etc/init.d/portmap start
221 /etc/init.d/nfs-common start
222 # FIXME /etc/init.d/nfs-kernel-server start
223 $USR_SHARE_/nfs-kernel-server start
230 if [[ `exportfs |wc -l` > 0 ]]; then
231 dprint "There are other exports, not stopping NFS serivces"
233 /etc/init.d/nfs-kernel-server stop >/dev/null 2>&1
234 /etc/init.d/nfs-common stop >/dev/null 2>&1
241 function createConfig
244 execute "sed -i 's/^ALL/\#ALL/' /etc/hosts.deny" warn
245 execute "sed -i 's/^ALL : ALL@ALL : DENY/ALL : ALL@ALL : ALLOW/' /etc/hosts.allow" warn
255 echo -n "Starting tftpd: "
256 runTftp && echo done || echo failed
258 echo -n "Starting dhcpd: "
259 runDhcp && echo done || echo failed
263 echo "Finally starting nfs services..."
264 startNfs && echo "Sucessfully finished startup of grml-terminalserver." || echo 'Startup of grml-terminalserver-config failed!'
272 notice "Terminal-server stopped"
283 function updateConfig
289 tftp) createTftpConf ;;
290 dhcp) createDhcpConf ;;
291 nfs) removeNfsConfig; createNfsConfig ;;
292 *) warn "Service $service_ not available" ;;
297 function serviceStart
299 local service_="$1" # service to start, if nothing => all
306 *) warn "Service $service_ not available" ;;
312 local service_="$1" # service to stop, if nothing => all
319 *) warn "Service $service_ not available" ;;
328 while getopts "fi:hv" opt; do
331 h) printUsage; exit ;;
332 v) let verbose_=$verbose_+1 ;;
333 ?) printUsage; exit 64 ;;
336 shift $(($OPTIND - 1)) # set ARGV to the first not parsed commandline parameter
340 help) printUsage; exit 0 ;;
343 checkRoot die "You have to be root to use this program"
346 isExistent $DEFAULT_CONFIG_ die
355 if [[ $MOUNT_POINT_ == "" || $KERNEL_IMAGE_ == "" || $MEMTEST_IMAGE_ == "" || \
356 $PXE_BOOT_MSG_ == "" || $PXE_BOOT_MSG_ == "" ]]; then
357 warn "MOUNT_POINT_=\"$MOUNT_POINT_\" \
358 KERNEL_IMAGE_=\"$KERNEL_IMAGE_\" \
359 MEMTEST_IMAGE_=\"$MEMTEST_IMAGE_\"
360 PXE_BOOT_MSG_=\"$PXE_BOOT_MSG_\"
361 PXE_BOOT_LOGO_=\"$PXE_BOOT_LOGO_\""
362 die "False configuration, please update $CONFIG_"
366 clean) actionClean; exit 0 ;;
371 isExistent "$CONF_FILE_" warn "sorry configfile \"$CONF_FILE_\" not found"
372 if [ $? -eq 1 ]; then
373 $CONFIG_PROG_ && continue
374 $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "Question" --yesno \
375 "grml-terminalserver-config returned an error, do you want to quit now?" 5 75 && exit 1
382 # check for necessary files
383 check_necessary_files_='no'
384 if [ "$1" == 'start' ]; then
386 tftp|"") check_necessary_files_='yes' ;;
389 if [ $check_necessary_files_ == 'yes' ]; then
390 # test for files absolutly necessary for grml-terminalserver and created from -config
392 for i in $PATH_/minirt26.gz; do
393 isExistent $i warn || problem_=1
395 if [ $problem_ -eq 1 ]; then
396 die 'Some necessary files are missing, please rerun grml-terminalserver-config, or copy the files manually'
402 start) serviceStart "$2" ;;
403 stop) serviceStop "$2" ;;
404 config) updateConfig "$2" ;;
410 ################################################################################
411 # vim:foldmethod=marker tabstop=2 expandtab shiftwidth=2