bug fix
[automated-distro-installer] / fai / config / files / etc / rc.local / FAISERVER
index 8710678a1991c0e1c8dc575e15754dd6b4307d25..69a4ee03e47d5948b3247ecd37f493c11d0baab0 100755 (executable)
@@ -10,15 +10,16 @@ GREEN='\E[32m'
 set -o pipefail
 
 # setup network
-nic=$(awk '/iface/ {print $2}' /etc/network/interfaces |egrep -v ^lo)
-ifup $nic
+nic=$(cat /etc/network/interfaces /etc/network/interfaces.d/* 2>/dev/null | awk '$1 == "iface" && $2 != "lo" {print $2; exit}')
+if [ -n "$nic" ]; then
+    ifup $nic
+fi
 # regenerate ssh_host keys
 ls /etc/ssh/ssh_host_* > /dev/null
 if [ $? -ne 0 ]; then
     dpkg-reconfigure -fnoninteractive openssh-server
 fi
 sleep 8
-[ -x /etc/init.d/nscd ] && invoke-rc.d nscd restart
 
 echo "================================="
 echo "Setting up the FAI install server"
@@ -33,15 +34,20 @@ if [ ! -d "$FAI_CONFIGDIR/class" ]; then
     mkdir -p $FAI_CONFIGDIR
     cp -a /usr/share/doc/fai-doc/examples/simple/* $FAI_CONFIGDIR
     ainsl /srv/fai/config/class/FAIBASE.var "^LOGUSER=fai"
-    myip=$(ip addr show up| grep -w inet | cut -d t -f 2 | cut -d ' ' -f 2 | cut -d / -f 1 | grep -v 127.0.0.1)
+    _nic=$(ip route | awk '/^default/ {print $5}'|head -1)
+    myip=$(ip -br ad sh $_nic | awk '{print $3}')
+    myip=${myip%/*}
     echo "APTPROXY=http://$myip:3142" >> /srv/fai/config/class/DEBIAN.var
 fi
 # set the LOGUSER, wo we get all the logs from our install clients
 ainsl /etc/fai/fai.conf "^LOGUSER=fai"
 
 # make index, then import the packages from the CD mirror
+/etc/init.d/apt-cacher-ng restart
 apt-get update >/dev/null
+echo "Importing local packages to apt cache"
 curl -fs 'http://127.0.0.1:3142/acng-report.html?doImport=Start+Import&calcSize=cs&asNeeded=an#bottom' >/dev/null
+echo "Creating FAI Server setup"
 
 # setup the FAI server, including creating the nfsroot, use my own proxy
 export APTPROXY="http://127.0.0.1:3142"
@@ -63,9 +69,12 @@ else
     echo "=================================================="
     echo -e "${RED}ERROR${NORMAL}: Setting up the FAI install server ${RED}FAILED${NORMAL}!"
     echo "Read /var/log/fai/fai-setup.log for more debugging"
+    echo "Setup script is now moved to /var/tmp/$0"
     echo "=================================================="
     echo ""
+    cp -p $0 /var/tmp
     sleep 10
+    rm -f $0
     exit 99
 fi
 
@@ -79,7 +88,7 @@ EOF
 fai-chboot -o default
 
 # create a template for booting the installation
-fai-chboot -Iv -f verbose,sshd,createvt,menu -u nfs://faiserver/srv/fai/config stretch.tmpl
+fai-chboot -Iv -f verbose,sshd,createvt,menu -u nfs://faiserver/srv/fai/config bookworm.tmpl
 
 # Since we do not know the MAC address, our DHCP cannot provide the hostname.
 # Therefore we do explicitly set the hostname
@@ -92,7 +101,7 @@ done
 fai-monitor > /var/log/fai/fai-monitor.log &
 
 # move me away
-mv $0 /var/tmp
+cp -p $0 /var/tmp
 
 # create new rc.local for next reboot
 echo '#! /bin/bash' > /etc/rc.local