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] TYPE [HOST]
34 TYPE is one of arch, plain, fai, or : for no pxe server.
35 HOST makes the pxe server only for that specific host
37 -h|--help Print help and exit
38 -- Subsequent arguments are never treated as options
39 -p Persist. Otherwise, wait for 2 dhcp acks then remove.
40 -r Don't redeploy fai config.
45 ##### begin command line parsing ########
54 -r) redep
=false
; shift ;;
55 -p) persist
=true
; shift ;;
56 *) args
+=("$1"); shift ;;
62 read type host <<<"${args[@]}"
64 if [[ ! $type ]]; then
65 echo "$0: error: exptected 1 argument of type"
74 :|true
) persist
=true
;;
77 ##### end command line parsing ########
86 dhcp-option-force=209,boot/syslinux/archiso.cfg
87 dhcp-option-force=210,/arch/
88 dhcp-boot=${host_tag}/arch/boot/syslinux/lpxelinux.0
93 # if arch was used before, this additionally needs
94 # the tftp link in /mnt/usb to be changed.
96 dhcp-boot=${host_tag}pxelinux.0
103 dhcp-boot=${host_tag}fai/pxelinux.0,faiserver.lan,faiserver.lan
112 regex
=".*DHCPACK.*$host_regex$"
115 while (( i
!= wait_count
)) && read line
; do
116 if [[ $line =~
$regex ]]; then
120 done < <(ssh wrt logread
-f)
125 ${1:-$type} |
ssh wrt
"cedit pxe-server /etc/dnsmasq.conf || /etc/init.d/dnsmasq restart
126 if [[ $type == arch ]]; then arch-pxe-mount; fi"
131 if [[ $type == fai
]]; then
139 # fai's debian jessie 8.5ish does 2 dhcp requests when booting,
140 # roughly 4 seconds apart. Earlier
141 # versions did just 1. Whatever.
142 echo "waiting for 3 dhcp acks then disabling pxe"
145 if [[ $type == fai
]]; then
146 # fai server can contain sensitive info, so turn it off
147 # when it's not in use.
148 echo "waiting for 1 dhcp ack then disabling fai server"