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
11 echo "see help from myfai-chboot"
26 [[ $EUID == 0 ]] ||
exec sudo
"${BASH_SOURCE}" "$@"
31 echo "$0: error: exit code $? from: $*"
38 # assuming ipv4, or else we might need to deal with multiple addresses
39 # in an ipv4 + ipv6 network.
40 my_ip
=$
(ip
-4 route get
8.8.8.8 |
sed -nr 's,^.*src\s+(\S+).*,\1,p')
41 if [[ ! $my_ip ||
$my_ip =~
[[:space
:]] ]]; then
42 echo "$0: error: failed to get \$my_ip, got: $my_ip"
46 if [[ $host == default
]]; then
48 elif [[ $host == [0-9]*.
[0-9]*.
[0-9]*.
[0-9]* ]]; then
51 type -t host &>/dev
/null || apt-get
-y install dnsutils
52 ip
=$
(host $host |
sed -rn 's/^\S+ has address //p;T;q' ||
:)
53 if [[ ! $ip ||
$ip =~
[[:space
:]] ]]; then
54 echo "$0: error: failed to get \$ip, got: $ip"
60 if modprobe nfsd
&>/dev
/null
; then
61 std_arg
="-u nfs://faiserver/srv/fai/config"
62 # nfsv4 wont do rw with overlayfs yet
63 # https://lists.uni-koeln.de/pipermail/linux-fai/2017-March/011641.html
64 root_arg
="$my_ip:/srv/fai/nfsroot:vers=3"
65 # fai-setup without -e sets the ip to the local_ip/local_network, eg 192.168.1.3/24
66 # I restrict it to one ip as simple but imperfect access control.
68 # we may chattr +i /etc/exports if we dun want it modified
69 # for example, if we made these exports more widely available
70 # while doing multiple installs or a recovery.
71 if [[ -w /etc
/exports
]]; then
72 sed -ri --follow-symlinks '\%^/srv/fai/%d' /etc
/exports
73 cat >>/etc
/exports
<<EOF
74 /srv/fai/config $ip(async,ro,no_subtree_check)
75 /srv/fai/nfsroot $ip(async,ro,no_subtree_check,no_root_squash)
79 systemctl start nfs-server
# assumes recent os
81 std_arg
="-u http://faiserver:8080/config.tar.gz"
82 root_arg
="live:http://faiserver:8080/squash.img"
83 /a
/exe
/web-conf
-i -p 8080 - apache2 faiserver
<<EOF
91 rm -f /srv
/tftp
/fai
/pxelinux.cfg
/*
97 # man page doesn't explain this, but this deletes & thus disables
99 e fai-chboot
-iv $std_arg default
# set it to default to get a val out of it next
100 kernel
=$
(fai-chboot
-L '^default$' |
awk '{print $3}')
101 default_k_args
=$
(fai-chboot
-L '^default$' | \
102 sed -r "s/^(\S+\s+){3}(.*)/\2/")
103 # example of default_k_args
104 # 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
106 k_args
=(console
=tty0 console
=ttyS0
,115200 FAI_ACTION
=$fai_action)
107 for arg
in $default_k_args; do
109 # default root arg is /srv/fai/nfsroot
110 root
=*) k_args
+=(root
=$root_arg) ;;
114 rm -f /srv
/tftp
/fai
/pxelinux.cfg
/*
115 e fai-chboot
-k "${k_args[*]}" -v -f verbose
,sshd
,createvt
$fai_reboot_arg $std_arg $kernel "$host"
117 # this is needed for autodiscover iso. i'm not sure, it might override
118 # the fai-chboot method of setting this, i'm not sure.
119 echo FAI_ACTION
=$fai_action >> /srv
/fai
/config
/class
/LAST.var