PL2066 partial fix: turn vserver-reference into an RPM
[vserver-reference.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 # Clean up
44 if grep -q %{installroot}/proc /proc/mounts ; then
45     umount %{installroot}/proc
46 fi
47 if grep -q %{installroot}/dev/pts /proc/mounts ; then
48     umount %{installroot}/dev/pts
49 fi
50 chattr -R -i $RPM_BUILD_ROOT
51 rm -rf $RPM_BUILD_ROOT
52
53 # Make /vservers
54 mkdir -p $RPM_BUILD_ROOT%{vrootdir}
55 chmod 000 $RPM_BUILD_ROOT%{vrootdir}
56 chattr +t $RPM_BUILD_ROOT%{vrootdir}
57
58 # Make /vservers/vserver-reference
59 mkdir -p %{installroot}
60 chattr -t %{installroot}
61 chmod 755 %{installroot}
62
63 MAKEDEV ()
64 {
65     if grep -q %{installroot}/dev/pts /proc/mounts ; then
66         umount %{installroot}/dev/pts
67     fi
68     rm -rf %{installroot}/dev
69     mkdir -p %{installroot}/dev
70     mknod -m 666 %{installroot}/dev/null c 1 3
71     mknod -m 666 %{installroot}/dev/zero c 1 5
72     mknod -m 666 %{installroot}/dev/full c 1 7
73     mknod -m 644 %{installroot}/dev/random c 1 8
74     mknod -m 644 %{installroot}/dev/urandom c 1 9
75     mknod -m 666 %{installroot}/dev/tty c 5 0
76     mknod -m 666 %{installroot}/dev/ptmx c 5 2
77     touch %{installroot}/dev/hdv1
78 }
79
80 # Initialize /dev in reference image
81 MAKEDEV
82
83 # Mount /dev/pts in reference image
84 mkdir -p %{installroot}/dev/pts
85 mount -t devpts none %{installroot}/dev/pts
86
87 # Mount /proc in reference image
88 mkdir -p %{installroot}/proc
89 mount -t proc none %{installroot}/proc
90
91 # Create a dummy /etc/fstab in reference image
92 mkdir -p %{installroot}/etc
93 cat > %{installroot}/etc/fstab <<EOF
94 # This fake fstab exists only to please df and linuxconf.
95 /dev/hdv1       /       ext2    defaults        1 1
96 EOF
97
98 # Prevent all locales from being installed in reference image
99 mkdir -p %{installroot}/etc/rpm
100 cat > %{installroot}/etc/rpm/macros <<EOF
101 %_install_langs en_US:en
102 EOF
103
104 # Initialize RPM database in reference image
105 mkdir -p %{installroot}/var/lib/rpm
106 rpm --root %{installroot} --initdb
107
108 # XXX Get yum.conf from PlanetLabConf
109
110 # Install RPMs in reference image
111 yum \
112 %{?sslcertdir:--sslcertdir=%{sslcertdir}} \
113 --installroot=%{installroot} \
114 -y groupinstall VServer
115
116 # Clean up /dev in reference image
117 MAKEDEV
118
119 # Configure authentication in reference image
120 chroot %{installroot} authconfig --nostart --kickstart --enablemd5 --enableshadow || :
121
122 # Disable all services in reference image
123 chroot %{installroot} /bin/sh -c "chkconfig --list | awk '{ print \$1 }' | xargs -i chkconfig {} off"
124
125 # Clean up
126 if grep -q %{installroot}/proc /proc/mounts ; then
127     umount %{installroot}/proc
128 fi
129 if grep -q %{installroot}/dev/pts /proc/mounts ; then
130     umount %{installroot}/dev/pts
131 fi
132
133 %clean
134 # Clean up
135 if grep -q %{installroot}/proc /proc/mounts ; then
136     umount %{installroot}/proc
137 fi
138 if grep -q %{installroot}/dev/pts /proc/mounts ; then
139     umount %{installroot}/dev/pts
140 fi
141 chattr -R -i $RPM_BUILD_ROOT
142 rm -rf $RPM_BUILD_ROOT
143
144 %post
145 # Copy configuration files from host to reference image
146 for file in /etc/hosts /etc/resolv.conf /etc/yum.conf ; do
147     if [ -f $file ] ; then
148         echo $file | cpio -p -d -u %{vrefdir}
149     fi
150 done
151
152 %preun
153
154 %files
155 %defattr(-,root,root)
156 %{vrefdir}
157
158 %changelog
159 * Tue Sep 14 2004 Mark Huang <mlhuang@cs.princeton.edu> 3.0-1.planetlab
160 - initial build