set -eE -o pipefail
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
-if [[ ! $1 ]]; then
+
+usage() {
+ cat <<EOF
+Usage: ${0##*/} [OPTIONS] TYPE [HOST]
+One line description
+
+TYPE is one of arch, plain, fai, or : for no pxe server.
+HOST makes the pxe server only for that specific host
+
+-h|--help Print help and exit
+-- Subsequent arguments are never treated as options
+EOF
+ exit $1
+}
+
+##### begin command line parsing ########
+
+
+args=()
+while [[ $1 ]]; do
+ case $1 in
+ --) shift; break ;;
+ -h|--help) usage ;;
+ *) args+=("$1"); shift ;;
+ esac
+done
+args+=("$@")
+
+
+read type host <<<"${args[@]}"
+
+if [[ ! $type ]]; then
echo "$0: error: exptected 1 argument of type"
+ usage 1
fi
-action=$1
+
+if [[ $host ]]; then
+ host_tag="tag:$host,"
+fi
+
+##### end command line parsing ########
arch() {
- plain-tftp
- cat <<'EOF'
+ plain
+ cat <<EOF
dhcp-option-force=209,boot/syslinux/archiso.cfg
dhcp-option-force=210,/arch/
-dhcp-boot=/arch/boot/syslinux/lpxelinux.0
+dhcp-boot=${host_tag}/arch/boot/syslinux/lpxelinux.0
EOF
}
-plain-tftp() {
+plain() {
# if arch was used before, this additionally needs
# the tftp link in /mnt/usb to be changed.
- cat <<'EOF'
+ cat <<EOF
enable-tftp
tftp-root=/mnt/usb/tftpboot
-dhcp-boot=pxelinux.0
+dhcp-boot=${host_tag}pxelinux.0
EOF
}
fai() {
- cat <<'EOF'
-dhcp-boot=fai/pxelinux.0,faiserver.lan,faiserver.lan
+ cat <<EOF
+$set_host_tag
+dhcp-boot=${host_tag}fai/pxelinux.0,faiserver.lan,faiserver.lan
EOF
}
-$action | ssh wrt "cedit pxe-server /etc/dnsmasq.conf || /etc/init.d/dnsmasq restart
-if [[ $action == arch ]]; then arch-pxe-mount; fi"
+$type | ssh wrt "cedit pxe-server /etc/dnsmasq.conf || /etc/init.d/dnsmasq restart
+if [[ $type == arch ]]; then arch-pxe-mount; fi"