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