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