]> andersk Git - gssapi-openssh.git/blobdiff - setup/setup-openssh.pl
o Add relative paths to the beginning of the original package build
[gssapi-openssh.git] / setup / setup-openssh.pl
index 0b1dc70f6437d5752734e6ed87480756970417c4..d703bf30dbf2e259c831f60103e10ccafaf6115f 100644 (file)
@@ -1,15 +1,30 @@
+#!/usr/bin/perl
 #
-# setup-openssh.pl:
-#   Adapts the installed gsi-ssh environment to the current machine,
-#   performing actions that originally occurred during the package's
-#   'make install' phase.
+# setup-openssh.pl
 #
-# Large parts adapted from 'fixpath', a tool found in openssh-3.0.2p1.
+# Adapts the installed gsi-ssh environment to the current machine,
+# performing actions that originally occurred during the package's
+# 'make install' phase.
+#
+# Parts adapted from 'fixpath', a tool found in openssh-3.0.2p1.
 #
 # Send comments/fixes/suggestions to:
 # Chase Phillips <cphillip@ncsa.uiuc.edu>
 #
 
+printf("setup-openssh.pl: Configuring gsi-openssh package\n");
+
+#
+# Get user's GPT_LOCATION since we may be installing this using a new(er)
+# version of GPT.
+#
+
+$gptpath = $ENV{GPT_LOCATION};
+
+#
+# And the old standby..
+#
+
 $gpath = $ENV{GLOBUS_LOCATION};
 if (!defined($gpath))
 {
@@ -21,7 +36,14 @@ if (!defined($gpath))
 # do so
 #
 
-@INC = (@INC, "$gpath/lib/perl");
+if (defined($gptpath))
+{
+    @INC = (@INC, "$gptpath/lib/perl", "$gpath/lib/perl");
+}
+else
+{
+    @INC = (@INC, "$gpath/lib/perl");
+}
 
 require Grid::GPT::Setup;
 
@@ -29,9 +51,6 @@ my $globusdir = $gpath;
 my $setupdir = "$globusdir/setup/globus";
 my $myname = "setup-openssh.pl";
 
-print "$myname: Configuring package 'gsi_openssh'...\n";
-print "Run this as root for the intended effect...\n";
-
 #
 # Set up path prefixes for use in the path translations
 #
@@ -47,65 +66,110 @@ $sysconfdir = "/etc/ssh";
 $piddir = "/var/run";
 $xauth_path = "/usr/bin/X11/xauth";
 
+#
+# Backup-related variables
+#
+
+$curr_time = time();
+$backupdir = "/etc/ssh/globus_backup_${curr_time}";
+
+#
+# Check that we are running as root
+#
+
+$uid = $>;
+
+if ($uid != 0)
+{
+    print "--> NOTE: You must be root to run this script! <--\n";
+    exit 0;
+}
+
 #
 # We need to make sure it's okay to copy our setup files (if some files are already
 # present).  If we do copy any files, we backup the old files so the user can (possibly)
 # reverse any damage.
 #
 
-sub copy_setup_files
+sub test_dirs
 {
-    my $response, $curr_time;
+    print "\nPreparatory: Checking for existence of critical directories..\n";
 
-    $curr_time = time();
+    #
+    # Remember to put in check for /etc
+    #
 
-    $response = "y";
-    if ( -e "${sysconfdir}/ssh_config" )
-    {
-        $response = query_boolean("${sysconfdir}/ssh_config already exists.  Overwrite? ", "n");
-    }
+    #
+    # Test for /etc/ssh
+    #
 
-    if ($response eq "y")
+    if ( ! -d "$sysconfdir" )
     {
-        action("cp ${sysconfdir}/ssh_config ${sysconfdir}/ssh_config.bak_${curr_time}");
-        action("cp ${globusdir}/setup/globus/ssh_config ${sysconfdir}/ssh_config");
+        print "Could not find directory: '${sysconfdir}'.. creating.\n";
+        mkdir($sysconfdir, 16877);
+        # 16877 should be 755, or drwxr-xr-x
     }
 
     #
-    # Reset response for our new query
+    # Test for /etc/ssh/globus_backup_<curr>
     #
 
-    $response = "y";
-    if ( -e "${sysconfdir}/sshd_config" )
+    if ( ! -d "${backupdir}" )
     {
-        $response = query_boolean("${sysconfdir}/sshd_config already exists.  Overwrite? ", "n");
+        print "Could not find directory: '${backupdir}'.. creating.\n";
+        mkdir($backupdir, 16877);
     }
 
-    if ($response eq "y")
+    return 0;
+}
+
+sub backup_files
+{
+    print "\nStage 1: Backing up configuration files to '${backupdir}/'..\n";
+
+    if ( -e "${sysconfdir}/ssh_config" )
+    {
+        action("cp ${sysconfdir}/ssh_config ${backupdir}/ssh_config");
+    }
+    else
     {
-        action("cp ${sysconfdir}/sshd_config ${sysconfdir}/sshd_config.bak_${curr_time}");
-        action("cp ${globusdir}/setup/globus/sshd_config ${sysconfdir}/sshd_config");
+        print "${sysconfdir}/ssh_config does not exist.\n";
     }
 
-    #
-    # Reset response for our new query
-    #
+    if ( -e "${sysconfdir}/sshd_config" )
+    {
+        action("cp ${sysconfdir}/sshd_config ${backupdir}/sshd_config");
+    }
+    else
+    {
+        print "${sysconfdir}/sshd_config does not exist.\n";
+    }
 
-    $response = "y";
     if ( -e "${sysconfdir}/moduli" )
     {
-        $response = query_boolean("${sysconfdir}/moduli already exists.  Overwrite? ", "n");
+        action("cp ${sysconfdir}/moduli ${backupdir}/moduli");
     }
-
-    if ($response eq "y")
+    else
     {
-        action("cp ${sysconfdir}/moduli ${sysconfdir}/moduli.bak_${curr_time}");
-        action("cp ${globusdir}/setup/globus/moduli ${sysconfdir}/moduli");
+        print "${sysconfdir}/moduli does not exist.\n";
     }
 }
 
+sub copy_setup_files
+{
+    my $response;
+
+    print "\nStage 2: Copying configuration files into '${sysconfdir}'..\n";
+
+    action("cp ${globusdir}/setup/globus/ssh_config ${sysconfdir}/ssh_config");
+    action("cp ${globusdir}/setup/globus/sshd_config ${sysconfdir}/sshd_config");
+    action("cp ${globusdir}/setup/globus/moduli ${sysconfdir}/moduli");
+}
+
 sub runkeygen
 {
+    print "\nStage 3: Generating ssh host keys..\n";
+
     if ( ! -d "${sysconfdir}" )
     {
         print "Could not find ${sysconfdir} directory... creating\n";
@@ -113,7 +177,6 @@ sub runkeygen
         # 16877 should be 755, or drwxr-xr-x
     }
 
-    print "Generating ssh keys (if necessary)...\n";
     if ( -e "${sysconfdir}/ssh_host_key" )
     {
         print "${sysconfdir}/ssh_host_key already exists, skipping.\n";
@@ -149,6 +212,10 @@ sub runkeygen
 
 sub fixpaths
 {
+    my $g, $h;
+
+    print "\nStage 4: Translating strings in config and man files..\n";
+
     #
     # Set up path translations for the installation files
     #
@@ -167,38 +234,28 @@ sub fixpaths
         "/etc/sshrc" => "${sysconfdir}/sshrc",
         "/usr/X11R6/bin/xauth" => "${xauth_path}",
         "/usr/bin:/bin:/usr/sbin:/sbin" => "/usr/bin:/bin:/usr/sbin:/sbin:${bindir}",
-        "(/path/to/scp.real)" => "${bindir}/scp.real",
-        "(/path/to/ssh)" => "${bindir}/ssh",
-        "(/path/to/sftp.real)" => "${bindir}/sftp.real",
-        "(/path/to/sshd.real)" => "${sbindir}/sshd.real",
-        "(/path/to/ssh_config)" => "${sysconfdir}/ssh_config",
-        "(/path/to/sshd_config)" => "${sysconfdir}/sshd_config",
         );
 
     #
     # Files on which to perform path translations
     #
 
-    %files = (
-        "${bindir}/scp" => 0,
-        "${bindir}/sftp" => 0,
-        "${sbindir}/sshd" => 0,
-        "${sysconfdir}/ssh_config" => 1,
-        "${sysconfdir}/sshd_config" => 1,
-        "${sysconfdir}/moduli" => 1,
-        "${mandir}/${mansubdir}1/scp.1" => 0,
-        "${mandir}/${mansubdir}1/ssh-add.1" => 0,
-        "${mandir}/${mansubdir}1/ssh-agent.1" => 0,
-        "${mandir}/${mansubdir}1/ssh-keygen.1" => 0,
-        "${mandir}/${mansubdir}1/ssh-keyscan.1" => 0,
-        "${mandir}/${mansubdir}1/ssh.1" => 0,
-        "${mandir}/${mansubdir}8/sshd.8" => 0,
-        "${mandir}/${mansubdir}8/sftp-server.8" => 0,
-        "${mandir}/${mansubdir}1/sftp.1" => 0,
+    @files = (
+        "${sysconfdir}/ssh_config",
+        "${sysconfdir}/sshd_config",
+        "${sysconfdir}/moduli",
+        "${mandir}/${mansubdir}1/scp.1",
+        "${mandir}/${mansubdir}1/ssh-add.1",
+        "${mandir}/${mansubdir}1/ssh-agent.1",
+        "${mandir}/${mansubdir}1/ssh-keygen.1",
+        "${mandir}/${mansubdir}1/ssh-keyscan.1",
+        "${mandir}/${mansubdir}1/ssh.1",
+        "${mandir}/${mansubdir}8/sshd.8",
+        "${mandir}/${mansubdir}8/sftp-server.8",
+        "${mandir}/${mansubdir}1/sftp.1",
         );
 
-    print "Translating strings in config/man files...\n";
-    for my $f (keys %files)
+    for my $f (@files)
     {
         $f =~ /(.*\/)*(.*)$/;
 
@@ -209,6 +266,13 @@ sub fixpaths
 
         $g = "$f.tmp";
 
+        #
+        # What is $f's filename? (taken from the qualified path)
+        #
+
+        $h = $f;
+        $h =~ s#^.*/##;
+
         #
         # Grab the current mode/uid/gid for use later
         #
@@ -217,7 +281,15 @@ sub fixpaths
         $uid = (stat($f))[4];
         $gid = (stat($f))[5];
 
-        action("mv $f $g");
+        #
+        # Move $f into a .tmp file for the translation step
+        #
+
+        $result = system("mv $f $g 2>&1");
+        if ($result or $?)
+        {
+            die "ERROR: Unable to execute command: $!\n";
+        }
 
         open(IN, "<$g") || die ("$0: input file $g missing!\n");
         open(OUT, ">$f") || die ("$0: unable to open output file $f!\n");
@@ -234,13 +306,15 @@ sub fixpaths
         close(OUT);
         close(IN);
 
-        if ($file{$f} eq 0)
-        {
-            action("rm $g");
-        }
-        else
+        #
+        # Remove the old .tmp file
+        #
+
+        $result = system("rm $g 2>&1");
+
+        if ($result or $?)
         {
-            print "Left backup config file '$g'\n";
+            die "ERROR: Unable to execute command: $!\n";
         }
 
         #
@@ -250,11 +324,102 @@ sub fixpaths
 
         chmod($mode, $f);
         chown($uid, $gid, $f);
+
+        print "$h\n";
     } # for $f
 
     return 0;
 }
 
+sub fixGlobusLocation
+{
+    $data = readFile($initfile);
+    $data =~ s|@GLOBUS_LOCATION@|$gpath|g;
+    writeFile($data);
+}
+
+### readFile( $filename )
+#
+# reads and returns $filename's contents
+#
+
+sub readFile
+{
+    my ($filename) = @_;
+    my $data;
+
+    open (IN, "$filename") || die "Can't open '$filename': $!";
+    $/ = undef;
+    $data = <IN>;
+    $/ = "\n";
+    close(IN);
+
+    return $data;
+}
+
+### writeFile( $filename, $fileinput )
+#
+# create the inputs to the ssl program at $filename, appending the common name to the
+# stream in the process
+#
+
+sub writeFile
+{
+    my ($filename, $fileinput) = @_;
+
+    #
+    # test for a valid $filename
+    #
+
+    if ( !defined($filename) || (length($filename) lt 1) )
+    {
+        die "Filename is undefined";
+    }
+
+    if ( ( -e "$filename" ) && ( ! -w "$filename" ) )
+    {
+        die "Cannot write to filename '$filename'";
+    }
+
+    #
+    # write the output to $filename
+    #
+
+    open(OUT, ">$filename");
+    print OUT "$fileinput";
+    close(OUT);
+}
+
+print "---------------------------------------------------------------\n";
+print "Hi, I'm the setup script for the gsi_openssh package!  There\n";
+print "are some last minute details that I've got to set straight\n";
+print "in the config and man files, along with generating the ssh keys\n";
+print "for this machine (if it doesn't already have them).\n";
+print "\n";
+print "I like to install my config-related files in:\n";
+print "  ${sysconfdir}/\n";
+print "\n";
+print "These files may overwrite your previously existing configuration\n";
+print "files.  If you choose to continue, you will find a backup of\n";
+print "those original files in:\n";
+print "  ${backupdir}/\n";
+print "\n";
+print "Your host keys will remain untouched if they are already present.\n";
+print "If they aren't present, this script will generate them for you.\n";
+print "\n";
+
+$response = query_boolean("Do you wish to continue with the setup package?","y");
+
+if ($response eq "n")
+{
+    print "\n";
+    print "Okay.. exiting gsi_openssh setup.\n";
+
+    exit 0;
+}
+
+test_dirs();
+backup_files();
 copy_setup_files();
 runkeygen();
 fixpaths();
@@ -263,7 +428,22 @@ my $metadata = new Grid::GPT::Setup(package_name => "gsi_openssh_setup");
 
 $metadata->finish();
 
+print "\n";
 print "$myname: Finished configuring package 'gsi_openssh'.\n";
+print "\n";
+print "I see that you have your GLOBUS_LOCATION environmental variable\n";
+print "set to:\n";
+print "  $gpath\n";
+print "\n";
+print "Remember to keep this variable set (correctly) when you want\n";
+print "to use the executables that came with this package.\n";
+print "\n";
+print "Additionally, you may need to set LD_LIBRARY_PATH to point to\n";
+print "the location in which your globus libraries reside.  For example:\n";
+print "\n";
+print "  export LD_LIBRARY_PATH=\"$gpath/lib\"\n";
+print "\n";
+print "---------------------------------------------------------------\n";
 
 #
 # Just need a minimal action() subroutine for now..
@@ -304,14 +484,27 @@ sub query_boolean
     print "${query_text} ";
     print "[$default] ";
 
-    $foo = getc(STDIN);
-    $bar = <STDIN>;
+    $foo = <STDIN>;
+    ($bar) = split //, $foo;
 
-    if ($foo ne $nondefault)
+    if ( grep(/\s/, $bar) )
     {
-        $foo = $default;
+        # this is debatable.  all whitespace means 'default'
+
+        $bar = $default;
     }
+    elsif ($bar ne $default)
+    {
+        # everything else means 'nondefault'.
 
-    return $foo;
-}
+        $bar = $nondefault;
+    }
+    else
+    {
+        # extraneous step.  to get here, $bar should be eq to $default anyway.
 
+        $bar = $default;
+    }
+
+    return $bar;
+}
This page took 0.050826 seconds and 4 git commands to generate.