Some cleanup + ntp, and disconnected operations.
[bootcd.git] / prep.sh
1 #!/bin/bash
2 #
3 # Builds the BootCD reference image, the first of two
4 # initramfs cpio archives that are concatenated together by
5 # isolinux/syslinux to form a custom BootCD.
6 #
7 # Aaron Klingaman <alk@absarokasoft.com>
8 # Mark Huang <mlhuang@cs.princeton.edu>
9 # Copyright (C) 2004-2006 The Trustees of Princeton University
10 #
11 # $Id: prep.sh,v 1.13 2006/08/21 20:45:23 mlhuang Exp $
12 #
13
14 PATH=/sbin:/bin:/usr/sbin:/usr/bin
15
16 # In both a normal CVS environment and a PlanetLab RPM
17 # build environment, all of our dependencies are checked out into
18 # directories at the same level as us.
19 if [ -d ../build ] ; then
20     PATH=$PATH:../build
21     srcdir=..
22 else
23     echo "Error: Could not find sources in either . or .."
24     exit 1
25 fi
26
27 export PATH
28
29 # Release and architecture to install
30 releasever=4
31 basearch=i386
32
33 # Packages to install
34 packagelist=(
35 filesystem
36 udev
37 dhclient
38 bash
39 coreutils
40 iputils
41 kernel
42 bzip2
43 diffutils
44 logrotate
45 passwd
46 rsh
47 rsync
48 sudo
49 tcpdump
50 telnet
51 traceroute
52 time
53 wget
54 yum
55 curl
56 gzip
57 python
58 tar
59 pciutils
60 kbd
61 authconfig
62 hdparm
63 lvm
64 lvm2
65 kexec-tools
66 gnupg
67 nano
68 parted
69 pyparted
70 openssh-server
71 openssh-clients
72 ncftp
73 dosfstools
74 dos2unix
75 bind-utils
76 sharutils
77 vconfig
78 ntp
79 )
80
81 # Unnecessary junk
82 junk=(
83 lib/obsolete
84 lib/tls
85 usr/share/cracklib
86 usr/share/emacs
87 usr/share/gnupg
88 usr/share/i18n
89 usr/share/locale
90 usr/share/terminfo
91 usr/share/zoneinfo
92 usr/sbin/build-locale-archive
93 usr/sbin/dbconverter-2
94 usr/sbin/sasl*
95 usr/sbin/tcpslice
96 usr/lib/perl*
97 usr/lib/locale
98 usr/lib/sasl*
99 usr/lib/gconv
100 usr/lib/tls
101 )
102
103 precious=(
104 usr/share/i18n/locales/en_US
105 usr/share/i18n/charmaps/UTF-8.gz
106 usr/share/locale/en
107 usr/share/terminfo/l/linux
108 usr/share/terminfo/v/vt100
109 usr/share/terminfo/x/xterm
110 usr/share/zoneinfo/UTC
111 usr/lib/locale/en_US.utf8
112 )
113
114 usage()
115 {
116     echo "Usage: prep.sh [OPTION]..."
117     echo "      -r release      Fedora release number (default: $releasever)"
118     echo "      -a arch         Fedora architecture (default: $basearch)"
119     echo "      -h              This message"
120     exit 1
121 }
122
123 # Get options
124 while getopts "r:a:h" opt ; do
125     case $opt in
126         r)
127             releasever=$OPTARG
128             ;;
129         a)
130             basearch=$OPTARG
131             ;;
132         h|*)
133             usage
134             ;;
135     esac
136 done
137
138 # Do not tolerate errors
139 set -e
140
141 # Root of the initramfs reference image
142 bootcd=$PWD/build/bootcd
143 install -d -m 755 $bootcd
144
145 # Write version number
146 rpmquery --specfile bootcd.spec --queryformat '%{VERSION}\n' | head -1 >build/version.txt
147
148 # Install base system
149 for package in "${packagelist[@]}" ; do
150     packages="$packages -p $package"
151 done
152 mkfedora -v -r $releasever -a $basearch -k $packages $bootcd
153
154 pushd $bootcd
155
156 echo "* Removing unnecessary junk"
157
158 # Save precious files
159 tar --ignore-failed-read -cpf precious.tar ${precious[*]}
160
161 # Remove unnecessary junk
162 rm -rf ${junk[*]}
163
164 # Restore precious files
165 tar -xpf precious.tar
166 rm -f precious.tar
167
168 popd
169
170 # Disable all services in reference image
171 chroot $bootcd sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
172
173 # Install ipnmac (for SuperMicro machines with IPMI)
174 echo "* Installing IPMI utilities"
175 install -D -m 755 ipnmac/ipnmac.x86 $bootcd/usr/sbin/ipnmac
176
177 # Install configuration files
178 echo "* Installing configuration files"
179 for file in fstab mtab modprobe.conf inittab hosts sysctl.conf ; do
180     install -D -m 644 conf_files/$file $bootcd/etc/$file
181 done
182
183 # Install initscripts
184 echo "* Installing initscripts"
185 for file in pl_sysinit pl_hwinit pl_netinit pl_validateconf pl_boot ; do
186     install -D -m 755 conf_files/$file $bootcd/etc/init.d/$file
187 done
188
189 # Install fallback node configuration file
190 echo "* Installing fallback node configuration file"
191 install -D -m 644 conf_files/default-net.cnf $bootcd/usr/boot/default-net.cnf
192
193 # Build pcitable for hardware detection
194 echo "* Building pcitable for hardware detection"
195 pci_map_file=$(find $bootcd/lib/modules/ -name modules.pcimap | head -1)
196 module_dep_file=$(find $bootcd/lib/modules/ -name modules.dep | head -1)
197 pci_table=$bootcd/usr/share/hwdata/pcitable
198 $srcdir/bootmanager/source/merge_hw_tables.py \
199     $module_dep_file $pci_map_file $pci_table $bootcd/etc/pl_pcitable
200
201 # Copy /etc/passwd out
202 install -D -m 644 $bootcd/etc/passwd build/passwd
203
204 # Root of the isofs
205 isofs=$PWD/build/isofs
206 install -d -m 755 $isofs
207
208 # Copy the kernel out
209 for kernel in $bootcd/boot/vmlinuz-* ; do
210     if [ -f $kernel ] ; then
211         install -D -m 644 $kernel $isofs/kernel
212     fi
213 done
214
215 # Don't need /boot anymore
216 rm -rf $bootcd/boot
217
218 # initramfs requires that /init be present
219 ln -sf /sbin/init $bootcd/init
220
221 # Pack the rest into a compressed archive
222 echo "* Compressing reference image"
223 (cd $bootcd && find . | cpio --quiet -c -o) | gzip -9 >$isofs/bootcd.img
224
225 # Build syslinux
226 echo "* Building syslinux"
227 CFLAGS="-Werror -Wno-unused -finline-limit=2000" make -C syslinux
228
229 # Install isolinux
230 echo "* Installing isolinux"
231 install -D -m 644 syslinux/isolinux.bin $isofs/isolinux.bin
232
233 exit 0