various fixes and improvements
[automated-distro-installer] / pxe-server
index 4fcf40c134cd472d3ba50aaa26687298846c5da1..d3625d692cef0441f40be9ab032691c60bd73eb9 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash -x
+#!/bin/bash
 
 # Setup dhcp server to point to tftp server,
 # and depending on the type, setup the tftp server.
@@ -21,18 +21,20 @@ HOST makes the pxe server only for that specific host
 
 -h|--help  Print help and exit
 --         Subsequent arguments are never treated as options
+-p         Persist. Otherwise, wait for 2 dhcp acks then remove.
 EOF
     exit $1
 }
 
 ##### begin command line parsing ########
 
-
+persist=false
 args=()
 while [[ $1 ]]; do
     case $1 in
         --) shift; break ;;
         -h|--help) usage ;;
+        -p) persist=true; shift ;;
         *) args+=("$1"); shift ;;
     esac
 done
@@ -50,10 +52,18 @@ if [[ $host ]]; then
     host_tag="tag:$host,"
 fi
 
+case $type in
+    :|true) persist=true ;;
+esac
+
 ##### end command line parsing ########
 
+sv() {
+    echo "$@"
+    "$@"
+}
+
 arch() {
-    plain
     cat <<EOF
 dhcp-option-force=209,boot/syslinux/archiso.cfg
 dhcp-option-force=210,/arch/
@@ -65,8 +75,6 @@ plain() {
     # if arch was used before, this additionally needs
     # the tftp link in /mnt/usb to be changed.
     cat <<EOF
-enable-tftp
-tftp-root=/mnt/usb/tftpboot
 dhcp-boot=${host_tag}pxelinux.0
 EOF
 }
@@ -78,6 +86,24 @@ dhcp-boot=${host_tag}fai/pxelinux.0,faiserver.lan,faiserver.lan
 EOF
 }
 
-
-$type | ssh wrt "cedit pxe-server /etc/dnsmasq.conf || /etc/init.d/dnsmasq restart
+echo "setting config type: $type"
+$type | ssh wrt "cedit pxe-server /etc/dnsmasq.conf || /etc/init.d/dnsmasq restart #
 if [[ $type == arch ]]; then arch-pxe-mount; fi"
+
+
+if ! $persist; then
+    if [[ $host ]]; then
+        host_regex=" $host"
+    fi
+    regex=".*DHCPACK.*$host_regex$"
+    i=0
+    tmp=$(mktemp)
+    while (( i != 2 )) && read line; do
+        if [[ $line =~ $regex ]]; then
+            i=$((i+1))
+            echo $line
+        fi
+    done < <(ssh wrt logread -f)
+    sv sleep 5
+    sv "$BASH_SOURCE" :
+fi