- run createrepo as well
[sliceimage.git] / build.sh
1 #!/bin/bash
2 #
3 # Builds VServer reference image. Requires the web and boot servers to
4 # be up, which complicates bootstrap. Alternatively, we could require
5 # the build server to host a local yum repository. Already, it is
6 # required to run the same major version of yum as the nodes.
7 #
8 # Mark Huang <mlhuang@cs.princeton.edu>
9 # Copyright (C) 2004-2005 The Trustees of Princeton University
10 #
11 # $Id: build.sh,v 1.3 2006/03/10 18:20:28 mlhuang Exp $
12 #
13
14 # Get the production /etc/yum.conf file. XXX When MAs begin deploying
15 # their own boot servers and/or code, this will have to change.
16 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
17
18 # Solve the bootstrap problem by including any just built packages in
19 # the yum configuration. This cooperates with the PlanetLab build
20 # system.
21 if [ -n "$RPM_BUILD_DIR" ] ; then
22     # Remove any [PlanetLab*] sections
23     sed -i -f - yum.conf <<EOF
24 # Match lines between [PlanetLab*] and the next [*
25 /\[PlanetLab.*\]/I,/^\[/{
26 # Delete [PlanetLab*]
27 /\[PlanetLab.*\]/Id
28 # Done when we see [*
29 /^\[/b
30 # Otherwise delete
31 d
32 }
33 EOF
34
35     # And replace them with a section for the RPMS that were just built
36     yum-arch $(dirname $RPM_BUILD_DIR)/RPMS
37     createrepo $(dirname $RPM_BUILD_DIR)/RPMS || :
38     # If run under sudo, allow user to delete the headers/ and
39     # repodata/ directories.
40     if [ -n "$SUDO_USER" ] ; then
41         chown -R $SUDO_USER $(dirname $RPM_BUILD_DIR)/RPMS
42     fi
43     cat >> yum.conf <<EOF
44 [Bootstrap]
45 name=Bootstrap RPMS -- $(dirname $RPM_BUILD_DIR)/RPMS/
46 baseurl=file://$(dirname $RPM_BUILD_DIR)/RPMS/
47 EOF
48 fi
49
50 # Make /vservers
51 VROOT=$PWD/vservers/vserver-reference
52 install -d -m 755 $VROOT
53
54 MAKEDEV ()
55 {
56     rm -rf $VROOT/dev
57     mkdir -p $VROOT/dev
58     mknod -m 666 $VROOT/dev/null c 1 3
59     mknod -m 666 $VROOT/dev/zero c 1 5
60     mknod -m 666 $VROOT/dev/full c 1 7
61     mknod -m 644 $VROOT/dev/random c 1 8
62     mknod -m 644 $VROOT/dev/urandom c 1 9
63     mknod -m 666 $VROOT/dev/tty c 5 0
64     mknod -m 666 $VROOT/dev/ptmx c 5 2
65     # For bash command substitution
66     ln -nsf ../proc/self/fd /dev/fd
67     # For df and linuxconf
68     touch $VROOT/dev/hdv1
69     # For TUN/TAP
70     mkdir -p $VROOT/dev/net
71     mknod -m 600 $VROOT/dev/net/tun c 10 200
72 }
73
74 # Initialize /dev in reference image
75 MAKEDEV
76
77 # Mount /dev/pts in reference image
78 mkdir -p $VROOT/dev/pts
79 mount -t devpts none $VROOT/dev/pts
80
81 # Mount /proc in reference image
82 mkdir -p $VROOT/proc
83 mount -t proc none $VROOT/proc
84
85 # Clean up before exiting if anything goes wrong
86 trap "umount $VROOT/proc ; umount $VROOT/dev/pts ; exit 255" ERR
87
88 # Create a dummy /etc/fstab in reference image
89 mkdir -p $VROOT/etc
90 cat > $VROOT/etc/fstab <<EOF
91 # This fake fstab exists only to please df and linuxconf.
92 /dev/hdv1       /       ext2    defaults        1 1
93 EOF
94 cp $VROOT/etc/fstab $VROOT/etc/mtab
95
96 # Prevent all locales from being installed in reference image
97 mkdir -p $VROOT/etc/rpm
98 cat > $VROOT/etc/rpm/macros <<EOF
99 %_install_langs en_US:en
100 %_excludedocs 1
101 %__file_context_path /dev/null
102 EOF
103
104 # This tells the Boot Manager that it is okay to update
105 # /etc/resolv.conf and /etc/hosts whenever the network configuration
106 # changes. Users are free to delete this file.
107 touch $VROOT/etc/AUTO_UPDATE_NET_FILES
108
109 # Trick rpm and yum, who read the real root /etc/rpm/macros file
110 # rather than the one installed in the reference image, despite what
111 # you might expect the --root and --installroot options to mean. Both
112 # programs always read $HOME/.rpmmacros.
113 export HOME=$PWD
114 ln -sf $VROOT/etc/rpm/macros $PWD/.rpmmacros
115
116 # Initialize RPM database in reference image
117 mkdir -p $VROOT/var/lib/rpm
118 rpm --root $VROOT --initdb
119
120 # Go, baby, go
121 yum -c yum.conf --installroot=$VROOT -y groupinstall VServer
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 MAKEDEV
129
130 # Disable all services in reference image
131 /usr/sbin/chroot $VROOT /bin/sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
132
133 # Clean up
134 umount $VROOT/proc
135
136 exit 0