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