a005502998d0d9c7d124362560221e3912ae3241
[bootmanager.git] / support-files / buildnode.sh
1 #!/bin/bash
2 #
3 # Build PlanetLab-Bootstrap.tar.bz2, the reference image for PlanetLab
4 # nodes. Requires the web and boot servers to be up, which complicates
5 # bootstrap. Alternatively, we could require the build server to host
6 # a local yum repository. Already, it is required to run the same
7 # major version of yum as the nodes.
8 #
9 # Mark Huang <mlhuang@cs.princeton.edu>
10 # Copyright (C) 2005 The Trustees of Princeton University
11 #
12 # $Id: buildnode.sh,v 1.3 2005/10/03 14:34:58 mlhuang Exp $
13 #
14
15 # Get the production /etc/yum.conf file. XXX When MAs begin deploying
16 # their own boot servers and/or code, this will have to change.
17 curl --silent http://boot.planet-lab.org/$(curl --silent --insecure --form node_id=1 --form file=/etc/yum.conf https://boot.planet-lab.org/db/plnodeconf/getsinglefile.php) > yum.conf
18
19 # Solve the bootstrap problem by including any just built packages in
20 # the yum configuration. This cooperates with the PlanetLab build
21 # system.
22 if [ -n "$RPM_BUILD_DIR" ] ; then
23     # Remove any [PlanetLab*] sections
24     sed -i -f - yum.conf <<EOF
25 # Match lines between [PlanetLab*] and the next [*
26 /\[PlanetLab.*\]/I,/^\[/{
27 # Delete [PlanetLab*]
28 /\[PlanetLab.*\]/Id
29 # Done when we see [*
30 /^\[/b
31 # Otherwise delete
32 d
33 }
34 EOF
35
36     # And replace them with a section for the RPMS that were just built
37     yum-arch $(dirname $RPM_BUILD_DIR)/RPMS
38     cat >> yum.conf <<EOF
39 [Bootstrap]
40 name=Bootstrap RPMS -- $(dirname $RPM_BUILD_DIR)/RPMS/
41 baseurl=file://$(dirname $RPM_BUILD_DIR)/RPMS/
42 EOF
43 fi
44
45 # Make /
46 VROOT=$PWD/PlanetLab-Bootstrap
47 install -d -m 755 $VROOT
48
49 MAKEDEV ()
50 {
51     rm -rf $VROOT/dev
52     mkdir -p $VROOT/dev
53     mknod -m 666 $VROOT/dev/null c 1 3
54     mknod -m 666 $VROOT/dev/zero c 1 5
55     mknod -m 666 $VROOT/dev/full c 1 7
56     mknod -m 644 $VROOT/dev/random c 1 8
57     mknod -m 644 $VROOT/dev/urandom c 1 9
58     mknod -m 666 $VROOT/dev/tty c 5 0
59     mknod -m 666 $VROOT/dev/ptmx c 5 2
60     # For bash command substitution
61     ln -nsf ../proc/self/fd /dev/fd
62     # For df and linuxconf
63     touch $VROOT/dev/hdv1
64 }
65
66 # Initialize /dev in reference image
67 MAKEDEV
68
69 # Mount /dev/pts in reference image
70 mkdir -p $VROOT/dev/pts
71 mount -t devpts none $VROOT/dev/pts
72
73 # Mount /proc in reference image
74 mkdir -p $VROOT/proc
75 mount -t proc none $VROOT/proc
76
77 # Clean up before exiting if anything goes wrong
78 trap "umount $VROOT/proc ; umount $VROOT/dev/pts ; exit 255" ERR
79
80 # Create a dummy /etc/fstab in reference image
81 mkdir -p $VROOT/etc
82 cat > $VROOT/etc/fstab <<EOF
83 # This fake fstab exists only to please df and linuxconf.
84 /dev/hdv1       /       ext2    defaults        1 1
85 EOF
86 cp $VROOT/etc/fstab $VROOT/etc/mtab
87
88 # Prevent all locales from being installed in reference image
89 mkdir -p $VROOT/etc/rpm
90 cat > $VROOT/etc/rpm/macros <<EOF
91 %_install_langs en_US:en
92 %_excludedocs 1
93 %__file_context_path /dev/null
94 EOF
95
96 # Trick rpm and yum, who read the real root /etc/rpm/macros file
97 # rather than the one installed in the reference image, despite what
98 # you might expect the --root and --installroot options to mean. Both
99 # programs always read $HOME/.rpmmacros.
100 export HOME=$PWD
101 ln -sf $VROOT/etc/rpm/macros $PWD/.rpmmacros
102
103 # Initialize RPM database in reference image
104 mkdir -p $VROOT/var/lib/rpm
105 rpm --root $VROOT --initdb
106
107 # glibc must be specified explicitly for the correct arch to be chosen.
108 yum -c yum.conf --installroot=$VROOT -y install glibc yum
109
110 # yum will annoyingly use the /etc/yum.conf file in the --installroot
111 # even if overridden with -c
112 rm -f $VROOT/etc/yum.conf
113
114 # Some of the PlanetLab RPMs may attempt to call /sbin/runlevel to
115 # determine if the installation is running inside the BootCD
116 # environment. We would like to pretend that we are, so make sure
117 # /sbin/runlevel returns 'unknown'.
118 rm -f $VROOT/var/run/utmp
119 export PL_BOOTCD=1
120
121 # Go, baby, go
122 yum -c yum.conf --installroot=$VROOT -y groupinstall PlanetLab
123
124 # Remove stale RPM locks
125 rm -f $VROOT/var/lib/rpm/__db*
126
127 # Clean up /dev in reference image
128 umount $VROOT/dev/pts
129
130 # Disable unnecessary services
131 for service in netfs rawdevices cpuspeed smartd ; do
132     /usr/sbin/chroot $VROOT /sbin/chkconfig $service off
133 done
134
135 # Clean up
136 umount $VROOT/proc
137
138 # Build tarball
139 tar -cpjf PlanetLab-Bootstrap.tar.bz2 -C $VROOT .
140 rm -rf $VROOT
141
142 exit 0