give it a basic password
[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$
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 . build.common
30
31 pldistro=$1 ; shift
32 nodefamily=$1; shift
33
34 # Packages to install, junk and precious : see build/<pldistro>/bootcd.pkgs
35
36 # Do not tolerate errors
37 set -e
38
39 # Root of the initramfs reference image
40 bootcd=$PWD/build/bootcd
41 install -d -m 755 $bootcd
42
43 # Write version number
44 rpmquery --specfile bootcd.spec --queryformat '%{VERSION}\n' | head -1 > build/version.txt
45 echo $nodefamily > build/nodefamily
46
47 # Install base system
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 empty 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 configuration files
62 echo "* Installing configuration files"
63 for file in fstab mtab modprobe.conf inittab hosts sysctl.conf ; do
64     install -D -m 644 etc/$file $bootcd/etc/$file
65 done
66
67 # Install initscripts
68 echo "* Installing initscripts"
69 for file in pl_sysinit pl_hwinit pl_netinit pl_validateconf pl_boot ; do
70     sed -i -e "s,@PLDISTRO@,$pldistro,g" -e "s,@FCDISTRO@,$fcdistro,g" initscripts/$file
71     install -D -m 755 initscripts/$file $bootcd/etc/init.d/$file
72 done
73
74 # connect the scripts for upstart
75 # fedora 9 comes with /sbin/init from upstart, that uses /etc/event.d instead of inittab
76 # (in fact inittab is read for determining the default runlevel)
77 if [ -d $bootcd/etc/event.d ] ; then
78     echo "* Tuning /etc/event.d for upstart"
79     pushd $bootcd/etc/event.d
80     # use our system initialisation script
81     sed -i -e 's,/etc/rc.d/rc.sysinit[a-z\.]*,/etc/init.d/pl_sysinit,g' *
82     # use our startup script in runlevel 2
83     sed -i -e 's,/etc/rc\.d/rc[ \t][ \t]*2,/etc/init.d/pl_boot,g' rc2
84     popd    
85 fi
86
87 # Write nodefamily stamp, to help bootmanager do the right thing
88 mkdir -p $bootcd/etc/planetlab
89 echo $nodefamily > $bootcd/etc/planetlab/nodefamily
90
91 # Install fallback node configuration file
92 echo "* Installing fallback node configuration file"
93 install -D -m 644 usr-boot/default-node.txt $bootcd/usr/boot/default-node.txt
94
95 # Copy /etc/passwd out
96 install -D -m 644 $bootcd/etc/passwd build/passwd
97
98 # Root of the isofs
99 isofs=$PWD/build/isofs
100 install -d -m 755 $isofs
101
102 # Copy the kernel out
103 for kernel in $bootcd/boot/vmlinuz-* ; do
104     if [ -f $kernel ] ; then
105         install -D -m 644 $kernel $isofs/kernel
106     fi
107 done
108
109 # Don't need /boot anymore
110 rm -rf $bootcd/boot
111
112 # initramfs requires that /init be present
113 ln -sf /sbin/init $bootcd/init
114
115 # Pack the rest into a compressed archive
116 echo "* Compressing reference image"
117 (cd $bootcd && find . | cpio --quiet -c -o) | gzip -9 > $isofs/bootcd.img
118
119 exit 0