3 # note, this script gets piped to bash, so cant cd to current dir
5 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
12 echo "see help from myfai-chboot"
22 [[ $EUID == 0 ]] ||
exec sudo
"${BASH_SOURCE}" "$@"
27 echo "$0: error: exit code $? from: $*"
34 type -t host &>/dev
/null || apt-get
-y install dnsutils
35 gateway_if
=$
(ip route |
sed -rn 's/^default via \S+ dev (\S+) .*/\1/p')
36 if [[ ! $gateway_if ]]; then
37 echo "$0: failed to find gateway interface"
40 # assuming ipv4, or else we might need to deal with multiple addresses
41 # in an ipv4 + ipv6 network.
42 network
=$
(ip
-4 -o a show dev
$gateway_if |
sed -rn '/scope.*global/s/^(\S+\s+){3}(\S+)\s.*/\2/p')
43 if [[ ! $network ]]; then
44 echo "$0: failed to find network"
48 if [[ $host == default
]]; then
50 elif [[ $host == [0-9]*.
[0-9]*.
[0-9]*.
[0-9]* ]]; then
53 ip
=$
(host $host |
sed -rn 's/^\S+ has address //p;T;q')/32
57 # alternate way of getting my ip
58 #gateway_ip=$(ip route | sed -rn 's/^default via (\S+) .*/\1/p')
59 #my_ip=$(host faiserver $gateway_ip | sed -rn 's/^\S+ has address //p;T;q')
61 if modprobe nfsd
&>/dev
/null
; then
62 std_arg
="-u nfs://faiserver/srv/fai/config"
63 root_arg
="$my_ip:/srv/fai/nfsroot"
64 # fai-setup without -e sets the ip to the local_ip/local_network, eg 192.168.1.3/24
65 # I restrict it to one ip as simple but imperfect access control.
66 sed -ri --follow-symlinks '\%^/srv/fai/%d' /etc
/exports
67 cat >>/etc
/exports
<<EOF
68 /srv/fai/config $ip(async,ro,no_subtree_check)
69 /srv/fai/nfsroot $ip(async,ro,no_subtree_check,no_root_squash)
73 std_arg
="-u http://faiserver:8080/config.tar.gz"
74 root_arg
="live:http://faiserver:8080/squash.img"
75 /a
/exe
/web-conf
-i -p 8080 - apache2 faiserver
<<EOF
83 rm -f /srv
/tftp
/fai
/pxelinux.cfg
/*
89 # man page doesn't explain this, but this deletes & thus disables
91 e fai-chboot
-${fai_action_arg}v
$std_arg default
# set it to default to get a val out of it next
92 kernel
=$
(fai-chboot
-L '^default$' |
awk '{print $3}')
93 default_k_args
=$
(fai-chboot
-L '^default$' | \
94 sed -r "s/^(\S+\s+){3}(.*)/\2/")
95 # example of default_k_args
96 # 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
99 for arg
in $default_k_args; do
101 # default root arg is /srv/fai/nfsroot
102 root
=*) k_args
+=(root
=$root_arg) ;;
106 rm -f /srv
/tftp
/fai
/pxelinux.cfg
/*
107 e fai-chboot
-k "${k_args[*]}" -v -f verbose
,sshd
,createvt
$fai_reboot_arg $std_arg $kernel "$host"