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
25 # this file holds all variable definitions
26 SHARED_PROG_VARS_="/usr/share/grml-terminalserver/shared_prog_vars"
27 isExistent $SHARED_PROG_VARS_ die
38 Usage: "$PROG_NAME__" [OPTIONS] <command>
40 $PROG_NAME__ is the config program for the terminalserver
45 start <service> Start services (if all services are started, configs will be updated)
46 stop <service> Stop services
47 config <service> Update config of given service (or from all if no services given)
48 clean Stop all + remove config and boot files from services
54 nfs All necessary nfs daemons
58 -v verbose (show what is going on, v++)
64 function killPortmapper
66 /etc/init.d/portmap stop >/dev/null &>/dev/null
67 killall -9 portmap &>/dev/null
71 function createDhcpConf
73 if [ -e "$DHCPD_CONFIG_FILE_" ]; then
74 if grep $CONFIG_PATTERN_ $DHCPD_CONFIG_FILE_ &>/dev/null; then
75 execute "mv -fb \"$DHCPD_CONFIG_FILE_\" \"$DHCPD_CONFIG_FILE_.old\"" eprint &>/dev/null
76 execute "source $TEMPLATE_CONFIG_DIR_/dhcpd_config" die
78 warn "Not updating user edited configfile $DHCPD_CONFIG_FILE_"
81 execute "source $TEMPLATE_CONFIG_DIR_/dhcpd_config" die
85 function removeDhcpConf
87 if [ -e "$DHCPD_CONFIG_FILE_" ]; then
88 if grep $CONFIG_PATTERN_ $DHCPD_CONFIG_FILE_ &>/dev/null; then
89 rm -f "$DHCPD_CONFIG_FILE_"
91 warn "Not deleting user edited configfile $DHCPD_CONFIG_FILE_"
99 start-stop-daemon --stop --quiet --pidfile "$DHCPD_PID_"
101 rm -f /var/lib/dhcp3/dhcpd.leases* 2>/dev/null #FIXME
102 touch /var/lib/dhcp3/dhcpd.leases
106 local conf_file_="$DHCPD_CONFIG_FILE_"
108 test -f $DHCPD_BIN_ || die "could not find dhcpd \"$DHCPD_BIN_\""
109 start-stop-daemon --start --quiet --pidfile "$DHCPD_PID_" \
110 --exec "$DHCPD_BIN_" -- -cf "$conf_file_" -q "$INTERFACE_" || warn "problems starting dhcpd"
114 isExistent "$DHCPD_CONFIG_FILE_" || \
115 warn "no config for dhcpd: \"$DHCPD_CONFIG_FILE_\" => not starting dhcpd" || return 1
124 function removeTftpConf
126 rm -rf $TFTPD_DATA_DIR_/*
128 function createTftpConf
132 execute "mkdir $TFTPD_DATA_DIR_/pxelinux.cfg" die
133 execute "install -m 644 /usr/lib/syslinux/pxelinux.0 $TFTPD_DATA_DIR_" die
134 execute "install -m 644 $PATH_/minirt26.gz $TFTPD_DATA_DIR_" die
135 execute "install -m 644 $KERNEL_IMAGE_ $TFTPD_DATA_DIR_/linux26" die
136 execute "install -m 644 $MEMTEST_IMAGE_ $TFTPD_DATA_DIR_/memtest" die
137 execute "install -m 644 $PXE_BOOT_MSG_ $TFTPD_DATA_DIR_" die
138 execute "install -m 644 $PXE_BOOT_LOGO_ $TFTPD_DATA_DIR_" die
140 execute "source $TEMPLATE_CONFIG_DIR_/grub-pxelinux_config" die
145 start-stop-daemon --stop --quiet --name "${TFTPD_BIN_##*/}"
149 test -f $TFTPD_BIN_ || die "could not find \"$TFTPD_BIN_\""
150 start-stop-daemon --start --quiet --exec "$TFTPD_BIN_" -- -l -a "$IP_" -s "$TFTPD_DATA_DIR_" || \
151 warn "problems starting tftpd server"
163 function createNfsConfig
165 execute "exportfs -o ro,no_root_squash,async,nohide $NETWORK_/$NETMASK_:$MOUNT_POINT_" warn
168 function removeNfsConfig
170 execute "exportfs -u -o ro,no_root_squash,async,nohide $NETWORK_/$NETMASK_:$MOUNT_POINT_" warn
175 /etc/init.d/portmap start
176 /etc/init.d/nfs-common start
177 # FIXME /etc/init.d/nfs-kernel-server start
178 $USR_SHARE_/nfs-kernel-server start
185 if [[ `exportfs |wc -l` > 0 ]]; then
186 dprint "There are other exports, not stopping NFS serivces"
188 /etc/init.d/nfs-kernel-server stop >/dev/null 2>&1
189 /etc/init.d/nfs-common stop >/dev/null 2>&1
195 function allreadyConfigured
197 isExistent "$CONF_FILE_" dprint || return 1
201 function createConfig
204 execute "sed -i 's/^ALL/\#ALL/' /etc/hosts.deny" warn
205 execute "sed -i 's/^ALL : ALL@ALL : DENY/ALL : ALL@ALL : ALLOW/' /etc/hosts.allow" warn
215 echo -n "Starting tftpd..."
218 echo -n "Starting dhcpd..."
221 echo -n "Starting nfs..."
231 notice "Terminal-server stopped"
242 function updateConfig
248 tftp) createTftpConf ;;
249 dhcp) createDhcpConf ;;
250 nfs) removeNfsConfig; createNfsConfig ;;
251 *) warn "Service $service_ not available" ;;
256 function serviceStart
258 local service_="$1" # service to start, if nothing => all
265 *) warn "Service $service_ not available" ;;
271 local service_="$1" # service to stop, if nothing => all
278 *) warn "Service $service_ not available" ;;
287 while getopts "i:hv" opt; do
289 h) printUsage; exit ;;
290 v) let verbose_=$verbose_+1 ;;
291 ?) printUsage; exit 64 ;;
294 shift $(($OPTIND - 1)) # set ARGV to the first not parsed commandline parameter
298 help) printUsage; exit 0 ;;
301 checkRoot die "You have to be root to use this program"
304 isExistent $DEFAULT_CONFIG_ die
313 if [[ $MOUNT_POINT_ == "" || $KERNEL_IMAGE_ == "" || $MEMTEST_IMAGE_ == "" || \
314 $PXE_BOOT_MSG_ == "" || $PXE_BOOT_MSG_ == "" ]]; then
315 warn "MOUNT_POINT_=\"$MOUNT_POINT_\" \
316 KERNEL_IMAGE_=\"$KERNEL_IMAGE_\" \
317 MEMTEST_IMAGE_=\"$MEMTEST_IMAGE_\"
318 PXE_BOOT_MSG_=\"$PXE_BOOT_MSG_\"
319 PXE_BOOT_LOGO_=\"$PXE_BOOT_LOGO_\""
320 die "False configuration, please update $CONFIG_"
324 clean) actionClean; exit 0 ;;
329 isExistent "$CONF_FILE_" warn "sorry configfile \"$CONF_FILE_\" not found"
330 if [ $? -eq 1 ]; then
331 $CONFIG_PROG_ && continue
332 $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "Question" --yesno \
333 "grml-terminalserver-config returned an error, do you want to quit now?" 5 75 && exit 1
340 # check for necessary files
341 check_necessary_files_='no'
342 if [ "$1" == 'start' ]; then
344 tftp|"") check_necessary_files_='yes' ;;
347 if [ $check_necessary_files_ == 'yes' ]; then
348 # test for files absolutly necessary for grml-terminalserver and created from -config
350 for i in $PATH_/minirt26.gz; do
351 isExistent $i warn || problem_=1
353 if [ $problem_ -eq 1 ]; then
354 die 'Some necessary files are missing, please rerun grml-terminalserver-config, or copy the files manually'
360 start) serviceStart "$2" ;;
361 stop) serviceStop "$2" ;;
362 config) updateConfig "$2" ;;
368 ################################################################################
369 # vim:foldmethod=marker tabstop=2 expandtab shiftwidth=2