#!/usr/local/bin/perl # # install script for UNIXhelp 1.2 $old_scripturl = "http://unixhelp.ed.ac.uk/CGI"; ## pageupdate (directory, file) ## ## Updates a specific file according to the desired parameters sub pageupdate { local($dir,$page) = @_; &replace($dir,$page,$old_scripturl,$script_dir); # update scriptname if ($anonymous == 0) { # add maintainer &replace($dir,$page,"",$extra_footer); } } ## input_details ## ## obtains references for custom install sub input_details { print "What is the URL of your script directory?\n"; &getinput; $script_dir = $answer; print "\nWhat is the full email address of the local maintainer?\n"; print "This will be added at the bottom of each page for local feedback.\n"; print "If you don't want such a link added, just press Return.\n"; &getinput; $maint_name = $answer; } ## these_are_ok ## ## checks with installer that parameters are correct sub these_are_ok { print "\n\nYou will put the scripts in the directory:\n"; print "$script_dir\n"; $anonymous = 0; print "\nYour local maintainer is:\n"; if (length($maint_name) == 0) { print "(anonymous)\n"; $anonymous = 1; } else { print "$maint_name\n"; $extra_footer=<$maint_name EOFOOT } print "\nIs this correct (y/n)? "; &getinput; print "\n"; $answer =~ /[yY]/; } ## getinput ## ## reads a value from stdin sub getinput { $answer = ; chop($answer); } ## replace (directory, file, searchstring, replacestring) ## ## does the search and replace operation on an individual file sub replace { local($dir,$file,$sstring,$rstring) = @_; $remember = $/; # Note current record separator $/ = undef; # Ignore newline characters open(FILE,"$dir/$file") || die "Can't open file: $!\n"; # open file if possible $_ = ; # Load entire file into matchspace s/$sstring/$rstring/gi; close(FILE); open(WRITEFILE,"> $dir/$file"); print WRITEFILE $_; $/ = $remember; # Recognise separator again close(WRITEFILE); } ## main ## ## # check working directory if (!(-d "Pages") || !(-d "Scripts")) { die "Working directory must be original location of install script\n"; } # get necessary information from installer do {&input_details} until &these_are_ok; if (substr($script_dir,-1) eq "/") { chop($script_dir); } # Remove trailing / if present # update pages to conform open(PAGES,"ls Pages |"); # Start page listing while ($item = ) { # get next page if possible chop($item); # strip newline from page name &pageupdate("Pages",$item); print "Updated page: $item\n"; } close(PAGES); # update search script $extra_footer =~ s/@/\\@/g; &pageupdate("Scripts","unixhelp_search"); print "Updated search script\n\n"; # end print "** All automatic changes complete **\n"; print "Now edit header of search script and move pages and scripts into place.\n\n";