+ack-wait() {
+ if $fsf; then
+ wait_cmd="ssh tarantula tail -n0 -f /var/log/syslog"
+ else
+ wait_cmd="ssh wrt logread -f"
+ fi
+ wait_count=$1
+ if [[ $host ]]; then
+ if $fsf; then
+ host_regex=" $(getent hosts kw | awk '{print $1}' | sed 's/\./\\./g')"
+ else
+ host_regex=" $host"
+ fi
+ fi
+ regex=".*DHCPACK.*$host_regex\b"
+ i=0
+ while (( i != wait_count )) && read -r line; do
+ if [[ $line =~ $regex ]]; then
+ i=$((i+1))
+ echo $line
+ fi
+ done < <($wait_cmd ||:) # tail returns 2 it seems
+ m sleep 20
+}
+
+set-pxe() {
+ $dhcp || return 0
+ if $fsf; then
+ if [[ ! $cmd ]]; then
+ e "removing pxe for $host on tarantula"
+ ssh tarantula bash -e <<EOF
+sed -ri 's/^( *host +$host *\{).*/\1/' /etc/dhcp3/dhcpd.conf
+/etc/init.d/dhcp3-server restart
+EOF
+ elif [[ $cmd == fai ]]; then
+ e "adding pxe for $host on tarantula"
+ ssh tarantula bash -e <<EOF
+sed -ri 's/^( *host +$host *\{).*/\1 next-server faiserver.office.fsf.org; filename "pxelinux.0";/' /etc/dhcp3/dhcpd.conf
+/etc/init.d/dhcp3-server restart
+EOF
+ fi
+ else
+ e "updating dnsmasq.conf:"
+ m $cmd
+ ${cmd:-:}|ssh wrt "cedit pxe /etc/dnsmasq.conf || /etc/init.d/dnsmasq restart
+$([[ $type == arch || $type == parabola ]] && echo archlike-pxe-mount)"
+ fi
+}
+
+
+if $set; then
+ set-pxe
+ if [[ $type == fai ]]; then
+ m myfai-chboot ${chboot_args[@]} $host
+ if $redep; then
+ m fai-redep
+ fi
+ else
+ # 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
+
+if $wait; then
+ # fai's debian jessie 8.5ish does 2 dhcp requests when booting,
+ # roughly 4 seconds apart. Earlier
+ # versions did just 1. Now testing on a vm, it does 1.
+ # bleh.
+ echo "waiting for $acks dhcp acks then disabling pxe"
+ ack-wait $acks
+ type=
+ unset cmd
+ set-pxe
+
+ # previously tried waiting for one more ack then disabling faiserver,
+ # since it can contain sensitive info, so turn it off when not in use,
+ # but disabling that for now as it's inconvenient to clean this
+ # up and run it in the background etc.