update upstream to 9084a3cbc0a55422beea4a55b530c1f03a910617 feb 2024
[automated-distro-installer] / fai / config / files / etc / rc.local / FAISERVER
1 #! /bin/bash
2
3 # setup script that is only run once at boot time
4 # set up an FAI install server
5
6 NORMAL='\E(B\E[m'
7 RED='\E[31m'
8 GREEN='\E[32m'
9
10 set -o pipefail
11
12 # setup network
13 nic=$(cat /etc/network/interfaces /etc/network/interfaces.d/* 2>/dev/null | awk '$1 == "iface" && $2 != "lo" {print $2; exit}')
14 if [ -n "$nic" ]; then
15 ifup $nic
16 fi
17 # regenerate ssh_host keys
18 ls /etc/ssh/ssh_host_* > /dev/null
19 if [ $? -ne 0 ]; then
20 dpkg-reconfigure -fnoninteractive openssh-server
21 fi
22 sleep 8
23
24 echo "================================="
25 echo "Setting up the FAI install server"
26 echo "This will take a few minutes"
27 echo "================================="
28
29 . /etc/fai/fai.conf
30 . /etc/fai/nfsroot.conf
31
32 # copy the simple examples and pimp my config space
33 if [ ! -d "$FAI_CONFIGDIR/class" ]; then
34 mkdir -p $FAI_CONFIGDIR
35 cp -a /usr/share/doc/fai-doc/examples/simple/* $FAI_CONFIGDIR
36 ainsl /srv/fai/config/class/FAIBASE.var "^LOGUSER=fai"
37 _nic=$(ip route | awk '/^default/ {print $5}'|head -1)
38 myip=$(ip -br ad sh $_nic | awk '{print $3}')
39 myip=${myip%/*}
40 echo "APTPROXY=http://$myip:3142" >> /srv/fai/config/class/DEBIAN.var
41 fi
42 # set the LOGUSER, wo we get all the logs from our install clients
43 ainsl /etc/fai/fai.conf "^LOGUSER=fai"
44
45 # make index, then import the packages from the CD mirror
46 /etc/init.d/apt-cacher-ng restart
47 apt-get update >/dev/null
48 echo "Importing local packages to apt cache"
49 curl -fs 'http://127.0.0.1:3142/acng-report.html?doImport=Start+Import&calcSize=cs&asNeeded=an#bottom' >/dev/null
50 echo "Creating FAI Server setup"
51
52 # setup the FAI server, including creating the nfsroot, use my own proxy
53 export APTPROXY="http://127.0.0.1:3142"
54 if [ -f /var/tmp/base.tar.xz ]; then
55 fai-setup -fvB /var/tmp/base.tar.xz > /var/log/fai/fai-setup.log 2>&1
56 else
57 fai-setup -fv > /var/log/fai/fai-setup.log 2>&1
58 fi
59 if [ $? -eq 0 ]; then
60 rm /var/tmp/base.tar.xz
61 echo ""
62 echo "================================================"
63 echo -e "Setting up the FAI server was ${GREEN}successful${NORMAL}"
64 echo "================================================"
65 echo ""
66 sleep 10
67 else
68 echo ""
69 echo "=================================================="
70 echo -e "${RED}ERROR${NORMAL}: Setting up the FAI install server ${RED}FAILED${NORMAL}!"
71 echo "Read /var/log/fai/fai-setup.log for more debugging"
72 echo "Setup script is now moved to /var/tmp/$0"
73 echo "=================================================="
74 echo ""
75 cp -p $0 /var/tmp
76 sleep 10
77 rm -f $0
78 exit 99
79 fi
80
81 cat <<EOF >> /srv/fai/nfsroot/etc/fai/fai.conf
82 # use short hostname instead of FQDN
83 export HOSTNAME=\${HOSTNAME%%.*}
84 echo \$HOSTNAME > /proc/sys/kernel/hostname
85 EOF
86
87 # create default pxelinux boot configuration
88 fai-chboot -o default
89
90 # create a template for booting the installation
91 fai-chboot -Iv -f verbose,sshd,createvt,menu -u nfs://faiserver/srv/fai/config bookworm.tmpl
92
93 # Since we do not know the MAC address, our DHCP cannot provide the hostname.
94 # Therefore we do explicitly set the hostname
95 fai-chboot -Iv -f verbose,sshd,createvt,menu -u nfs://faiserver/srv/fai/config -k hostname=xfcehost xfcehost
96 fai-chboot -Iv -f verbose,sshd,createvt,menu -u nfs://faiserver/srv/fai/config -k hostname=demohost demohost
97 for c in {01..10}; do
98 fai-chboot -Iv -f verbose,sshd,createvt,menu -u nfs://faiserver/srv/fai/config -k hostname=client$c client$c
99 done
100
101 fai-monitor > /var/log/fai/fai-monitor.log &
102
103 # move me away
104 cp -p $0 /var/tmp
105
106 # create new rc.local for next reboot
107 echo '#! /bin/bash' > /etc/rc.local
108 echo 'fai-monitor > /var/log/fai/fai-monitor.log &' >> /etc/rc.local
109 chmod a+rx /etc/rc.local
110
111 exit 0