2 # Copyright (C) 2016 Ian Kelling
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Setup dhcp server to point to tftp server,
19 # and depending on the type, setup the tftp server.
22 # default distro is the base debian/fedora type. others are fai & arch.
23 # for no pxe server, use a no-op like : or true.
26 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
31 Usage: ${0##*/} [OPTIONS] [HOST TYPE]
34 Without HOST TYPE, disable pxe server and fai server.
35 TYPE is one of arch, plain, fai.
36 HOST is a hostname known to the dhcp server, or default for all
38 -r Don't redeploy fai config. For example, if there is a different host
40 -a Wait for 2 dhcp acks, then disable the pxe server after a delay.
41 First ack is for pxe boot, 2nd ack is for os boot. Sometimes
42 on debian, there is a 3rd one shortly after the 2nd. I can't remember
43 exactly why this caused a problem, but I'm hoping the sleep
45 -w Initially setup pxe, then wait like -a.
46 -h|--help Print help and exit
49 Note: Uses GNU getopt options parsing style
54 ##### begin command line parsing ########
60 temp
=$
(getopt
-l help harw
"$@") || usage
1
64 -a) wait=true
; set=false
; shift ;;
65 -r) redep
=false
; shift ;;
66 -w) wait=true
; set=true
; shift ;;
69 *) echo "$0: Internal error!" ; exit 1 ;;
73 read host type <<<"$@"
78 echo "$0: error: expected 0 or 2 arguments"
88 ##### end command line parsing ########
97 dhcp-option-force=209,boot/syslinux/archiso.cfg
98 dhcp-option-force=210,/arch/
99 dhcp-boot=${host_tag}/arch/boot/syslinux/lpxelinux.0
104 # if arch was used before, this additionally needs
105 # the tftp link in /mnt/usb to be changed.
107 dhcp-boot=${host_tag}pxelinux.0
114 dhcp-boot=${host_tag}pxelinux.0,faiserver.lan,faiserver.lan
123 regex
=".*DHCPACK.*$host_regex$"
126 while (( i
!= wait_count
)) && read line
; do
127 if [[ $line =~
$regex ]]; then
131 done < <(ssh wrt logread
-f)
136 ${type:-:}|
ssh wrt
"cedit pxe /etc/dnsmasq.conf || /etc/init.d/dnsmasq restart
137 $([[ $type == arch ]] && echo arch-pxe-mount)"
143 if [[ $type == fai
]]; then
154 # fai's debian jessie 8.5ish does 2 dhcp requests when booting,
155 # roughly 4 seconds apart. Earlier
156 # versions did just 1. Now testing on a vm, it does 1.
158 echo "waiting for $acks dhcp acks then disabling pxe"
163 # previously tried waiting for one more ack then disabling faiserver,
164 # since it can contain sensitive info, so turn it off when not in use,
165 # but disabling that for now as it's inconvenient to clean this
166 # up and run it in the background etc.
168 # if [[ $type == fai ]]; then
169 # echo "waiting for 1 dhcp ack then disabling fai server"