- get yum.conf from boot, not www
[sliceimage.git] / vserver-reference.init
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: vserver-reference.init,v 1.16 2005/09/02 15:21:00 mlhuang Exp $
12 #
13
14 # Get the URL for the production /etc/yum.conf file. XXX When MAs
15 # begin deploying their own boot servers and/or code, this will have
16 # to change.
17 YUM_CONF=http://boot.planet-lab.org/$(curl --silent --insecure --form node_id=0 --form file=/etc/yum.conf https://boot.planet-lab.org/db/plnodeconf/getsinglefile.php)
18
19 # Make /vservers
20 VROOT=$PWD/vservers/vserver-reference
21 install -d -m 755 $VROOT
22
23 MAKEDEV ()
24 {
25     rm -rf $VROOT/dev
26     mkdir -p $VROOT/dev
27     mknod -m 666 $VROOT/dev/null c 1 3
28     mknod -m 666 $VROOT/dev/zero c 1 5
29     mknod -m 666 $VROOT/dev/full c 1 7
30     mknod -m 644 $VROOT/dev/random c 1 8
31     mknod -m 644 $VROOT/dev/urandom c 1 9
32     mknod -m 666 $VROOT/dev/tty c 5 0
33     mknod -m 666 $VROOT/dev/ptmx c 5 2
34     # For bash command substitution
35     ln -nsf ../proc/self/fd /dev/fd
36     # For df and linuxconf
37     touch $VROOT/dev/hdv1
38     # For TUN/TAP
39     mkdir -p $VROOT/dev/net
40     mknod -m 600 $VROOT/dev/net/tun c 10 200
41 }
42
43 # Initialize /dev in reference image
44 MAKEDEV
45
46 # Mount /dev/pts in reference image
47 mkdir -p $VROOT/dev/pts
48 mount -t devpts none $VROOT/dev/pts
49
50 # Mount /proc in reference image
51 mkdir -p $VROOT/proc
52 mount -t proc none $VROOT/proc
53
54 # Clean up before exiting if anything goes wrong
55 trap "umount $VROOT/proc ; umount $VROOT/dev/pts ; exit 255" ERR
56
57 # Create a dummy /etc/fstab in reference image
58 mkdir -p $VROOT/etc
59 cat > $VROOT/etc/fstab <<EOF
60 # This fake fstab exists only to please df and linuxconf.
61 /dev/hdv1       /       ext2    defaults        1 1
62 EOF
63 cp $VROOT/etc/fstab $VROOT/etc/mtab
64
65 # Prevent all locales from being installed in reference image
66 mkdir -p $VROOT/etc/rpm
67 cat > $VROOT/etc/rpm/macros <<EOF
68 %_install_langs en_US:en
69 %_excludedocs 1
70 %__file_context_path /dev/null
71 EOF
72
73 # This tells the Boot Manager that it is okay to update
74 # /etc/resolv.conf and /etc/hosts whenever the network configuration
75 # changes. Users are free to delete this file.
76 touch $VROOT/etc/AUTO_UPDATE_NET_FILES
77
78 # Trick rpm and yum, who read the real root /etc/rpm/macros file
79 # rather than the one installed in the reference image, despite what
80 # you might expect the --root and --installroot options to mean. Both
81 # programs always read $HOME/.rpmmacros.
82 export HOME=$PWD
83 ln -sf $VROOT/etc/rpm/macros $PWD/.rpmmacros
84
85 # Initialize RPM database in reference image
86 mkdir -p $VROOT/var/lib/rpm
87 rpm --root $VROOT --initdb
88
89 # Go, baby, go
90 yum -c $YUM_CONF --installroot=$VROOT -y groupinstall VServer
91
92 # Freshen the RPM set with any just built. This does not help when a
93 # completely new PlanetLab package must be installed in the reference
94 # image. To work around this limitation, introduce the new package in
95 # one release, then include it in the VServer yumgroup in the next.
96 if [ -d $RPM_BUILD_DIR/../RPMS ] ; then
97     rpm --root $VROOT --freshen --verbose $RPM_BUILD_DIR/../RPMS/*/*.rpm
98 fi
99
100 # Remove stale RPM locks
101 rm -f $VROOT/var/lib/rpm/__db*
102
103 # Clean up /dev in reference image
104 umount $VROOT/dev/pts
105 MAKEDEV
106
107 # Disable all services in reference image
108 /usr/sbin/chroot $VROOT /bin/sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
109
110 # Clean up
111 umount $VROOT/proc
112
113 exit 0