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