reorganized Config file
[hdw-linux/hdw-linux.git] / scripts / Create-FAI
1 #!/bin/bash
2 #
3 # author: hackbard@hackdaworld.dyndns.org
4 #
5 # script creating a minimal system nfsroot for automated installation of hdw
6 #
7
8 home_dir=$PWD
9 fairoot="$1"
10 iface="eth0"
11
12 [ "$2" ] && iface="$2"
13
14 myip="`ifconfig $iface | grep inet\ addr | awk '{ print $2 }' | awk -F: '{ print $2 }'`"
15
16 if [ -z $myip ] ; then
17         echo "unable to figure out your ip addr."
18         echo "pls specify the network interface."
19         echo
20         echo "example: $0 $1 br0"
21         echo
22         exit
23 fi
24
25 usage() {
26         echo
27         echo "usage:"
28         echo "$0 <fai-root> [<network interface>]"
29         echo
30         exit
31         }
32
33 [ "$#" -lt "1" ] && usage
34 [ ! -d $fairoot ] && usage
35
36 echo "reading config ..."
37 if [ ! -f ./Config ] ; then
38         echo "config file not found, aborting"
39         exit
40 fi
41 . ./Config
42
43 if [ ! -f ./fai/nfsroot-packages ] ; then
44         echo "storing $hdw_target as original target"
45         hdw_orig_target=$hdw_target
46
47         echo "pretending default target for nfsroot install now"
48         export hdw_target=default
49         echo "hdw_target=default # FAI_WAS_HERE" >> Config # dirty!
50
51         ./scripts/Helper -create_dist_files
52
53         export hdw_target=$hdw_orig_target
54         grep -v '# FAI_WAS_HERE' Config > tmp~
55         mv tmp~ Config
56         echo "orig target restored to $hdw_target"
57
58         cp ./distro/default ./fai/nfsroot-packages
59
60         echo "deleting some packages from list now"
61         del="linux-libc-headers man-pages binutils gcc m4 autoconf automake"
62         del="$del man make patch bin86 nasm lilo cvs devfsd"
63         del="$del bootdisk" # just by now - may contain kernel image later
64         for package in $del; do
65                 grep -v ^$package ./fai/nfsroot-packages > ./fai/tmp~
66                 mv ./fai/tmp~ ./fai/nfsroot-packages
67         done
68         echo "adding needed packages to list now"
69         echo "portmap" >> ./fai/nfsroot-packages
70         echo "tcp_wrappers" >> ./fai/nfsroot-packages
71         [ "$hdw_arch" = "ia32" ] && echo "lilo" >> ./fai/nfsroot-packages
72 fi
73
74 if [ ! -f $fairoot/packages_installed ] ; then
75         echo "creating nfsroot..."
76         chmod 755 ./misc/hdw-tools/hdw-get
77         ./misc/hdw-tools/hdw-get dist-install $fairoot ./fai/nfsroot-packages
78         touch $fairoot/packages_installed
79         echo "done"
80 else
81         echo "nfsroot seems to be available already"
82         echo "(del $fairoot/packages_installed to recreate it)"
83 fi
84
85 if [ ! -f $fairoot/prepared_nfsroot ] ; then
86         echo "preparing nfsroot for automated install routine ..."
87         cd $fairoot
88         # special files (null & console)
89         [ ! -c dev/null ] && mknod -m 0666 dev/null c 1 3
90         [ ! -c dev/console ] && mknod -m 0600 dev/console c 5 1
91         # fstab
92         cp $home_dir/misc/sysfiles/etc/fstab ./etc
93         # the target directory
94         mkdir -p ./trg
95         # dir for mounting fai config
96         mkdir -p fai
97         # removing some services
98         for i in sysklogd network inetd nscd; do
99                 rm -f etc/init.d/rc2.d/*${i}
100         done
101         # modified inittab, rc and bootscript
102         sed "s%| /sbin/btee .*%%g" $home_dir/packages/base/sysvinit/inittab > \
103                 etc/inittab
104         cp $home_dir/misc/fai/fai_boot ./etc/init.d/boot
105         sed "s%^FAI_MOUNT_LINE%mount -tnfs $myip:/$home_dir/fai /fai%" \
106                 $home_dir/misc/fai/fai_rc > etc/init.d/rc
107         chmod 755 etc/init.d/rc
108         # modify hdw-get.conf
109         sed "s%hdw_arch_opt=.*%hdw_arch_opt=$hdw_arch_opt%" etc/hdw-get.conf > \
110                 tmp~
111         mv tmp~ etc/hdw-get.conf
112         # get to home_dir again
113         cd $home_dir
114         echo "done"
115         touch $fairoot/prepared_nfsroot
116 else
117         echo "nfsroot seems to be prepared already"
118         echo "(del $fairoot/prepared_nfsroot to recreate it)"
119 fi
120
121 echo "checking pxe/nfs environment ..."
122 mkdir -p /tftpboot
123 cp $fairoot/boot/vmlinuz_hdw /tftpboot
124 if [ ! -f /tftpboot/pxelinux.0 ] ; then
125         if [ ! -f /usr/lib/syslinux/pxelinux.0 ] ; then
126                 echo "pxelinux (syslinux) not found, fix this manually now :p"
127         fi
128         cp /usr/lib/syslinux/pxelinux.0 /tftpboot
129 fi
130 mkdir -p /tftpboot/pxelinux.cfg
131 cat > /tftpboot/pxelinux.cfg/fai << EOF
132 PROMPT 1
133 DEFAULT disk
134 TIMEOUT 200
135
136 LABEL fai
137         KERNEL vmlinuz_hdw
138         APPEND root=/dev/nfs nfsroot=$myip:$fairoot ip=dhcp
139
140 LABEL disk
141         LOCALBOOT 0
142 EOF
143 echo -e "$fairoot\tfoobar(async,ro,no_root_squash)" >> /etc/exports
144 echo -e "$home_dir/fai\tfoobar(async,ro,no_root_squash)" >> /etc/exports
145
146 echo "everything should work now. now do the following:"
147 echo "1) edit /etc/exports to allow your clients to mount the nfsroot"
148 echo "2) link the ipaddr in hex of the client to fai in pxe config dir"
149 echo "3) tell your dhcpd (see syslinux docs for more help)"
150 echo "4) make sure inetd/nfs/dhcpd are up running"
151 echo "5) do the configuration stuff (see doc/FAI)"
152 echo "6) adapt the hdw-get.conf file in the fai nfsroot tree"
153 echo
154 echo "note: tftp must support tsize option (use e.g. tftp-hpa package)"
155 echo
156
157 echo "done"