update to 31b795ca71189b326b80666076398f31aea4f2be
[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 [ -x /etc/init.d/nscd ] && invoke-rc.d nscd restart
24
25 echo "================================="
26 echo "Setting up the FAI install server"
27 echo "This will take a few minutes"
28 echo "================================="
29
30 . /etc/fai/fai.conf
31 . /etc/fai/nfsroot.conf
32
33 # copy the simple examples and pimp my config space
34 if [ ! -d "$FAI_CONFIGDIR/class" ]; then
35 mkdir -p $FAI_CONFIGDIR
36 cp -a /usr/share/doc/fai-doc/examples/simple/* $FAI_CONFIGDIR
37 ainsl /srv/fai/config/class/FAIBASE.var "^LOGUSER=fai"
38 myip=$(ip addr show up| grep -P -o '(?<=inet )[^/]+' | grep -v 127.0.0.1)
39 echo "APTPROXY=http://$myip:3142" >> /srv/fai/config/class/DEBIAN.var
40 fi
41 # set the LOGUSER, wo we get all the logs from our install clients
42 ainsl /etc/fai/fai.conf "^LOGUSER=fai"
43
44 # make index, then import the packages from the CD mirror
45 apt-get update >/dev/null
46 curl -fs 'http://127.0.0.1:3142/acng-report.html?doImport=Start+Import&calcSize=cs&asNeeded=an#bottom' >/dev/null
47
48 # setup the FAI server, including creating the nfsroot, use my own proxy
49 export APTPROXY="http://127.0.0.1:3142"
50 if [ -f /var/tmp/base.tar.xz ]; then
51 fai-setup -fvB /var/tmp/base.tar.xz > /var/log/fai/fai-setup.log 2>&1
52 else
53 fai-setup -fv > /var/log/fai/fai-setup.log 2>&1
54 fi
55 if [ $? -eq 0 ]; then
56 rm /var/tmp/base.tar.xz
57 echo ""
58 echo "================================================"
59 echo -e "Setting up the FAI server was ${GREEN}successful${NORMAL}"
60 echo "================================================"
61 echo ""
62 sleep 10
63 else
64 echo ""
65 echo "=================================================="
66 echo -e "${RED}ERROR${NORMAL}: Setting up the FAI install server ${RED}FAILED${NORMAL}!"
67 echo "Read /var/log/fai/fai-setup.log for more debugging"
68 echo "=================================================="
69 echo ""
70 sleep 10
71 exit 99
72 fi
73
74 cat <<EOF >> /srv/fai/nfsroot/etc/fai/fai.conf
75 # use short hostname instead of FQDN
76 export HOSTNAME=\${HOSTNAME%%.*}
77 echo \$HOSTNAME > /proc/sys/kernel/hostname
78 EOF
79
80 # create default pxelinux boot configuration
81 fai-chboot -o default
82
83 # create a template for booting the installation
84 fai-chboot -Iv -f verbose,sshd,createvt,menu -u nfs://faiserver/srv/fai/config buster.tmpl
85
86 # Since we do not know the MAC address, our DHCP cannot provide the hostname.
87 # Therefore we do explicitly set the hostname
88 fai-chboot -Iv -f verbose,sshd,createvt,menu -u nfs://faiserver/srv/fai/config -k hostname=xfcehost xfcehost
89 fai-chboot -Iv -f verbose,sshd,createvt,menu -u nfs://faiserver/srv/fai/config -k hostname=demohost demohost
90 for c in {01..10}; do
91 fai-chboot -Iv -f verbose,sshd,createvt,menu -u nfs://faiserver/srv/fai/config -k hostname=client$c client$c
92 done
93
94 fai-monitor > /var/log/fai/fai-monitor.log &
95
96 # move me away
97 mv $0 /var/tmp
98
99 # create new rc.local for next reboot
100 echo '#! /bin/bash' > /etc/rc.local
101 echo 'fai-monitor > /var/log/fai/fai-monitor.log &' >> /etc/rc.local
102 chmod a+rx /etc/rc.local
103
104 exit 0