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