-#!/bin/bash -x
+#!/bin/bash
# Setup dhcp server to point to tftp server,
# and depending on the type, setup the tftp server.
-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
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/
# 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
}
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