From e37bab52fe933afc29428cd22527909ab4651acf Mon Sep 17 00:00:00 2001 From: "bugreport%peshkin.net" <> Date: Sun, 1 Sep 2002 07:33:01 +0000 Subject: Bug 123957 run checksetup.pl non-interactively (for use with cron jobs on test installs) 2xr=bbaetz --- checksetup.pl | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'checksetup.pl') diff --git a/checksetup.pl b/checksetup.pl index 99a04d621..d387571b4 100755 --- a/checksetup.pl +++ b/checksetup.pl @@ -88,7 +88,27 @@ # example, --LOCAL-- is at least 3 times in this code! --TABLE-- # also is used more than once. So search for every occurence! # - +# To operate checksetup non-interactively, run it with a single argument +# specifying a filename with the information usually obtained by +# prompting the user or by editing localconfig. Only information +# superceding defaults from LocalVar() function calls needs to be +# specified. +# +# The format of that file is.... +# +# $answer{'db_host'} = '$db_host = "localhost"; +# $db_port = 3306; +# $db_name = "mydbname"; +# $db_user = "mydbuser";'; +# +# $answer{'db_pass'} = q[$db_pass = 'mydbpass';]; +# +# $answer{'ADMIN_OK'} = 'Y'; +# $answer{'ADMIN_EMAIL'} = 'myadmin@mydomain.net'; +# $answer{'ADMIN_PASSWORD'} = 'fooey'; +# $answer{'ADMIN_REALNAME'} = 'Joel Peshkin'; +# +# ########################################################################### # Global definitions @@ -104,7 +124,7 @@ use Bugzilla::Config qw(:DEFAULT :admin); # this way we can look in the symbol table to see if they've been declared # yet or not. -use vars qw( $db_name ); +use vars qw( $db_name %answer ); ########################################################################### # Check required module @@ -300,6 +320,11 @@ if (%missing) { print "Checking user setup ...\n"; $@ = undef; +if ($ARGV[0]) { + do $ARGV[0] + or eval die("Error $! processing $ARGV[0]") + or die("Error $@ processing $ARGV[0]"); +} do 'localconfig'; if ($@) { # capture errors in localconfig, bug 97290 print STDERR <>localconfig'; - print FILE $definition, "\n\n"; + print FILE ($answer{$name} or $definition), "\n\n"; close FILE; } @@ -1953,7 +1978,7 @@ if ($sth->rows == 0) { while(! $admin_ok ) { while( $login eq "" ) { print "Enter the e-mail address of the administrator: "; - $login = ; + $login = $answer{'ADMIN_EMAIL'} or ; chomp $login; if(! $login ) { print "\nYou DO want an administrator, don't you?\n"; @@ -1977,7 +2002,7 @@ _End_Of_SQL_ if ($sth->rows > 0) { print "$login already has an account.\n"; print "Make this user the administrator? [Y/n] "; - my $ok = ; + my $ok = $answer{'ADMIN_OK'} or ; chomp $ok; if ($ok !~ /^n/i) { $admin_ok = 1; @@ -1988,7 +2013,7 @@ _End_Of_SQL_ } } else { print "You entered $login. Is this correct? [Y/n] "; - my $ok = ; + my $ok = $answer{'ADMIN_OK'} or ; chomp $ok; if ($ok !~ /^n/i) { $admin_ok = 1; @@ -2003,7 +2028,7 @@ _End_Of_SQL_ while( $realname eq "" ) { print "Enter the real name of the administrator: "; - $realname = ; + $realname = $answer{'ADMIN_REALNAME'} or ; chomp $realname; if(! $realname ) { print "\nReally. We need a full name.\n"; @@ -2021,7 +2046,7 @@ _End_Of_SQL_ while( $pass1 ne $pass2 ) { while( $pass1 eq "" || $pass1 !~ /^[a-zA-Z0-9-_]{3,16}$/ ) { print "Enter a password for the administrator account: "; - $pass1 = ; + $pass1 = $answer{'ADMIN_PASSWORD'} or ; chomp $pass1; if(! $pass1 ) { print "\n\nIt's just plain stupid to not have a password. Try again!\n"; @@ -2030,7 +2055,7 @@ _End_Of_SQL_ } } print "\nPlease retype the password to verify: "; - $pass2 = ; + $pass2 = $answer{'ADMIN_PASSWORD'} or ; chomp $pass2; if ($pass1 ne $pass2) { print "\n\nPasswords don't match. Try again!\n"; -- cgit v1.2.3-24-g4f1b