From: Matt L. v. a. <we...@ma...> - 2007-09-09 21:24:54
|
Log Message: ----------- More robust installation script. Finds support programs automagically and installs CPAN modules as necessary. Modified Files: -------------- ww_question_server/bin/setup: setup.pl Revision Data ------------- Index: setup.pl =================================================================== RCS file: /webwork/cvs/system/ww_question_server/bin/setup/setup.pl,v retrieving revision 1.3 retrieving revision 1.4 diff -Lbin/setup/setup.pl -Lbin/setup/setup.pl -u -r1.3 -r1.4 --- bin/setup/setup.pl +++ bin/setup/setup.pl @@ -1,88 +1,197 @@ #!/usr/bin/env perl -# + +use CPAN; +use File::Which; die "You do not have File::Which installed.\n Run perl -MCPAN -e 'install File::Which' to install. Then rerun this." if $@; + +sub promptUser { + + #-------------------------------------------------------------------# + # two possible input arguments - $promptString, and $defaultValue # + # make the input arguments local variables. # + #-------------------------------------------------------------------# + + local($promptString,$defaultValue) = @_; + + #-------------------------------------------------------------------# + # if there is a default value, use the first print statement; if # + # no default is provided, print the second string. # + #-------------------------------------------------------------------# + + if ($defaultValue) { + print $promptString, "[", $defaultValue, "]: "; + } else { + print $promptString, ": "; + } + + $| = 1; # force a flush after our print + $_ = <STDIN>; # get the input from STDIN (presumably the keyboard) + + + #------------------------------------------------------------------# + # remove the newline character from the end of the input the user # + # gave us. # + #------------------------------------------------------------------# + + chomp; + + #-----------------------------------------------------------------# + # if we had a $default value, and the user gave us input, then # + # return the input; if we had a default, and they gave us no # + # no input, return the $defaultValue. # + # # + # if we did not have a default value, then just return whatever # + # the user gave us. if they just hit the <enter> key, # + # the calling routine will have to deal with that. # + #-----------------------------------------------------------------# + + if ("$defaultValue") { + return $_ ? $_ : $defaultValue; # return $_ if it has a value + } else { + return $_; + } +} + +sub getListModules { + my @cpanModules; + print "Finding Installed CPAN Modules.\n"; + for $mod (CPAN::Shell->expand("Module","/./")){ + next unless $mod->inst_file; + # here only when installed + #get the module + my $modname = $mod->id; + push(@cpanModules,$modname); + print "."; + } + print "Done\n"; + return @cpanModules; +} + +sub moduleExists { + my ($searchModule,@cpanModules) = @_; + foreach(@cpanModules) { + if($_ eq $searchModule) { + return 1; + } + } + return 0; +} + +sub moduleInstaller { + my(@modulesNeeded) = @_; + my @moduleList = getListModules; + my @manuallyNeeded; + foreach(@modulesNeeded) { + my $needed = $_; + if(moduleExists($needed,@moduleList) == 0) { + print "$needed was not found. Do you want to try and install it?\n"; + my $choice = promptUser('(y,n)','y'); + if($choice eq 'y') { + system("perl -MCPAN -e 'install $needed'"); + print "Installed!\n"; + } else { + push(@manuallyNeeded,$needed); + } + } else { + print "Found $needed \n"; + } + } + return @manuallyNeeded; +} + +sub programPath { + my($program) = @_; + $path = which($program); + if($path != 0) { + $enteredPath = promptUser("Enter the path to '$program'"); + } else { + $enteredPath = promptUser("Enter the path to '$program'",$path); + } + return $enteredPath; +} + + + print "###################################\n"; print "#WeBWorK Question Server #\n"; print "###################################\n"; -print "This script will setup the configuration of WeBWorK Question Server.\n"; -print "Continue? (y,n):"; -$input = <STDIN>; -chop $input; -if($input eq "n") {exit;} +#Continue? +print "This script will setup the configuration of WeBWorK Question Server.\n"; +$continue = promptUser('Continue','y'); +if($continue ne "y") { + exit; +} -#APACHE 1 OR 2 -print "Will you be using Apache 1 or 2\n"; -print "(1,2)>"; -$apache = <STDIN>; -chop $apache; -if($apache eq "1") { - $apachecpan = "Apache::SOAP"; -} elsif ($apache eq "2") { - $apachecpan = "Apache2::SOAP"; +#Apache Version +$question = "Which version of Apache"; +$result = which('apache2ctl'); +if($result != 0) { + $result = which('apachectl'); + if($result != 0) { + $apacheVersion = promptUser("$question(1,2)"); + } else { + $apacheVersion = promptUser("$question(1,2)",'1'); + } +} else { + $apacheVersion = promptUser("$question(1,2)",'2'); +} +if($apacheVersion eq '1') { + $apacheSoapCPAN = "Apache::SOAP"; + $modperlCPAN = 'mod_perl'; +} elsif ($apacheVersion eq '2') { + $apacheSoapCPAN = "Apache2::SOAP"; + $modperlCPAN = 'mod_perl2'; } else { exit; } +#CPAN Module Administration +$preqCheck = promptUser("Check CPAN Prerequisites(y,n)",'y'); +if($preqCheck eq 'y') { + @modulesNeeded = ($modperlCPAN,$apacheSoapCPAN,'LWP::Simple','Pod::WSDL','Safe','MIME::Base64','File::Which'); + @manuallyNeeded = moduleInstaller(@modulesNeeded); + + $manuallyNeededCount = @manuallyNeeded; + if($manuallyNeededCount == 0) { + print "All CPAN Modules are Installed!\n"; + } else { + print "Install the following CPAN Modules and rerun this script.\n"; + foreach(@manuallyNeeded) { + print "$_\n"; + } + exit; + } +} + +#Programs +$latex = programPath('latex'); +$dvipng = programPath('dvipng'); +$tth = programPath('tth'); + +#Configuration #HOSTNAME $hostnameExample = "http://www.example.com/"; - print "Please enter the http hostname of the computer.\n"; print "This should be a value like '$hostnameExample'\n"; -print ">"; -$hostname = <STDIN>; -chop $hostname; +$hostname = promptUser(''); print "Please enter the root directory where WeBWorK Question Server is located. \n"; print "Example: /var/www/ww_question_server \n"; -print ">"; -$root = <STDIN>; -chop $root; +$root = promptUser(''); print "Please enter the directory where the PG libraries are located. \n"; print "Example: /opt/webwork/pg \n"; -print ">"; -$pg = <STDIN>; -chop $pg; - -print "Please enter the path to 'latex' command. Leave blank for default. \n"; -print "Default '/usr/bin/latex'\n"; -print ">"; -$latex = <STDIN>; -chop $latex; -if($latex eq "") { - $latex = "/usr/bin/latex"; -} - -print "Please enter the path to 'dvipng' command. Leave blank for default. \n"; -print "Default '/usr/bin/dvipng'\n"; -print ">"; -$dvipng = <STDIN>; -chop $dvipng; -if($dvipng eq "") { - $dvipng = "/usr/bin/dvipng"; -} - -print "Please enter the path to 'tth' command. Leave blank for default. \n"; -print "Default '/usr/bin/tth'\n"; -print ">"; -$tth = <STDIN>; -chop $tth; -if($tth eq "") { - $tth = "/usr/bin/tth"; -} - - - +$pg = promptUser(''); $rpc = "/problemserver_rpc"; $files = "/problemserver_files"; #WSDL FILE CREATION +use Pod::WSDL; print "Creating WSDL File...\n"; eval "use lib '$root/lib'"; die "Your root directory is wrong." if $@; -eval "use Pod::WSDL"; die "You do not have Pod::WSDL installed.\n Run perl -MCPAN -e 'install Pod::WSDL' to install. Then rerun this." if $@; $pod = new Pod::WSDL( source => 'ProblemServer', location => $hostname.$rpc, @@ -149,6 +258,22 @@ close OUTP3; print "Done\n"; +#POST CONFIGURATION +$copyFiles = promptUser('Do you want me to copy created files to their proper locations (y,n)','y'); +if($copyFiles eq 'y') { + system('mv global.conf ' . $root . '/conf/global.conf'); + system('mv problemserver.apache-config ' . $root . '/conf/problemserver.apache-config'); + system('mv WSDL.wsdl ' . $root . '/htdocs/WSDL.wsdl'); +} + +print "********************************\n"; print "Your WSDL path: '" . $hostname . $files . '/'.$wsdlfilename."'\n"; +print "********************************\n"; -#POST CONFIGURATION +print "POST INSTALL\n"; +print "1) Append the following line to your apache configuration file:\n"; +print "Include $root/conf/problemserver.apache-config\n\n"; + +print "2) Restart Apache\n"; + +print "Your done, Enjoy!\n"; |