[[ $EUID == 0 ]] || exec sudo "${BASH_SOURCE}" "$@"
+e() { echo "$@"; "$@"; }
# for ubuntu:
#add-apt-repository -y ppa:fai/ppa
apt-get update
# all the dependencies except the dhcp server
-apt-get -y install $(apt-cache show fai-quickstart | grep ^Depends: |head -n 1|\
- sed -r 's/^Depends:|,|\|[^,]+|isc-dhcp-server//g')
+deps="$(apt-cache show fai-quickstart | grep ^Depends: |head -n 1|\
+ sed -r 's/^Depends:|,|\|[^,]+|isc-dhcp-server//g')"
+to_install=()
+for pkg in $deps; do
+ dpkg -s $pkg &>/dev/null && continue ||:
+ to_install+=($pkg)
+ echo $pkg >> /etc/fai/fai-manually-installed-packages
+done
+if [[ $to_install ]]; then
+ apt-get -y install ${to_install[@]}
+fi
+
sed -i 's/^#deb/deb/' /etc/fai/apt/sources.list
sed -i 's/#LOGUSER/LOGUSER/' /etc/fai/fai.conf
# from man fai-make-nfsroot,
# Add debug to -f flag for more verbose output.
std_arg="-u nfs://faiserver/srv/fai/config"
-fai-chboot -Iv $std_arg default
+fai-chboot -Iv $std_arg default # reset so we are idempotent
kernel=$(fai-chboot -L '^default$' | awk '{print $3}')
type -t host &>/dev/null || apt-get -y install dnsutils
my_ip=$(host faiserver $(route -n | sed -rn 's/^(0\.){3}0\s+(\S+).*/\2/p') | \
- sed -rn 's/^faiserver has address //p')
+ sed -rn 's/^\S+ has address //p')
k_args=$(fai-chboot -L '^default$' | \
sed -r "s/^(\S+\s+){3}(.*root=)(.*)/\2$my_ip:\3/")
-fai-chboot -k "$k_args" -v -f verbose,sshd,createvt,reboot $std_arg $kernel default
+e fai-chboot -k "$k_args" -v -f verbose,sshd,createvt,reboot $std_arg $kernel default
# make the faiserver also the apt proxy server
apt-get -y install apt-cacher-ng
# random fai note: as far as I can tell, profiles are just for putting
# in a selectable boot menu, which I don't want.
-# somewhere I call it faiserver, but debian's default is faiserver.lan
-sed -ri 's/faiserver.lan/faiserver/' /srv/fai/nfsroot/root/.ssh/known_hosts
+# the logsave prompted because the hostname faiserver was uknown.
+# Here it was faiserver.lan when running from a faiserver vm.
+# When running from a normal host with faiserver alias, it was the normal hosts name.
+sed -ri 's/(^[^,]+,)\S+/\1faiserver/' /srv/fai/nfsroot/root/.ssh/known_hosts
+# ditch the logo banner up top which screws with less.
+touch /srv/fai/nfsroot/.nocolorlogo