c9e04cd4992bdd3aa0429a88cd14c13a364d51a5
[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.2 2005/09/03 21:42:07 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     cat >> yum.conf <<EOF
38 [Bootstrap]
39 name=Bootstrap RPMS -- $(dirname $RPM_BUILD_DIR)/RPMS/
40 baseurl=file://$(dirname $RPM_BUILD_DIR)/RPMS/
41 EOF
42 fi
43
44 # Make /
45 VROOT=$PWD/PlanetLab-Bootstrap
46 install -d -m 755 $VROOT
47
48 MAKEDEV ()
49 {
50     rm -rf $VROOT/dev
51     mkdir -p $VROOT/dev
52     mknod -m 666 $VROOT/dev/null c 1 3
53     mknod -m 666 $VROOT/dev/zero c 1 5
54     mknod -m 666 $VROOT/dev/full c 1 7
55     mknod -m 644 $VROOT/dev/random c 1 8
56     mknod -m 644 $VROOT/dev/urandom c 1 9
57     mknod -m 666 $VROOT/dev/tty c 5 0
58     mknod -m 666 $VROOT/dev/ptmx c 5 2
59     # For bash command substitution
60     ln -nsf ../proc/self/fd /dev/fd
61     # For df and linuxconf
62     touch $VROOT/dev/hdv1
63 }
64
65 # Initialize /dev in reference image
66 MAKEDEV
67
68 # Mount /dev/pts in reference image
69 mkdir -p $VROOT/dev/pts
70 mount -t devpts none $VROOT/dev/pts
71
72 # Mount /proc in reference image
73 mkdir -p $VROOT/proc
74 mount -t proc none $VROOT/proc
75
76 # Clean up before exiting if anything goes wrong
77 trap "umount $VROOT/proc ; umount $VROOT/dev/pts ; exit 255" ERR
78
79 # Create a dummy /etc/fstab in reference image
80 mkdir -p $VROOT/etc
81 cat > $VROOT/etc/fstab <<EOF
82 # This fake fstab exists only to please df and linuxconf.
83 /dev/hdv1       /       ext2    defaults        1 1
84 EOF
85 cp $VROOT/etc/fstab $VROOT/etc/mtab
86
87 # Prevent all locales from being installed in reference image
88 mkdir -p $VROOT/etc/rpm
89 cat > $VROOT/etc/rpm/macros <<EOF
90 %_install_langs en_US:en
91 %_excludedocs 1
92 %__file_context_path /dev/null
93 EOF
94
95 # Trick rpm and yum, who read the real root /etc/rpm/macros file
96 # rather than the one installed in the reference image, despite what
97 # you might expect the --root and --installroot options to mean. Both
98 # programs always read $HOME/.rpmmacros.
99 export HOME=$PWD
100 ln -sf $VROOT/etc/rpm/macros $PWD/.rpmmacros
101
102 # Initialize RPM database in reference image
103 mkdir -p $VROOT/var/lib/rpm
104 rpm --root $VROOT --initdb
105
106 # glibc must be specified explicitly for the correct arch to be chosen.
107 yum -c yum.conf --installroot=$VROOT -y install glibc yum
108
109 # yum will annoyingly use the /etc/yum.conf file in the --installroot
110 # even if overridden with -c
111 rm -f $VROOT/etc/yum.conf
112
113 # Some of the PlanetLab RPMs may attempt to call /sbin/runlevel to
114 # determine if the installation is running inside the BootCD
115 # environment. We would like to pretend that we are, so make sure
116 # /sbin/runlevel returns 'unknown'.
117 rm -f $VROOT/var/run/utmp
118 export PL_BOOTCD=1
119
120 # Go, baby, go
121 yum -c yum.conf --installroot=$VROOT -y groupinstall PlanetLab
122
123 # Remove stale RPM locks
124 rm -f $VROOT/var/lib/rpm/__db*
125
126 # Clean up /dev in reference image
127 umount $VROOT/dev/pts
128
129 # Disable unnecessary services
130 for service in netfs rawdevices cpuspeed smartd ; do
131     /usr/sbin/chroot $VROOT /sbin/chkconfig $service off
132 done
133
134 # Clean up
135 umount $VROOT/proc
136
137 # Build tarball
138 tar -cpjf PlanetLab-Bootstrap.tar.bz2 -C $VROOT .
139 rm -rf $VROOT
140
141 exit 0