- move vserver-reference to .vref/default
[vserver-reference.git] / build.sh
1 #!/bin/bash
2 #
3 # Builds VServer reference image
4 #
5 # Mark Huang <mlhuang@cs.princeton.edu>
6 # Copyright (C) 2004-2006 The Trustees of Princeton University
7 #
8 # $Id$
9 #
10
11 PATH=/sbin:/bin:/usr/sbin:/usr/bin
12
13 # In both a normal CVS environment and a PlanetLab RPM
14 # build environment, all of our dependencies are checked out into
15 # directories at the same level as us.
16 if [ -d ../build ] ; then
17     PATH=$PATH:../build
18     srcdir=..
19 else
20     echo "Error: Could not find $(cd .. && pwd -P)/build/"
21     exit 1
22 fi
23
24 export PATH
25
26 # Release and architecture to install
27 releasever=4
28 basearch=i386
29
30 # Packages to install
31 packagelist=(
32 bash
33 coreutils
34 iputils
35 kernel-vserver
36 bzip2
37 crontabs
38 diffutils
39 logrotate
40 openssh-clients
41 passwd
42 rsh
43 rsync
44 sudo
45 tcpdump
46 telnet
47 traceroute
48 time
49 vixie-cron
50 wget
51 yum
52 curl
53 gzip
54 perl
55 python
56 tar
57 )
58
59 usage()
60 {
61     echo "Usage: build.sh [OPTION]..."
62     echo "      -r release      Fedora release number (default: $releasever)"
63     echo "      -a arch         Fedora architecture (default: $basearch)"
64     echo "      -h              This message"
65     exit 1
66 }
67
68 # Get options
69 while getopts "r:a:h" opt ; do
70     case $opt in
71         r)
72             releasever=$OPTARG
73             ;;
74         a)
75             basearch=$OPTARG
76             ;;
77         h|*)
78             usage
79             ;;
80     esac
81 done
82
83 # Do not tolerate errors
84 set -e
85
86 # Make /vservers
87 vroot=$PWD/vservers/.vref/default
88 install -d -m 755 $vroot
89
90 # Install default reference image
91 for package in "${packagelist[@]}" ; do
92     packages="$packages -p $package"
93 done
94 mkfedora -v -r $releasever -a $basearch -k $packages $vroot
95
96 # Clean /dev
97 rm -rf $vroot/dev
98 mkdir -p $vroot/dev
99 mknod -m 666 $vroot/dev/null c 1 3
100 mknod -m 666 $vroot/dev/zero c 1 5
101 mknod -m 666 $vroot/dev/full c 1 7
102 mknod -m 644 $vroot/dev/random c 1 8
103 mknod -m 644 $vroot/dev/urandom c 1 9
104 mknod -m 666 $vroot/dev/tty c 5 0
105 mknod -m 666 $vroot/dev/ptmx c 5 2
106 # For bash command substitution
107 ln -nsf ../proc/self/fd $vroot/dev/fd
108 # For df and linuxconf
109 touch $vroot/dev/hdv1
110 # For TUN/TAP
111 mkdir -p $vroot/dev/net
112 mknod -m 600 $vroot/dev/net/tun c 10 200
113 # For pseudo ttys
114 mkdir -p $vroot/dev/pts
115
116 # Disable all services in reference image
117 chroot $vroot sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
118
119 # This tells the Boot Manager that it is okay to update
120 # /etc/resolv.conf and /etc/hosts whenever the network configuration
121 # changes. Users are free to delete this file.
122 touch $vroot/etc/AUTO_UPDATE_NET_FILES
123
124 exit 0