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