0d0a87292114c6b0e9e041a6869a23c2926238a8
[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
12 PATH=/sbin:/bin:/usr/sbin:/usr/bin
13
14 # In both a normal CVS environment and a PlanetLab RPM
15 # build environment, all of our dependencies are checked out into
16 # directories at the same level as us.
17 if [ -d ../build ] ; then
18     PATH=$PATH:../build
19     srcdir=..
20 else
21     echo "Error: Could not find sources in either . or .."
22     exit 1
23 fi
24
25 export PATH
26
27 . build.common
28
29 pldistro=$1 ; shift
30 nodefamily=$1; shift
31 rpmversion=$1; shift
32
33 # Packages to install, junk and precious : see build/<pldistro>/bootcd.pkgs
34
35 # Do not tolerate errors
36 set -e
37
38 # Root of the initramfs reference image
39 bootcd=$PWD/build/bootcd
40 install -d -m 755 $bootcd
41
42 # Write version number
43 echo ${rpmversion} > build/version.txt
44 echo ${nodefamily} > build/nodefamily
45
46 # Install base system
47 echo "* Creating fedora root image"
48 pl_root_makedevs $bootcd
49 pkgsfile=$(pl_locateDistroFile ../build/ $pldistro bootcd.pkgs) 
50 pl_root_mkfedora $bootcd $pldistro $pkgsfile
51 pl_root_tune_image $bootcd
52
53 # Add site_admin console account to BootCD: with root priv, and self passwd
54 CRYPT_SA_PASSWORD=$(python -c "import crypt, random, string; salt = [random.choice(string.letters + string.digits + \"./\") for i in range(0,8)] ; print crypt.crypt('site_admin', '\$1\$' + \"\".join(salt) + '\$')")
55 chroot ${bootcd} /usr/sbin/useradd -p "$CRYPT_SA_PASSWORD" -o -g 0 -u 0 -m site_admin
56
57 # Install ipnmac (for SuperMicro machines with IPMI)
58 echo "* Installing IPMI utilities"
59 install -D -m 755 ipnmac/ipnmac.x86 $bootcd/usr/sbin/ipnmac
60
61 # Install initscripts
62 echo "* Installing initscripts"
63 for file in pl_functions pl_sysinit pl_hwinit pl_netinit pl_validateconf pl_boot ; do
64     sed -i -e "s,@PLDISTRO@,$pldistro,g" -e "s,@FCDISTRO@,$fcdistro,g" initscripts/$file
65     install -D -m 755 initscripts/$file $bootcd/etc/init.d/$file
66 done
67
68 # Install configuration files
69 echo "* Installing configuration files"
70 for file in fstab mtab modprobe.conf inittab hosts sysctl.conf ; do
71     install -D -m 644 etc/$file $bootcd/etc/$file
72 done
73 # connect our initscripts scripts for upstart
74 # fedora 9 comes with /sbin/init from upstart, that uses /etc/event.d instead of inittab
75 # (in fact inittab is read for determining the default runlevel)
76 if [ -d $bootcd/etc/event.d ] ; then
77     echo "* Tuning /etc/event.d/ for upstart"
78     pushd $bootcd/etc/event.d
79     # use our system initialisation script
80     sed -i -e 's,/etc/rc\.d/rc\.sysinit[a-z\.]*,/etc/init.d/pl_sysinit,g' rcS
81     # use our startup script in runlevel 2
82     sed -i -e 's,/etc/rc\.d/rc[ \t][ \t]*2,/etc/init.d/pl_boot,g' rc2
83     popd    
84 fi
85 # ditto for f14 and higher init style
86 if [ -d $bootcd/etc/init ] ; then
87     echo "* Tuning /etc/init/ for upstart"
88     pushd $bootcd/etc/init
89     # use our system initialisation script
90     sed -i -e 's,/etc/rc\.d/rc\.sysinit[a-z\.]*,/bin/bash -c /etc/init.d/pl_sysinit,g' rcS.conf
91     # use our startup script in runlevel 2
92     sed -i -e 's,/etc/rc.d/rc[a-z\.]*,/etc/init.d/pl_boot,g' rc.conf
93     popd    
94 fi
95 # Install systemd files for f16 and above
96 if [ -d $bootcd/etc/systemd/system ] ; then
97     echo "* Installing systemd files"
98     for file in pl_boot.service pl_boot.target ; do
99         install -D -m 644 systemd/$file $bootcd/etc/systemd/system
100     done
101     echo "* Enabling getty on tty2"
102     # select pl_boot target this way instead of using kargs, as kargs apply to kexec boot as well
103     ln -sf /etc/systemd/system/pl_boot.target $bootcd/etc/systemd/system/default.target
104     [ -d $bootcd/etc/systemd/system/pl_boot.target.wants ] || mkdir -p $bootcd/etc/systemd/system/pl_boot.target.wants
105     ln -sf /usr/lib/systemd/system/getty@.service $bootcd/etc/systemd/system/pl_boot.target.wants/getty@tty2.service
106 fi
107
108 # Install fallback node configuration file
109 echo "* Installing fallback node configuration file"
110 install -D -m 644 usr-boot/default-node.txt $bootcd/usr/boot/default-node.txt
111
112 # Copy /etc/passwd out
113 install -D -m 644 $bootcd/etc/passwd build/passwd
114
115 # Root of the isofs
116 isofs=$PWD/build/isofs
117 install -d -m 755 $isofs
118
119 # Copy the kernel out
120 for kernel in $bootcd/boot/vmlinuz-* ; do
121     if [ -f $kernel ] ; then
122         install -D -m 644 $kernel $isofs/kernel
123     fi
124 done
125
126 # Don't need /boot anymore
127 rm -rf $bootcd/boot
128
129 # initramfs requires that /init be present
130 ln -sf /sbin/init $bootcd/init
131
132 # Pack the rest into a compressed archive
133 echo "* Compressing reference image"
134 (cd $bootcd && find . | cpio --quiet -c -o) | gzip -9 > $isofs/bootcd.img
135
136 exit 0