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