#!/usr/bin/perl -w # # localize # # Change the named programs depending upon the machine this # is being executed on. # # Usage: # SupportBin/localize file1 file2 file3 # # It is important that this be started from the top # of the application area from the main Makefile. This # allows us to know a certain amount of information. # # This makes the following changes: # Sets permissions of files to 444 unless it is a config # file in which case the permissions are set to 664. # Programs are marked as executable. # # Changes ApplRoot to the current directory. # # Sets the #!.../perl at the top of the programs to something # appropriate. # # Rewrite the entries in the register.config file. # # Write an appropriate location for the webc program. # # This does make use of selections in Config/defs.wh, so # that file should be set up before running this program. # # Dave Regan # regan@peak.org # http://cornvalley.peak.org/ # Copyright 1997,1998 Dave Regan, all rights reserved # use Sys::Hostname; use English; use Cwd; use Config; use vars qw($LocalizeVersion); $LocalizeVersion = 'localize v0.06 regan@ao.com'; ### ### Main program ### ### Site installation should not have to change anything below here. ### if ($PERL_VERSION < 5.003) { print STDERR "We need perl 5.\n"; exit 1; } # The caller has requested the value of a specific value if ($ARGV[0] eq "-v") { print Head($ARGV[1]); exit 0; } DiscoverEnvironment(); for $file (@ARGV) { $mode = 0444; $mode |= 0220 if ($file =~ m#/config#); if (!open(PGM, "<$file")) { print "Cannot open $file\n"; next; } if (!open(NEW, ">$file.new")) { close PGM; print "Cannot open $file.new\n"; next; } for ($line = 1; ; $line++) { if ($line == 1 && /^(#!).*perl\S*(.*)/) { # Handle the #!.../perl at the start of programs. $_ = "$1$Perl$2\n"; $mode |= 0111; } if (/^\$ApplRoot\s*=/) { # Handle the ApplRoot definition in programs # This code only is effective if the root isn't already # defined. This is important for the appl.lc file. s/=.*;/= \"$Root\" if (!defined(\$ApplRoot));/; } if (/^AuthUserFile\s/) { $_ = "AuthUserFile $Data/passwd\n"; } if ($file =~ /register.config/) { # Handle the various data fields in register.config. if (m#^(\$(Password|Pending|Accepted|Configuration)\s*=\s*").*(/[^/]+$)#) { $_ = "$1$Data$3"; } if (m#^(\$Template\s*=\s*").*(/[^/]+$)#) { $_ = "$1$Root$2"; } } elsif ($file =~ /config/ || $file =~ /\.wh/) { # Handle fields in the registration config files. # These aren't really needed if the file is correct. # if (m#(.*)/export/home/regan/public_html/odfw/(.*)#) # { # $_ = "$1$Root/$2\n"; # } # if (m#(.*)http://www.ao.com/~regan/odfw(.*)#) # { # $_ = "$1$WebRoot/$2\n"; # } if (/adminemail/) { $_ = "adminemail\t$Address\n"; } } # if (m#(\$WebC\s*=\s*").*(";)#) # { # # Set the path for Webc. # $_ = "$1$Root/SupportBin/webc$2\n"; # } print NEW $_; } close PGM; close NEW; unlink("$file.old"); rename($file, "$file.old"); rename("$file.new", $file); chmod($mode, $file); } ### ### DiscoverEnvironment ### ### Find out about ourself. ### sub DiscoverEnvironment { # # The root should be where we are. See that the directories # look approximately right. # $Root = cwd(); if (! -d "SupportBin" || ! -d "Config" || ! -d "Site") { print STDERR "The localize program must be run from the main\n" . "application directory. Go back and edit Config/defs.wh\n" . "and then type \"make install\".\n"; exit 1; } print "We will be using \"$Root\" as our main directory\n"; # # Discover the name of the perl interpreter we are # currently using. # if ($EXECUTABLE_NAME =~ m#^/#) { $Perl = $EXECUTABLE_NAME; # Absolute path is unambiguous } else { # Look to see how we are supposed to start up. ($Perl = $Config{'startperl'}) =~ s/^#!//; } print "We will be using \"$Perl\" for an interpreter\n"; # # The next few items will come from Config/defs.wh. # It better be right. # $Data = Head('_HOME-FS_'); print "We will be using \"$Data\" for the data directory\n"; $Group = Head('_HOME-GROUP_'); print "We will be using \"$Group\" for the group ID\n"; $Address = Head('_EMAIL-ADDR_'); print "We will be using \"$Address\" for the administrator's address\n"; $WebRoot = Head('_HOME-URL_'); print "We will be using \"$WebRoot\" for the home web page\n"; } ### ### Head ### ### Return a variable from the %Head hash, and make all of the ### possible expansions from %Head. ### ### This is patterned from the Expand function in webc. ### sub Head { my($name) = @_; my($count1, $count2, $sym); if (!defined(%Head)) { if (!open(HEAD, ") { chomp; $Head{$1} = $2 if (/^\s*#\s*define\s+(\S+)\s+(.*)/); } close HEAD; } $_ = $Head{$name}; return "" if (!defined($_)); for ($count1 = 0; $count1 < 100; $count1++) { $count2 = 0; for $sym (keys %Head) { next if (!defined($sym) || $sym eq "" || !defined($Head{$sym})); $count2 += s/$sym/$Head{$sym}/g; } last if ($count2 == 0); } return $_; }