- add /sbin and /usr/sbin to our PATH in case we are running in an sudo
[sliceimage.git] / vserver-reference.spec
1 %define name vserver-reference
2 %define version 3.0
3 %define release 1.planetlab%{?date:.%{date}}
4
5 Vendor: PlanetLab
6 Packager: PlanetLab Central <support@planet-lab.org>
7 Distribution: PlanetLab 3.0
8 URL: http://www.planet-lab.org
9
10 Summary: VServer reference image
11 Name: %{name}
12 Version: %{version}
13 Release: %{release}
14 Source0: %{name}-%{version}.tar.bz2
15 License: GPL
16 Group: Applications/System
17 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
18 BuildArchitectures: noarch
19 Requires: util-vserver
20 AutoReqProv: no
21 BuildRequires: e2fsprogs, yum
22
23 %description
24 This package creates the virtual server (VServer) reference image used
25 as the installation base for new PlanetLab slivers.
26
27 %define vrootdir /vservers
28 %define vrefdir %{vrootdir}/%{name}
29 %define installroot $RPM_BUILD_ROOT%{vrefdir}
30
31 %prep
32 %setup -q
33
34 # chattr, mknod, mount, yum all require root privileges. Yech.
35 if [ $UID -ne 0 ] ; then
36     echo You must be root to build the %{name} package.
37     false
38 fi
39
40 %build
41
42 %install
43 # Running as root
44 export PATH="$PATH:/sbin:/usr/sbin"
45
46 # Clean up
47 if grep -q %{installroot}/proc /proc/mounts ; then
48     umount %{installroot}/proc
49 fi
50 if grep -q %{installroot}/dev/pts /proc/mounts ; then
51     umount %{installroot}/dev/pts
52 fi
53 chattr -R -i $RPM_BUILD_ROOT
54 rm -rf $RPM_BUILD_ROOT
55
56 # Make /vservers
57 mkdir -p $RPM_BUILD_ROOT%{vrootdir}
58 chmod 000 $RPM_BUILD_ROOT%{vrootdir}
59 chattr +t $RPM_BUILD_ROOT%{vrootdir}
60
61 # Make /vservers/vserver-reference
62 mkdir -p %{installroot}
63 chattr -t %{installroot}
64 chmod 755 %{installroot}
65
66 MAKEDEV ()
67 {
68     if grep -q %{installroot}/dev/pts /proc/mounts ; then
69         umount %{installroot}/dev/pts
70     fi
71     rm -rf %{installroot}/dev
72     mkdir -p %{installroot}/dev
73     mknod -m 666 %{installroot}/dev/null c 1 3
74     mknod -m 666 %{installroot}/dev/zero c 1 5
75     mknod -m 666 %{installroot}/dev/full c 1 7
76     mknod -m 644 %{installroot}/dev/random c 1 8
77     mknod -m 644 %{installroot}/dev/urandom c 1 9
78     mknod -m 666 %{installroot}/dev/tty c 5 0
79     mknod -m 666 %{installroot}/dev/ptmx c 5 2
80     touch %{installroot}/dev/hdv1
81 }
82
83 # Initialize /dev in reference image
84 MAKEDEV
85
86 # Mount /dev/pts in reference image
87 mkdir -p %{installroot}/dev/pts
88 mount -t devpts none %{installroot}/dev/pts
89
90 # Mount /proc in reference image
91 mkdir -p %{installroot}/proc
92 mount -t proc none %{installroot}/proc
93
94 # Create a dummy /etc/fstab in reference image
95 mkdir -p %{installroot}/etc
96 cat > %{installroot}/etc/fstab <<EOF
97 # This fake fstab exists only to please df and linuxconf.
98 /dev/hdv1       /       ext2    defaults        1 1
99 EOF
100
101 # Prevent all locales from being installed in reference image
102 mkdir -p %{installroot}/etc/rpm
103 cat > %{installroot}/etc/rpm/macros <<EOF
104 %_install_langs en_US:en
105 EOF
106
107 # Initialize RPM database in reference image
108 mkdir -p %{installroot}/var/lib/rpm
109 rpm --root %{installroot} --initdb
110
111 # XXX Get yum.conf from PlanetLabConf
112
113 # Install RPMs in reference image
114 yum -c ./yum.conf \
115 %{?sslcertdir:--sslcertdir=%{sslcertdir}} \
116 --installroot=%{installroot} \
117 -y groupinstall VServer
118
119 # Clean up /dev in reference image
120 MAKEDEV
121
122 # Configure authentication in reference image
123 chroot %{installroot} authconfig --nostart --kickstart --enablemd5 --enableshadow || :
124
125 # Disable all services in reference image
126 chroot %{installroot} /bin/sh -c "chkconfig --list | awk '{ print \$1 }' | xargs -i chkconfig {} off"
127
128 # Clean up
129 if grep -q %{installroot}/proc /proc/mounts ; then
130     umount %{installroot}/proc
131 fi
132 if grep -q %{installroot}/dev/pts /proc/mounts ; then
133     umount %{installroot}/dev/pts
134 fi
135
136 %clean
137 # Running as root
138 export PATH="$PATH:/sbin:/usr/sbin"
139
140 # Clean up
141 if grep -q %{installroot}/proc /proc/mounts ; then
142     umount %{installroot}/proc
143 fi
144 if grep -q %{installroot}/dev/pts /proc/mounts ; then
145     umount %{installroot}/dev/pts
146 fi
147 chattr -R -i $RPM_BUILD_ROOT
148 rm -rf $RPM_BUILD_ROOT
149
150 %post
151 # Copy configuration files from host to reference image
152 for file in /etc/hosts /etc/resolv.conf /etc/yum.conf ; do
153     if [ -f $file ] ; then
154         echo $file | cpio -p -d -u %{vrefdir}
155     fi
156 done
157
158 %preun
159
160 %files
161 %defattr(-,root,root)
162 %{vrefdir}
163
164 %changelog
165 * Tue Sep 14 2004 Mark Huang <mlhuang@cs.princeton.edu> 3.0-1.planetlab
166 - initial build