dev replaced with udev for mkfedora package checking
[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.10 2006/07/24 15:33:07 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 )
77
78 # Unnecessary junk
79 junk=(
80 lib/obsolete
81 lib/tls
82 usr/share/cracklib
83 usr/share/emacs
84 usr/share/gnupg
85 usr/share/i18n
86 usr/share/locale
87 usr/share/terminfo
88 usr/share/zoneinfo
89 usr/sbin/build-locale-archive
90 usr/sbin/dbconverter-2
91 usr/sbin/sasl*
92 usr/sbin/tcpslice
93 usr/lib/perl*
94 usr/lib/locale
95 usr/lib/sasl*
96 usr/lib/gconv
97 usr/lib/tls
98 )
99
100 precious=(
101 usr/share/i18n/locales/en_US
102 usr/share/i18n/charmaps/UTF-8.gz
103 usr/share/locale/en
104 usr/share/terminfo/l/linux
105 usr/share/terminfo/v/vt100
106 usr/share/terminfo/x/xterm
107 usr/share/zoneinfo/UTC
108 usr/lib/locale/en_US.utf8
109 )
110
111 usage()
112 {
113     echo "Usage: prep.sh [OPTION]..."
114     echo "      -r release      Fedora release number (default: $releasever)"
115     echo "      -a arch         Fedora architecture (default: $basearch)"
116     echo "      -h              This message"
117     exit 1
118 }
119
120 # Get options
121 while getopts "r:a:h" opt ; do
122     case $opt in
123         r)
124             releasever=$OPTARG
125             ;;
126         a)
127             basearch=$OPTARG
128             ;;
129         h|*)
130             usage
131             ;;
132     esac
133 done
134
135 # Do not tolerate errors
136 set -e
137
138 # Root of the initramfs reference image
139 bootcd=$PWD/build/bootcd
140 install -d -m 755 $bootcd
141
142 # Write version number
143 rpmquery --specfile bootcd.spec --queryformat '%{VERSION}\n' | head -1 >build/version.txt
144
145 # Install base system
146 for package in "${packagelist[@]}" ; do
147     packages="$packages -p $package"
148 done
149 mkfedora -v -r $releasever -a $basearch -k $packages $bootcd
150
151 pushd $bootcd
152
153 echo "* Removing unnecessary junk"
154
155 # Save precious files
156 tar --ignore-failed-read -cpf precious.tar ${precious[*]}
157
158 # Remove unnecessary junk
159 rm -rf ${junk[*]}
160
161 # Restore precious files
162 tar -xpf precious.tar
163 rm -f precious.tar
164
165 popd
166
167 # Disable all services in reference image
168 chroot $bootcd sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
169
170 # Install configuration files
171 echo "* Installing configuration files"
172 for file in fstab mtab modprobe.conf inittab hosts sysctl.conf ; do
173     install -D -m 644 conf_files/$file $bootcd/etc/$file
174 done
175
176 # Install initscripts
177 echo "* Installing initscripts"
178 for file in pl_sysinit pl_hwinit pl_netinit pl_validateconf pl_boot ; do
179     install -D -m 755 conf_files/$file $bootcd/etc/init.d/$file
180 done
181
182 # Install fallback node configuration file
183 echo "* Installing fallback node configuration file"
184 install -D -m 644 conf_files/default-net.cnf $bootcd/usr/boot/default-net.cnf
185
186 # Build pcitable for hardware detection
187 echo "* Building pcitable for hardware detection"
188 pci_map_file=$(find $bootcd/lib/modules/ -name modules.pcimap | head -1)
189 module_dep_file=$(find $bootcd/lib/modules/ -name modules.dep | head -1)
190 pci_table=$bootcd/usr/share/hwdata/pcitable
191 $srcdir/bootmanager/source/merge_hw_tables.py \
192     $module_dep_file $pci_map_file $pci_table $bootcd/etc/pl_pcitable
193
194 # Copy /etc/passwd out
195 install -D -m 644 $bootcd/etc/passwd build/passwd
196
197 # Root of the isofs
198 isofs=$PWD/build/isofs
199 install -d -m 755 $isofs
200
201 # Copy the kernel out
202 for kernel in $bootcd/boot/vmlinuz-* ; do
203     if [ -f $kernel ] ; then
204         install -D -m 644 $kernel $isofs/kernel
205     fi
206 done
207
208 # Don't need /boot anymore
209 rm -rf $bootcd/boot
210
211 # initramfs requires that /init be present
212 ln -sf /sbin/init $bootcd/init
213
214 # Pack the rest into a compressed archive
215 echo "* Compressing reference image"
216 (cd $bootcd && find . | cpio --quiet -c -o) | gzip -9 >$isofs/bootcd.img
217
218 # Build syslinux
219 echo "* Building syslinux"
220 CFLAGS="-Werror -Wno-unused -finline-limit=2000" make -C syslinux
221
222 # Install isolinux
223 echo "* Installing isolinux"
224 install -D -m 644 syslinux/isolinux.bin $isofs/isolinux.bin
225
226 exit 0