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