Add "which".
[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: build.sh,v 1.14 2006/11/13 19:03:53 mlhuang Exp $
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 which
52 yum
53 curl
54 gzip
55 perl
56 python
57 tar
58 )
59
60 usage()
61 {
62     echo "Usage: build.sh [OPTION]..."
63     echo "      -r release      Fedora release number (default: $releasever)"
64     echo "      -a arch         Fedora architecture (default: $basearch)"
65     echo "      -h              This message"
66     exit 1
67 }
68
69 # Get options
70 while getopts "r:a:h" opt ; do
71     case $opt in
72         r)
73             releasever=$OPTARG
74             ;;
75         a)
76             basearch=$OPTARG
77             ;;
78         h|*)
79             usage
80             ;;
81     esac
82 done
83
84 # Do not tolerate errors
85 set -e
86
87 # Make /vservers
88 vroot=$PWD/vservers/.vref/default
89 install -d -m 755 $vroot
90
91 # Install default reference image
92 for package in "${packagelist[@]}" ; do
93     packages="$packages -p $package"
94 done
95 mkfedora -v -r $releasever -a $basearch -k $packages $vroot
96
97 # Clean /dev
98 rm -rf $vroot/dev
99 mkdir -p $vroot/dev
100 mknod -m 666 $vroot/dev/null c 1 3
101 mknod -m 666 $vroot/dev/zero c 1 5
102 mknod -m 666 $vroot/dev/full c 1 7
103 mknod -m 644 $vroot/dev/random c 1 8
104 mknod -m 644 $vroot/dev/urandom c 1 9
105 mknod -m 666 $vroot/dev/tty c 5 0
106 mknod -m 666 $vroot/dev/ptmx c 5 2
107 # For bash command substitution
108 ln -nsf ../proc/self/fd $vroot/dev/fd
109 # For df and linuxconf
110 touch $vroot/dev/hdv1
111 # For TUN/TAP
112 mkdir -p $vroot/dev/net
113 mknod -m 600 $vroot/dev/net/tun c 10 200
114 # For pseudo ttys
115 mkdir -p $vroot/dev/pts
116
117 # Disable all services in reference image
118 chroot $vroot sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
119
120 # This tells the Boot Manager that it is okay to update
121 # /etc/resolv.conf and /etc/hosts whenever the network configuration
122 # changes. Users are free to delete this file.
123 touch $vroot/etc/AUTO_UPDATE_NET_FILES
124
125 exit 0