fixed hdw-get & fai routine
[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         [ "$hdw_arch" = "ia32" ] && echo "lilo" >> ./fai/nfsroot-packages
71 fi
72
73 if [ ! -f $fairoot/packages_installed ] ; then
74         echo "creating nfsroot..."
75         chmod 755 ./misc/hdw-tools/hdw-get
76         ./misc/hdw-tools/hdw-get dist-install $fairoot ./fai/nfsroot-packages
77         touch $fairoot/packages_installed
78         echo "done"
79 else
80         echo "nfsroot seems to be available already"
81         echo "(del $fairoot/packages_installed to recreate it)"
82 fi
83
84 if [ ! -f $fairoot/prepared_nfsroot ] ; then
85         echo "preparing nfsroot for automated install routine ..."
86         cd $fairoot
87         # special files (null & console)
88         [ ! -c dev/null ] && mknod -m 0666 dev/null c 1 3
89         [ ! -c dev/console ] && mknod -m 0600 dev/console c 5 1
90         # fstab
91         cp $home_dir/misc/sysfiles/etc/fstab ./etc
92         # the target directory
93         mkdir -p ./trg
94         # dir for mounting fai config
95         mkdir -p fai
96         # removing some services
97         for i in sysklogd network inetd nscd; do
98                 rm -f etc/init.d/rc2.d/*${i}
99         done
100         # modified inittab, rc and bootscript
101         sed "s%| /sbin/btee .*%%g" $home_dir/packages/base/sysvinit/inittab > \
102                 etc/inittab
103         cp $home_dir/misc/fai/fai_boot ./etc/init.d/boot
104         sed "s%^FAI_MOUNT_LINE%mount -tnfs $myip:/$home_dir/fai /fai%" \
105                 $home_dir/misc/fai/fai_rc > etc/init.d/rc
106         chmod 755 etc/init.d/rc
107         # modify hdw-get.conf
108         sed "s%hdw_arch_opt=.*%hdw_arch_opt=$hdw_arch_opt%" etc/hdw-get.conf > \
109                 tmp~
110         mv tmp~ etc/hdw-get.conf
111         # get to home_dir again
112         cd $home_dir
113         echo "done"
114         touch $fairoot/prepared_nfsroot
115 else
116         echo "nfsroot seems to be prepared already"
117         echo "(del $fairoot/prepared_nfsroot to recreate it)"
118 fi
119
120 echo "checking pxe/nfs environment ..."
121 mkdir -p /tftpboot
122 cp $fairoot/boot/vmlinuz_hdw /tftpboot
123 if [ ! -f /tftpboot/pxelinux.0 ] ; then
124         if [ ! -f /usr/lib/syslinux/pxelinux.0 ] ; then
125                 echo "pxelinux (syslinux) not found, fix this manually now :p"
126         fi
127         cp /usr/lib/syslinux/pxelinux.0 /tftpboot
128 fi
129 mkdir -p /tftpboot/pxelinux.cfg
130 cat > /tftpboot/pxelinux.cfg/fai << EOF
131 PROMPT 1
132 DEFAULT disk
133 TIMEOUT 200
134
135 LABEL fai
136         KERNEL vmlinuz_hdw
137         APPEND root=/dev/nfs nfsroot=$myip:$fairoot ip=dhcp
138
139 LABEL disk
140         LOCALBOOT 0
141 EOF
142 echo -e "$fairoot\tfoobar(async,ro,no_root_squash)" >> /etc/exports
143 echo -e "$home_dir/fai\tfoobar(async,ro,no_root_squash)" >> /etc/exports
144
145 echo "everything should work now. now do the following:"
146 echo "1) edit /etc/exports to allow your clients to mount the nfsroot"
147 echo "2) link the ipaddr in hex of the client to fai in pxe config dir"
148 echo "3) tell your dhcpd (see syslinux docs for more help)"
149 echo "4) make sure inetd/nfs/dhcpd are up running"
150 echo "5) do the configuration stuff (see doc/FAI)"
151 echo
152 echo "note: tftp must support tsize option (use e.g. tftp-hpa package)"
153 echo
154
155 echo "done"