1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 02_checksetup.dpatch by <sukria@sukria.net>
4
## All lines beginning with `## DP:' are a description of the patch.
5
## DP: Change checksetup.pl to fit our needs
8
diff -urNad bugzilla-2.18.2/checksetup.pl /tmp/dpep.PEzGnE/bugzilla-2.18.2/checksetup.pl
9
--- bugzilla-2.18.2/checksetup.pl 2005-07-10 20:34:58.000000000 +0200
10
+++ /tmp/dpep.PEzGnE/bugzilla-2.18.2/checksetup.pl 2005-07-10 20:38:32.000000000 +0200
14
# -*- Mode: perl; indent-tabs-mode: nil -*-
16
# The contents of this file are subject to the Mozilla Public
22
+use lib "/usr/share/bugzilla";
24
use vars qw( $db_name %answer );
25
use Bugzilla::Constants;
26
+use constant MAX_PROMPT_CYCLE => 10;
34
+# the Debian way of fixing permissions
35
+# Comes from bugzilla.postinst.
36
+sub fix_www_data_perm {
38
+ my $chown_cmd = "chown -R www-data:www-data $path";
39
+ my $chmod_file_cmd = "find $path -type f -exec chmod 644 {} \\;";
40
+ my $chmod_dir_cmd = "find $path -type d -exec chmod 755 {} \\; ";
42
+ foreach my $cmd ($chown_cmd, $chmod_file_cmd, $chmod_dir_cmd) {
44
+ or die "Command `$cmd` failed ($!)";
47
+sub fix_pl_scripts_perm
50
+ system(qq{find $path -type f -name '*.pl' -print0 | xargs -0 chmod 755}) == 0
51
+ or die "Can't fix $path/* .pl perm : $!";
54
###########################################################################
55
# Non-interactive override. Pass a filename on the command line which is
56
# a Perl script. This script defines a %answer hash whose names are tags
58
unless (-d 'graphs') {
59
print "Creating graphs directory...\n";
60
# permissions for non-webservergroup are fixed later on
61
- mkdir 'graphs', 0770;
62
+ mkdir 'graphs', 0775;
65
foreach my $in_file (glob("$datadir/mining/*"))
67
@@ -1017,17 +1040,21 @@
71
- if (!-e "Bugzilla/.htaccess") {
72
- print "Creating Bugzilla/.htaccess...\n";
73
- open HTACCESS, '>', 'Bugzilla/.htaccess';
74
- print HTACCESS <<'END';
75
-# nothing in this directory is retrievable unless overriden by an .htaccess
80
- chmod $fileperm, "Bugzilla/.htaccess";
83
+ # This has nothing to do with Debian in fact, as Bugzilla Perl modules are
84
+ # in /usr/share/perl5/Bugzilla.
85
+ # I then comment out that block.
86
+# if (!-e "Bugzilla/.htaccess") {
87
+# print "Creating Bugzilla/.htaccess...\n";
88
+# open HTACCESS, '>', 'Bugzilla/.htaccess';
89
+# print HTACCESS <<'END';
90
+## nothing in this directory is retrievable unless overriden by an .htaccess
95
+# chmod $fileperm, "Bugzilla/.htaccess";
97
# Even though $datadir may not (and should not) be in the webtree,
98
# we can't know for sure, so create the .htaccess anyeay. Its harmless
99
# if its not accessible...
100
@@ -1308,6 +1335,11 @@
102
# fix file (or files - wildcards ok) permissions
105
+ # In Debian, we already have good permissions thanks to postinst
106
+ # and we use a simpliest method for that, see fix_www_data_perm()
109
my ($file_pattern, $owner, $group, $umask, $do_dirs) = @_;
110
my @files = glob($file_pattern);
111
my $execperm = 0777 & ~ $umask;
112
@@ -1317,6 +1349,7 @@
113
# do not change permissions on directories here unless $do_dirs is set
115
chown $owner, $group, $file;
116
+ print "chown $owner, $group, $file;\n";
117
# check if the file is executable.
118
if (isExecutableFile($file)) {
119
#printf ("Changing $file to %o\n", $execperm);
120
@@ -1328,6 +1361,7 @@
123
chown $owner, $group, $file;
124
+ print "chown $owner, $group, $file;\n";
125
if ($file =~ /CVS$/) {
128
@@ -1362,14 +1396,14 @@
129
fixPerms($templatedir, $<, $webservergid, 027, 1);
130
fixPerms('css', $<, $webservergid, 027, 1);
131
fixPerms('js', $<, $webservergid, 027, 1);
132
- chmod 0644, 'globals.pl';
133
+# chmod 0644, 'globals.pl';
135
# Don't use fixPerms here, because it won't change perms on the directory
136
# unless its using recursion
137
- chown $<, $webservergid, $datadir;
138
- chmod 0771, $datadir;
139
- chown $<, $webservergid, 'graphs';
140
- chmod 0770, 'graphs';
141
+# chown $<, $webservergid, $datadir;
142
+# chmod 0771, $datadir;
143
+# chown $<, $webservergid, 'graphs';
144
+# chmod 0770, 'graphs';
146
# get current gid from $( list
147
my $gid = (split " ", $()[0];
148
@@ -1390,10 +1424,10 @@
150
# Don't use fixPerms here, because it won't change perms on the directory
151
# unless its using recursion
152
- chown $<, $gid, $datadir;
153
- chmod 0777, $datadir;
154
- chown $<, $gid, 'graphs';
155
- chmod 01777, 'graphs';
156
+# chown $<, $gid, $datadir;
157
+# chmod 0777, $datadir;
158
+# chown $<, $gid, 'graphs';
159
+# chmod 01777, 'graphs';
163
@@ -4238,7 +4272,9 @@
164
" WHERE name = 'admin' AND id = group_id");
166
# when we have no admin users, prompt for admin email address and password ...
167
-if ($sth->rows == 0) {
168
+# if we are in non-interactive mode, process anyway.
169
+if ($sth->rows == 0 or defined $answer{'ADMIN_EMAIL'}) {
170
+ my $update_only = 1 if $sth->rows > 0;
174
@@ -4263,16 +4299,24 @@
175
and at least one \'.\' after the @.';
178
- print "\nLooks like we don't have an administrator set up yet. Either this is your\n";
179
- print "first time using Bugzilla, or your administrator's privileges might have accidently\n";
180
- print "been deleted.\n";
181
- while(! $admin_ok ) {
182
- while( $login eq "" ) {
183
- print "Enter the e-mail address of the administrator: ";
184
+ unless ($update_only) {
185
+ print "\nLooks like we don't have an administrator set up yet. Either this is your\n";
186
+ print "first time using Bugzilla, or your administrator's privileges might have accidently\n";
187
+ print "been deleted.\n";
190
+ #this is useful when using this script in non-interactive mode.
191
+ my $cycle_count = 0;
193
+ while(! $admin_ok ) {
194
+ while( $login eq "") {
195
+ print "Enter the e-mail address of the administrator: "
196
+ unless defined $answer{'ADMIN_EMAIL'};
197
$login = $answer{'ADMIN_EMAIL'}
198
|| ($silent && die("cant preload ADMIN_EMAIL"))
203
print "\nYou DO want an administrator, don't you?\n";
205
@@ -4284,18 +4328,24 @@
206
# Go round, and ask them again
210
+ die "Failed to get a valid email address: $login\n" if
211
+ ($cycle_count++ > MAX_PROMPT_CYCLE);
213
$login = $dbh->quote($login);
214
$sth = $dbh->prepare("SELECT login_name FROM profiles" .
215
" WHERE login_name=$login");
217
if ($sth->rows > 0) {
218
- print "$login already has an account.\n";
219
- print "Make this user the administrator? [Y/n] ";
220
+ if (not $answer{'ADMIN_OK'}) {
221
+ print "$login already has an account.\n";
222
+ print "Make this user the administrator? [Y/n] ";
224
my $ok = $answer{'ADMIN_OK'}
225
|| ($silent && die("cant preload ADMIN_OK"))
232
@@ -4318,17 +4368,21 @@
236
- if ($admin_create) {
239
while( $realname eq "" ) {
240
- print "Enter the real name of the administrator: ";
241
+ print "Enter the real name of the administrator: "
242
+ unless defined $answer{'ADMIN_REALNAME'};
243
$realname = $answer{'ADMIN_REALNAME'}
244
|| ($silent && die("cant preload ADMIN_REALNAME"))
249
print "\nReally. We need a full name.\n";
251
+ die "Failed to get a valid realname: $realname\n" if
252
+ ($cycle_count++ > MAX_PROMPT_CYCLE);
255
# trap a few interrupts so we can fix the echo if we get aborted.
256
@@ -4337,17 +4391,23 @@
257
$SIG{QUIT} = \&bailout;
258
$SIG{TERM} = \&bailout;
260
- if ($^O !~ /MSWin32/i) {
261
+ # only on interactive mode !
262
+ if ((not $answer{'ADMIN_PASSWORD'}) and $^O !~ /MSWin32/i) {
263
system("stty","-echo"); # disable input echoing
266
+ my $interactive = 1;
267
+ $interactive = 0 if defined $answer{'ADMIN_PASSWORD'};
269
while( $pass1 ne $pass2 ) {
271
while( $pass1 eq "" || $pass1 !~ /^[[:print:]]{3,16}$/ ) {
272
- print "Enter a password for the administrator account: ";
273
+ print "Enter a password for the administrator account: "
274
+ unless defined $answer{'ADMIN_PASSWORD'};
275
$pass1 = $answer{'ADMIN_PASSWORD'}
276
|| ($silent && die("cant preload ADMIN_PASSWORD"))
281
print "\n\nAn empty password is a security risk. Try again!\n";
282
} elsif ( $pass1 !~ /^.{3,16}$/ ) {
283
@@ -4355,8 +4415,13 @@
284
} elsif ( $pass1 !~ /^[[:print:]]{3,16}$/ ) {
285
print "\n\nThe password contains non-printable characters.\n";
288
+ die "Failed to get a valid password: $pass1\n" if
289
+ ($cycle_count++ > MAX_PROMPT_CYCLE);
291
- print "\nPlease retype the password to verify: ";
292
+ print "\nPlease retype the password to verify: "
295
$pass2 = $answer{'ADMIN_PASSWORD'}
296
|| ($silent && die("cant preload ADMIN_PASSWORD"))
298
@@ -4371,7 +4436,8 @@
299
# Crypt the administrator's password
300
my $cryptedpassword = Crypt($pass1);
302
- if ($^O !~ /MSWin32/i) {
303
+ # Only on interactive mode
304
+ if ($interactive and $^O !~ /MSWin32/i) {
305
system("stty","echo"); # re-enable input echoing
308
@@ -4386,9 +4452,26 @@
309
# Set default email flags for the Admin, same as for users
310
my $defaultflagstring = $dbh->quote(Bugzilla::Constants::DEFAULT_EMAIL_SETTINGS);
312
- $dbh->do("INSERT INTO profiles (login_name, realname, cryptpassword, emailflags) " .
313
- "VALUES ($login, $realname, $cryptedpassword, $defaultflagstring)");
314
+ if ($admin_create) {
315
+ warn "Creating the administrator $login...\n"
316
+ if ($answer{'ADMIN_REALNAME'});
318
+ unless($dbh->do("INSERT INTO profiles (login_name, realname, cryptpassword, emailflags) " .
319
+ "VALUES ($login, $realname, $cryptedpassword, $defaultflagstring)")) {
320
+ die "Unable to create the $login profile.";
324
+ # The ADMIN_REALNAME exists already, but we have to update his profile.
326
+ warn "Updating the $login account...\n";
327
+ unless ($dbh->do("UPDATE profiles SET realname=$realname, cryptpassword=$cryptedpassword ".
328
+ "WHERE login_name=$login")) {
329
+ die "Unable to update the $login profile.";
333
+ unless ($update_only) {
334
# Put the admin in each group if not already
335
my $query = "select userid from profiles where login_name = $login";
336
$sth = $dbh->prepare($query);
337
@@ -4405,6 +4488,7 @@
338
(user_id, group_id, isbless, grant_type)
339
VALUES ($userid, $admingroupid, 1, " . GRANT_DIRECT . ")");
342
# Admins get inherited membership and bless capability for all groups
343
foreach my $group ( @groups ) {
344
$dbh->do("INSERT INTO group_group_map
345
@@ -4414,6 +4498,7 @@
346
(member_id, grantor_id, isbless)
347
VALUES ($admingroupid, $group, 1)");
351
print "\n$login is now set up as an administrator account.\n";
353
@@ -4550,5 +4635,17 @@
354
# when test product was created, admin was unknown
355
$dbh->do("UPDATE components SET initialowner = $adminuid WHERE initialowner = 0");
357
+# That's deprecated...
359
+# Now fixing the right permissions ala bugzilla.postinst.
360
+# Doing this here is better : it will allow user to run
361
+# checksetup.pl by hand without breaking bugzilla.
363
+# print "Fixing permissions for www-data...\n";
364
+fix_www_data_perm('/usr/share/bugzilla');
365
+fix_www_data_perm('/var/cache/bugzilla');
366
+fix_www_data_perm('/var/lib/bugzilla');
367
+fix_pl_scripts_perm('/usr/share/bugzilla/lib');
369
unlink "$datadir/versioncache";