4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
10 echo "see help from myfai-chboot"
20 [[ $EUID == 0 ]] ||
exec sudo
"${BASH_SOURCE}" "$@"
22 e
() { echo "$@"; "$@"; }
26 type -t host &>/dev
/null || apt-get
-y install dnsutils
27 gateway_if
=$
(ip route |
sed -rn 's/^default via \S+ dev (\S+) .*/\1/p')
28 if [[ ! $gateway_if ]]; then
29 echo "$0: failed to find gateway interface"
32 # assuming ipv4, or else we might need to deal with multiple addresses
33 # in an ipv4 + ipv6 network.
34 network
=$
(ip
-4 -o a show dev
$gateway_if |
sed -rn '/scope.*global/s/^(\S+\s+){3}(\S+)\s.*/\2/p')
35 if [[ ! $network ]]; then
36 echo "$0: failed to find network"
40 if [[ $host == default
]]; then
43 ip
=$
(host $host |
sed -rn 's/^\S+ has address //p;T;q')/32
47 # alternate way of getting my ip
48 #gateway_ip=$(ip route | sed -rn 's/^default via (\S+) .*/\1/p')
49 #my_ip=$(host faiserver $gateway_ip | sed -rn 's/^\S+ has address //p;T;q')
51 if modprobe nfsd
&>/dev
/null
; then
52 std_arg
="-u nfs://faiserver/srv/fai/config"
53 root_arg
="$my_ip:/srv/fai/nfsroot"
54 # fai-setup without -e sets the ip to the local_ip/local_network, eg 192.168.1.3/24
55 # I restrict it to one ip as simple but imperfect access control.
56 sed -ri --follow-symlinks '\%^/srv/fai/%d' /etc
/exports
57 cat >>/etc
/exports
<<EOF
58 /srv/fai/config $ip(async,ro,no_subtree_check)
59 /srv/fai/nfsroot $ip(async,ro,no_subtree_check,no_root_squash)
63 std_arg
="-u http://faiserver:8080/config.tar.gz"
64 root_arg
="live:http://faiserver:8080/squash.img"
65 /a
/exe
/web-conf
-i -p 8080 - apache2 faiserver
<<EOF
73 rm -f /srv
/tftp
/fai
/pxelinux.cfg
/*
79 # man page doesn't explain this, but this deletes & thus disables
81 e fai-chboot
-${fai_action_arg}v
$std_arg default
# set it to default to get a val out of it next
82 kernel
=$
(fai-chboot
-L '^default$' |
awk '{print $3}')
83 default_k_args
=$
(fai-chboot
-L '^default$' | \
84 sed -r "s/^(\S+\s+){3}(.*)/\2/")
85 # example of default_k_args
86 # initrd=initrd.img-3.16.0-4-amd64 ip=dhcp root=192.168.1.3:/srv/fai/nfsroot aufs FAI_CONFIG_SRC=nfs://faiserver/srv/fai/config FAI_ACTION=install
89 for arg
in $default_k_args; do
91 # default root arg is /srv/fai/nfsroot
92 root
=*) k_args
+=(root
=$root_arg) ;;
96 rm -f /srv
/tftp
/fai
/pxelinux.cfg
/*
97 e fai-chboot
-k "${k_args[*]}" -v -f verbose
,sshd
,createvt
$fai_reboot_arg $std_arg $kernel "$host"