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
120 echo "Installing initrd $PATH_/initrd.img:"
121 # until we have a stable file location API let's use
122 # an according heuristic
123 initrd_=initrd.img-"$(uname -r)"
124 cp /boot/"$initrd_" "$PATH_"/initrd.img || die "Could not copy /boot/$initrd_"
129 # INTERACTIVE CONFIGURATION {{{
131 function actionInteractive
135 dprint "running in interactive mode"
137 local card_title_="Choose network device connected to client network"
138 local card_message_="Available network devices:"
139 local iprange_title_="IP Address range for clients"
140 local iprange_message_="
141 Please enter the desired IP-Range of addresses that should be allocated by clients, separated by a single space.
144 192.168.0.101 192.168.0.200
146 for addresses from 192.168.0.101 to (and including) 192.168.0.200.
149 local runconfig_title_="Networkcard config"
150 local runconfig_message_="Would you like to configure your interfaces now?"
152 # on which interfaces should we listen
153 local netdevices_="$(grep -ve 'lo:' -ve 'Inter-|' -ve 'face |bytes' /proc/net/dev | awk -F: '{print $1}')"
154 local device_list_=""
155 for INTERFACE_ in $netdevices_; do device_list_="$device_list_ ${INTERFACE_} Networkcard_${INTERFACE_##eth}"; done
157 $DIALOG_ --backtitle "$BACK_TITLE_" --title "$card_title_" --menu "$card_message_" \
158 0 0 18 $device_list_ 2>"$TMP_" || warn "could not get network-interface"
159 INTERFACE_="$(<$TMP_)" ; echo -n "" >"$TMP_"
162 IP_=`netGetIp "$INTERFACE_" warn`
163 NETMASK_=`netGetNetmask "$INTERFACE_" warn`
164 netValidIp "$IP_" warn && break
165 $DIALOG_ --backtitle "$BACK_TITLE_" --title "$runconfig_title_" --yesno "$runconfig_message_" 18 45 && \
166 netcardconfig || die "Could not get interface" $?
169 IPRANGE_FROM_=`execute "ipcalc -nb $IP_/$NETMASK_" warn |awk '/HostMin/{print $2}'`
170 # if we have x.x.x.1 as starting range address provide
171 # x.x.x.10 instead so we avoid possible conflicts with
173 if echo $IPFROM | grep -c '\.1$' ; then
174 IPFROM="${IPFROM%%\.1}.10"
176 IPRANGE_TO_=`execute "ipcalc -nb $IP_/$NETMASK_" warn |awk '/HostMax/{print $2}'`
177 NETWORK_=`execute "ipcalc -nb $IP_/$NETMASK_" warn |awk '/Network:/{print $2}'`
178 NETWORK_=${NETWORK_%/*}
180 while [ -z "$IPRANGE_FROM_" -o -z "$IPRANGE_TO_" -o -z "$iprange_" ]; do
181 iprange_="$IPRANGE_FROM_ $IPRANGE_TO_"
183 $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$iprange_title_ ($INTERFACE_=$IP_/$NETMASK_)" \
184 --inputbox "$iprange_message_" 18 75 "$iprange_" 2>"$TMP_" || die "problems getting network range" $?
187 IPRANGE_FROM_="${iprange_%% *}"
188 IPRANGE_TO_="${iprange_##* }"
190 for i in "$IPRANGE_FROM_" "$IPRANGE_TO_"; do
191 netValidIp "$i" warn || iprange_=""
195 NAMESERVERS_=`netGetNameservers warn`
196 GW_=`netGetDefaultGateway warn`
197 GW_DEV_=`/sbin/ip route get "$GW_" | sed 's/^local //' | awk '{ print $3; exit; }'`
198 if [ "$GW_DEV_" != "$INTERFACE_" ] && [ "$GW_DEV_" != "" ] && [ "$GW_DEV_" != "lo" ]; then
199 # GW_DEV_ of server is not the same device as the one serviced by dhcpd
200 # so it doesn't make sense to provide the GW_ address to the clients
202 local do_nat_title_="Network Address Translation"
203 local do_nat_message_="
204 Do you want to set up NAT so that clients booting from this
205 grml-terminalserver can use this machine also as gateway to
208 $DIALOG_ --clear --backtitle "$BACK_TITLE_" --title "$do_nat_title_" --yesno "$do_nat_message_" 15 75 || \
210 if [ "$do_nat_" = "YES" ]; then
211 # user wants NAT, we give the clients the server address as
214 NAT_INTERFACE_="$GW_DEV_"
216 # no NAT, no sensible gateway
223 local OPTIONS_BOOTARG_MESSAGE_="Here you can add additional boot arguments for the clients seperated by spaces:
225 Quite useful examples:
227 ssh=<pw> - Start ssh server and set password of user grml to pw
228 services=<1,2,3> - Execute /etc/init.d/{1,2,3} start
229 console=ttyS0,9600n8 - Initialise serial console
234 $DIALOG_ --clear --no-collapse --backtitle "$BACK_TITLE_" --title "$OPTIONS_TITLE_" --inputbox "$OPTIONS_BOOTARG_MESSAGE_" 0 0\
235 2>$TMP_ || die "problems getting additional boot arguments"
236 BOOT_ARGS_="$BOOT_ARGS_ $(<$TMP_)"
240 notice "GRML terminalserver successfully configured"
244 function removeTmpFiles
246 execute "rm -f $TMP_" warn
251 for i in dhcpd.conf initrd.img; do
252 execute "rm -f $PATH_/$i*"
255 for i in $CARDS_DETECTED_BY_DISCOVER $CONF_FILE_; do
266 while getopts "i:hv" opt; do
268 i) interface_=$OPTARG ;;
269 h) printUsage; exit ;;
270 v) let verbose_=$verbose_+1 ;;
271 ?) printUsage; exit 64 ;;
274 shift $(($OPTIND - 1)) # set ARGV to the first not parsed commandline parameter
278 help) printUsage; exit 0 ;;
281 checkRoot die 'You have to be root to use this program'
284 execute "mkdir -p $PATH_" die
286 TMP_=`mktemp -t grml-terminalserver-config.XXXXXX` || die "Could not create tmpfile" $?
287 setExitFunction 'removeTmpFiles'
294 interactive) actionInteractive ;;
295 initrd) actionMkInitrd ;;
296 clean) actionClean ;;
297 *) actionInteractive ;;
302 ################################################################################
303 # vim:foldmethod=marker tabstop=2 expandtab shiftwidth=2