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