various improvements
[automated-distro-installer] / pxe-server
1 #!/bin/bash -x
2
3 # Setup dhcp server to point to tftp server,
4 # and depending on the type, setup the tftp server.
5
6 # usage: $0 TYPE
7 # default distro is the base debian/fedora type. others are fai & arch.
8 # for no pxe server, use a no-op like : or true.
9
10 set -eE -o pipefail
11 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
12
13
14 usage() {
15 cat <<EOF
16 Usage: ${0##*/} [OPTIONS] TYPE [HOST]
17 One line description
18
19 TYPE is one of arch, plain, fai, or : for no pxe server.
20 HOST makes the pxe server only for that specific host
21
22 -h|--help Print help and exit
23 -- Subsequent arguments are never treated as options
24 EOF
25 exit $1
26 }
27
28 ##### begin command line parsing ########
29
30
31 args=()
32 while [[ $1 ]]; do
33 case $1 in
34 --) shift; break ;;
35 -h|--help) usage ;;
36 *) args+=("$1"); shift ;;
37 esac
38 done
39 args+=("$@")
40
41
42 read type host <<<"${args[@]}"
43
44 if [[ ! $type ]]; then
45 echo "$0: error: exptected 1 argument of type"
46 usage 1
47 fi
48
49 if [[ $host ]]; then
50 host_tag="tag:$host,"
51 fi
52
53 ##### end command line parsing ########
54
55 arch() {
56 plain
57 cat <<EOF
58 dhcp-option-force=209,boot/syslinux/archiso.cfg
59 dhcp-option-force=210,/arch/
60 dhcp-boot=${host_tag}/arch/boot/syslinux/lpxelinux.0
61 EOF
62 }
63
64 plain() {
65 # if arch was used before, this additionally needs
66 # the tftp link in /mnt/usb to be changed.
67 cat <<EOF
68 enable-tftp
69 tftp-root=/mnt/usb/tftpboot
70 dhcp-boot=${host_tag}pxelinux.0
71 EOF
72 }
73
74 fai() {
75 cat <<EOF
76 $set_host_tag
77 dhcp-boot=${host_tag}fai/pxelinux.0,faiserver.lan,faiserver.lan
78 EOF
79 }
80
81
82 $type | ssh wrt "cedit pxe-server /etc/dnsmasq.conf || /etc/init.d/dnsmasq restart
83 if [[ $type == arch ]]; then arch-pxe-mount; fi"