use disk/by-id if possibe, other small fixes
[automated-distro-installer] / faiserver-setup
similarity index 72%
rename from fai-setup
rename to faiserver-setup
index dc0dceb57afd2f8cae4dae86fd607149455603fe..54b69f617edcf6ba3966e8ede477c06e56a3b398 100755 (executable)
--- a/fai-setup
@@ -7,6 +7,7 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
 
 [[ $EUID == 0 ]] || exec sudo "${BASH_SOURCE}" "$@"
 
+e() { echo "$@"; "$@"; }
 # for ubuntu:
 #add-apt-repository -y ppa:fai/ppa
 
@@ -18,8 +19,18 @@ EOF
 
 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,
@@ -49,14 +60,14 @@ service tftpd-hpa restart
 # 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
+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
@@ -75,5 +86,9 @@ 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