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 # assuming ipv4, or else we might need to deal with multiple addresses
35 # in an ipv4 + ipv6 network.
36 my_ip
=$
(ip
-4 route get
8.8.8.8 |
sed -nr 's,^.*src\s+(\S+).*,\1,p')
37 if [[ $x =~
[[:space
:]] ]]; then
38 echo "$0: error: failed to get \$my_ip, got: $my_ip"
42 if [[ $host == default
]]; then
44 elif [[ $host == [0-9]*.
[0-9]*.
[0-9]*.
[0-9]* ]]; then
47 type -t host &>/dev
/null || apt-get
-y install dnsutils
48 ip
=$
(host $host |
sed -rn 's/^\S+ has address //p;T;q')/32
51 if modprobe nfsd
&>/dev
/null
; then
52 std_arg
="-u nfs://faiserver/srv/fai/config"
53 # nfsv4 wont do rw with overlayfs yet
54 # https://lists.uni-koeln.de/pipermail/linux-fai/2017-March/011641.html
55 root_arg
="$my_ip:/srv/fai/nfsroot:vers=3"
56 # fai-setup without -e sets the ip to the local_ip/local_network, eg 192.168.1.3/24
57 # I restrict it to one ip as simple but imperfect access control.
58 sed -ri --follow-symlinks '\%^/srv/fai/%d' /etc
/exports
59 cat >>/etc
/exports
<<EOF
60 /srv/fai/config $ip(async,ro,no_subtree_check)
61 /srv/fai/nfsroot $ip(async,ro,no_subtree_check,no_root_squash)
64 systemctl start nfs-server
# assumes recent os
66 std_arg
="-u http://faiserver:8080/config.tar.gz"
67 root_arg
="live:http://faiserver:8080/squash.img"
68 /a
/exe
/web-conf
-i -p 8080 - apache2 faiserver
<<EOF
76 rm -f /srv
/tftp
/fai
/pxelinux.cfg
/*
82 # man page doesn't explain this, but this deletes & thus disables
84 e fai-chboot
-${fai_action_arg}v
$std_arg default
# set it to default to get a val out of it next
85 kernel
=$
(fai-chboot
-L '^default$' |
awk '{print $3}')
86 default_k_args
=$
(fai-chboot
-L '^default$' | \
87 sed -r "s/^(\S+\s+){3}(.*)/\2/")
88 # example of default_k_args
89 # 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
92 for arg
in $default_k_args; do
94 # default root arg is /srv/fai/nfsroot
95 root
=*) k_args
+=(root
=$root_arg) ;;
99 rm -f /srv
/tftp
/fai
/pxelinux.cfg
/*
100 e fai-chboot
-k "${k_args[*]}" -v -f verbose
,sshd
,createvt
$fai_reboot_arg $std_arg $kernel "$host"