code cleanup, arch fixes
[automated-distro-installer] / pxe-server
index 66bc4ff4129da671c713082138ae091c40834e81..a3df1a5953846368397e9b335be844970b132771 100755 (executable)
@@ -29,18 +29,30 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 usage() {
     cat <<EOF
 Usage: ${0##*/} [OPTIONS] [HOST TYPE]
-One line description
+Configure dnsmasq pxe server options and fai-chboot if appropriate.
 
+
+Without HOST TYPE, disable pxe server and fai server.
 TYPE is one of arch, plain, fai.
-HOST is a hostname known to the dhcp server, or default for all, or none to disable
-
--r         Don't redeploy fai config.
--a         Wait for 2 dhcp acks, then disable the pxe server after a delay.
-           First ack is for pxe boot, 2nd ack is for os boot. Sometimes
-           on debian, there is a 3rd one shortly after the 2nd. I can't remember
-           exactly why this caused a problem, but I'm hoping the sleep
-           will take care of it.
--w         Initially setup pxe, then wait like -a.
+HOST is a hostname known to the dhcp server, or default for all
+Note, when switching between plain and arch, you will need to
+do something like:
+ssh wrt
+cd /mnt/usb
+rm tftpboot
+ln -s <arch/debian iso dir> tftpboot
+
+
+-r         Don't redeploy fai config. For example, if there is a different host
+           that is mid-install.
+
+-a         Don't setup pxe, just Wait for 2 dhcp acks, then disable the pxe
+           server after a delay.  First ack is for pxe boot, 2nd ack is
+           for os boot. Sometimes on debian, there is a 3rd one shortly
+           after the 2nd. I can't remember exactly why this caused a
+           problem, but I'm hoping the sleep will take care of it.
+
+-w         Setup pxe, then wait like -a.
 -h|--help  Print help and exit
 
 
@@ -51,7 +63,6 @@ EOF
 
 ##### begin command line parsing ########
 
-args=()
 redep=true
 acks=2
 wait=false
@@ -68,7 +79,7 @@ while true; do
     esac
 done
 
-read host type <<<"$@"
+read -r host type <<<"$@"
 
 case $# in
     0|2);;
@@ -108,7 +119,6 @@ EOF
 
 fai() {
     cat <<EOF
-$set_host_tag
 dhcp-boot=${host_tag}pxelinux.0,faiserver.lan,faiserver.lan
 EOF
 }
@@ -120,8 +130,7 @@ ack-wait() {
     fi
     regex=".*DHCPACK.*$host_regex$"
     i=0
-    tmp=$(mktemp)
-    while (( i != wait_count )) && read line; do
+    while (( i != wait_count )) && read -r line; do
         if [[ $line =~ $regex ]]; then
             i=$((i+1))
             echo $line
@@ -139,12 +148,14 @@ $([[ $type == arch ]] && echo arch-pxe-mount)"
 if $set; then
     set-pxe
     if [[ $type == fai ]]; then
-        myfai-chboot $host
+        myfai-chboot $host
         if $redep; then
-            fai-redep
+            fai-redep
         fi
     else
-        myfai-chboot
+        # This will fail if faiserver is not setup, so ignore any
+        # failure and don't bother us about it.
+        myfai-chboot &>/dev/null ||:
     fi
 fi