Added flag to skip signing, change Copyright and BuildArchitectures properties
[webmin.git] / makerpm.pl
1 #!/usr/local/bin/perl
2 # Build an RPM package of Webmin
3
4 if (-r "/usr/src/OpenLinux") {
5         $base_dir = "/usr/src/OpenLinux";
6         }
7 else {
8         $base_dir = "/usr/src/redhat";
9         }
10 $spec_dir = "$base_dir/SPECS";
11 $source_dir = "$base_dir/SOURCES";
12 $rpms_dir = "$base_dir/RPMS/noarch";
13 $srpms_dir = "$base_dir/SRPMS";
14
15 $< && die "makerpm.pl must be run as root";
16
17 if ($ARGV[0] eq "--nosign" || $ARGV[0] eq "-nosign") {
18         $nosign = 1;
19         shift(@ARGV);
20         }
21 $ver = $ARGV[0] || die "usage: makerpm.pl <version> [release]";
22 $rel = $ARGV[1] || "1";
23
24 $oscheck = <<EOF;
25 if (-r "/etc/.issue") {
26         \$etc_issue = `cat /etc/.issue`;
27         }
28 elsif (-r "/etc/issue") {
29         \$etc_issue = `cat /etc/issue`;
30         }
31 \$uname = `uname -a`;
32 EOF
33 open(OS, "os_list.txt");
34 while(<OS>) {
35         chop;
36         if (/^([^\t]+)\t+([^\t]+)\t+([^\t]+)\t+([^\t]+)\t*(.*)$/ && $5) {
37                 $if = $count++ == 0 ? "if" : "elsif";
38                 $oscheck .= "$if ($5) {\n".
39                             "   print \"oscheck='$1'\\n\";\n".
40                             "   }\n";
41                 }
42         }
43 close(OS);
44 $oscheck =~ s/\\/\\\\/g;
45 $oscheck =~ s/`/\\`/g;
46 $oscheck =~ s/\$/\\\$/g;
47
48 open(TEMP, "maketemp.pl");
49 while(<TEMP>) {
50         $maketemp .= $_;
51         }
52 close(TEMP);
53 $maketemp =~ s/\\/\\\\/g;
54 $maketemp =~ s/`/\\`/g;
55 $maketemp =~ s/\$/\\\$/g;
56
57 system("cp tarballs/webmin-$ver.tar.gz $source_dir");
58 open(SPEC, ">$spec_dir/webmin-$ver.spec");
59 print SPEC <<EOF;
60 #%define BuildRoot /tmp/%{name}-%{version}
61 %define __spec_install_post %{nil}
62
63 Summary: A web-based administration interface for Unix systems.
64 Name: webmin
65 Version: $ver
66 Release: $rel
67 Provides: %{name}-%{version}
68 PreReq: /bin/sh /usr/bin/perl /bin/rm
69 Requires: /bin/sh /usr/bin/perl /bin/rm
70 AutoReq: 0
71 License: Freeware
72 Group: System/Tools
73 Source: http://www.webmin.com/download/%{name}-%{version}.tar.gz
74 Vendor: Jamie Cameron
75 BuildRoot: /tmp/%{name}-%{version}
76 BuildArch: noarch
77 %description
78 A web-based administration interface for Unix systems. Using Webmin you can
79 configure DNS, Samba, NFS, local/remote filesystems and more using your
80 web browser.
81
82 After installation, enter the URL http://localhost:10000/ into your
83 browser and login as root with your root password.
84
85 %prep
86 %setup -q
87
88 %build
89 (find . -name '*.cgi' ; find . -name '*.pl') | perl perlpath.pl /usr/bin/perl -
90 rm -f mount/freebsd-mounts*
91 rm -f mount/openbsd-mounts*
92 rm -f mount/macos-mounts*
93 rm -f webmin-gentoo-init
94 rm -rf format bsdexports hpuxexports sgiexports zones rbac
95 chmod -R og-w .
96
97 %install
98 mkdir -p %{buildroot}/usr/libexec/webmin
99 mkdir -p %{buildroot}/etc/sysconfig/daemons
100 mkdir -p %{buildroot}/etc/rc.d/{rc0.d,rc1.d,rc2.d,rc3.d,rc5.d,rc6.d}
101 mkdir -p %{buildroot}/etc/init.d
102 mkdir -p %{buildroot}/etc/pam.d
103 cp -rp * %{buildroot}/usr/libexec/webmin
104 cp webmin-daemon %{buildroot}/etc/sysconfig/daemons/webmin
105 cp webmin-init %{buildroot}/etc/init.d/webmin
106 cp webmin-pam %{buildroot}/etc/pam.d/webmin
107 ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc2.d/S99webmin
108 ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc3.d/S99webmin
109 ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc5.d/S99webmin
110 ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc0.d/K10webmin
111 ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc1.d/K10webmin
112 ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc6.d/K10webmin
113 echo rpm >%{buildroot}/usr/libexec/webmin/install-type
114
115 %clean
116 #%{rmDESTDIR}
117 [ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
118
119 %files
120 %defattr(-,root,root)
121 /usr/libexec/webmin
122 %config /etc/sysconfig/daemons/webmin
123 /etc/init.d/webmin
124 /etc/rc.d/rc2.d/S99webmin
125 /etc/rc.d/rc3.d/S99webmin
126 /etc/rc.d/rc5.d/S99webmin
127 /etc/rc.d/rc0.d/K10webmin
128 /etc/rc.d/rc1.d/K10webmin
129 /etc/rc.d/rc6.d/K10webmin
130 %config /etc/pam.d/webmin
131
132 %pre
133 perl <<EOD;
134 $maketemp
135 EOD
136 if [ "\$?" != "0" ]; then
137         echo "Failed to create or check temp files directory /tmp/.webmin"
138         exit 1
139 fi
140 if [ "\$tempdir" = "" ]; then
141         tempdir=/tmp/.webmin
142 fi
143 perl >$tempdir/\$\$.check <<EOD;
144 $oscheck
145 EOD
146 . $tempdir/\$\$.check
147 rm -f $tempdir/\$\$.check
148 if [ ! -r /etc/webmin/config ]; then
149         if [ "\$oscheck" = "" ]; then
150                 echo Unable to identify operating system
151                 exit 2
152         fi
153         echo Operating system is \$oscheck
154         if [ "\$WEBMIN_PORT\" != \"\" ]; then
155                 port=\$WEBMIN_PORT
156         else
157                 port=10000
158         fi
159         perl -e 'use Socket; socket(FOO, PF_INET, SOCK_STREAM, getprotobyname("tcp")); setsockopt(FOO, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)); bind(FOO, pack_sockaddr_in(\$ARGV[0], INADDR_ANY)) || exit(1); exit(0);' \$port
160         if [ "\$?" != "0" ]; then
161                 echo Port \$port is already in use
162                 exit 2
163         fi
164 fi
165 # Save /etc/webmin in case the upgrade trashes it
166 if [ "\$1" != 1 ]; then
167         rm -rf /etc/.webmin-backup
168         cp -r /etc/webmin /etc/.webmin-backup
169 fi
170
171 %post
172 inetd=`grep "^inetd=" /etc/webmin/miniserv.conf 2>/dev/null | sed -e 's/inetd=//g'`
173 if [ "\$1" != 1 ]; then
174         # Upgrading the RPM, so stop the old webmin properly
175         if [ "\$inetd" != "1" ]; then
176                 /etc/init.d/webmin stop >/dev/null 2>&1 </dev/null
177         fi
178 fi
179 cd /usr/libexec/webmin
180 config_dir=/etc/webmin
181 var_dir=/var/webmin
182 perl=/usr/bin/perl
183 autoos=3
184 if [ "\$WEBMIN_PORT\" != \"\" ]; then
185         port=\$WEBMIN_PORT
186 else
187         port=10000
188 fi
189 login=root
190 if [ -r /etc/shadow ]; then
191         #crypt=`grep "^root:" /etc/shadow | cut -f 2 -d :`
192         crypt=x
193 else
194         crypt=`grep "^root:" /etc/passwd | cut -f 2 -d :`
195 fi
196 host=`hostname`
197 ssl=1
198 atboot=1
199 nochown=1
200 autothird=1
201 noperlpath=1
202 nouninstall=1
203 nostart=1
204 if [ "\$tempdir" = "" ]; then
205         tempdir=/tmp/.webmin
206 fi
207 export config_dir var_dir perl autoos port login crypt host ssl nochown autothird noperlpath nouninstall nostart allow atboot
208 ./setup.sh >$tempdir/webmin-setup.out 2>&1
209 rm -f /var/lock/subsys/webmin
210 if [ "$inetd" != "1" ]; then
211         /etc/init.d/webmin start >/dev/null 2>&1 </dev/null
212 fi
213 cat >/etc/webmin/uninstall.sh <<EOFF
214 #!/bin/sh
215 printf "Are you sure you want to uninstall Webmin? (y/n) : "
216 read answer
217 printf "\\n"
218 if [ "\\\$answer" = "y" ]; then
219         echo "Removing webmin RPM .."
220         rpm -e --nodeps webmin
221         echo "Done!"
222 fi
223 EOFF
224 chmod +x /etc/webmin/uninstall.sh
225 port=`grep "^port=" /etc/webmin/miniserv.conf | sed -e 's/port=//g'`
226 perl -e 'use Net::SSLeay' >/dev/null 2>/dev/null
227 sslmode=0
228 if [ "\$?" = "0" ]; then
229         grep ssl=1 /etc/webmin/miniserv.conf >/dev/null 2>/dev/null
230         if [ "\$?" = "0" ]; then
231                 sslmode=1
232         fi
233 fi
234 musthost=`grep musthost= /etc/webmin/miniserv.conf | sed -e 's/musthost=//'`
235 if [ "$musthost" != "" ]; then
236         host=$musthost
237 fi
238 if [ "\$sslmode" = "1" ]; then
239         echo "Webmin install complete. You can now login to https://\$host:\$port/"
240 else
241         echo "Webmin install complete. You can now login to http://\$host:\$port/"
242 fi
243 echo "as root with your root password."
244
245 %preun
246 if [ "\$1" = 0 ]; then
247         grep root=/usr/libexec/webmin /etc/webmin/miniserv.conf >/dev/null 2>&1
248         if [ "\$?" = 0 ]; then
249                 # RPM is being removed, and no new version of webmin
250                 # has taken it's place. Run uninstalls and stop the server
251                 echo "Running uninstall scripts .."
252                 (cd /usr/libexec/webmin ; WEBMIN_CONFIG=/etc/webmin WEBMIN_VAR=/var/webmin LANG= /usr/libexec/webmin/run-uninstalls.pl)
253                 /etc/init.d/webmin stop >/dev/null 2>&1 </dev/null
254                 /etc/webmin/stop >/dev/null 2>&1 </dev/null
255                 /bin/true
256         fi
257 fi
258
259 %postun
260 if [ "\$1" = 0 ]; then
261         grep root=/usr/libexec/webmin /etc/webmin/miniserv.conf >/dev/null 2>&1
262         if [ "\$?" = 0 ]; then
263                 # RPM is being removed, and no new version of webmin
264                 # has taken it's place. Delete the config files
265                 rm -rf /etc/webmin /var/webmin
266         fi
267 fi
268
269 %triggerpostun -- webmin
270 if [ ! -d /var/webmin -a "\$1" = 2 ]; then
271         echo Re-creating /var/webmin directory
272         mkdir /var/webmin
273 fi
274 if [ ! -r /etc/webmin/miniserv.conf -a -d /etc/.webmin-backup -a "\$1" = 2 ]; then
275         echo Recovering /etc/webmin directory
276         rm -rf /etc/.webmin-broken
277         mv /etc/webmin /etc/.webmin-broken
278         mv /etc/.webmin-backup /etc/webmin
279         /etc/init.d/webmin stop >/dev/null 2>&1 </dev/null
280         /etc/init.d/webmin start >/dev/null 2>&1 </dev/null
281 else
282         rm -rf /etc/.webmin-backup
283 fi
284
285 EOF
286 close(SPEC);
287
288 $cmd = -x "/usr/bin/rpmbuild" ? "rpmbuild" : "rpm";
289 system("$cmd -ba --target=noarch $spec_dir/webmin-$ver.spec") && exit;
290 if (-d "rpm") {
291         system("mv $rpms_dir/webmin-$ver-$rel.noarch.rpm rpm/webmin-$ver-$rel.noarch.rpm");
292         print "Moved to rpm/webmin-$ver-$rel.noarch.rpm\n";
293         system("mv $srpms_dir/webmin-$ver-$rel.src.rpm rpm/webmin-$ver-$rel.src.rpm");
294         print "Moved to rpm/webmin-$ver-$rel.src.rpm\n";
295         system("chown jcameron: rpm/webmin-$ver-$rel.noarch.rpm rpm/webmin-$ver-$rel.src.rpm");
296         if (!$nosign) {
297                 system("rpm --resign rpm/webmin-$ver-$rel.noarch.rpm rpm/webmin-$ver-$rel.src.rpm");
298                 }
299         }
300
301