]> andersk Git - gssapi-openssh.git/blobdiff - setup/setup-openssh.pl
o Change wrapper scripts to use environmental variables.
[gssapi-openssh.git] / setup / setup-openssh.pl
index 62416aa85e712df1d4c783986e874e8069b49c7d..c3bb31626c599e9724c3d50d6936451c2009ca3e 100644 (file)
@@ -29,9 +29,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
 #
@@ -48,53 +45,149 @@ $piddir = "/var/run";
 $xauth_path = "/usr/bin/X11/xauth";
 
 #
-# Just need a minimal action() subroutine for now..
+# Backup-related variables
 #
 
-sub action
+$curr_time = time();
+$backupdir = "globus_backup_${curr_time}";
+$confbackupdir = "$backupdir/s1_conf";
+$transbackupdir = "$backupdir/s3_trans";
+
+#
+# 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 test_dirs
 {
-    my $command = @_;
+    my $composite;
 
-    printf "$command\n";
+    print "\nPreparatory: checking for existence of critical directories\n";
 
-    my $result = system("$command 2>&1");
+    #
+    # Remember to put in check for /etc
+    #
 
-    if (($result or $?) and $command !~ m!patch!)
+    #
+    # Test for /etc/ssh
+    #
+
+    $composite = $sysconfdir;
+    if ( ! -d "$composite" )
     {
-        die "ERROR: Unable to execute command: $!\n";
+        print "Could not find directory: '${composite}'.. creating.\n";
+        mkdir($composite, 16877);
+        # 16877 should be 755, or drwxr-xr-x
+    }
+
+    #
+    # Test for /etc/ssh/globus_backup_<curr>
+    #
+
+    $composite = "$sysconfdir/$backupdir";
+    if ( ! -d "${composite}" )
+    {
+        print "Could not find directory: '${composite}'.. creating.\n";
+        mkdir($composite, 16877);
+    }
+
+    #
+    # Test for /etc/ssh/globus_backup_<curr>/s1_conf
+    #
+
+    $composite = "$sysconfdir/$confbackupdir";
+    if ( ! -d "${composite}" )
+    {
+        print "Could not find directory: '${composite}'.. creating.\n";
+        mkdir($composite, 16877);
+    }
+
+    #
+    # Test for /etc/ssh/globus_backup_<curr>/s2_trans
+    #
+
+    $composite = "$sysconfdir/$transbackupdir";
+    if ( ! -d "${composite}" )
+    {
+        print "Could not find directory: '${composite}'.. creating.\n";
+        mkdir($composite, 16877);
     }
+
+    return 0;
 }
 
 sub copy_setup_files
 {
+    my $response;
+
+    print "\nStage 1: Copying configuration files into '${sysconfdir}'..\n";
+
+    $response = "y";
     if ( -e "${sysconfdir}/ssh_config" )
     {
-        print "${sysconfdir}/ssh_config already exists, skipping.\n";
+        $response = query_boolean("${sysconfdir}/ssh_config already exists.  Overwrite?", "n");
+        if ($response eq "y")
+        {
+            action("cp ${sysconfdir}/ssh_config ${sysconfdir}/${confbackupdir}/ssh_config");
+        }
     }
-    else
+
+    if ($response eq "y")
     {
         action("cp ${globusdir}/setup/globus/ssh_config ${sysconfdir}/ssh_config");
     }
 
+    #
+    # Reset response for our new query
+    #
+
+    $response = "y";
     if ( -e "${sysconfdir}/sshd_config" )
     {
-        print "${sysconfdir}/sshd_config already exists, skipping.\n";
+        $response = query_boolean("${sysconfdir}/sshd_config already exists.  Overwrite?", "n");
+        if ($response eq "y")
+        {
+            action("cp ${sysconfdir}/sshd_config ${sysconfdir}/${confbackupdir}/sshd_config");
+        }
     }
-    else
+
+    if ($response eq "y")
     {
         action("cp ${globusdir}/setup/globus/sshd_config ${sysconfdir}/sshd_config");
     }
+
+    #
+    # Reset response for our new query
+    #
+
+    $response = "y";
+    if ( -e "${sysconfdir}/moduli" )
+    {
+        $response = query_boolean("${sysconfdir}/moduli already exists.  Overwrite?", "n");
+        if ($response eq "y")
+        {
+            action("cp ${sysconfdir}/moduli ${sysconfdir}/${confbackupdir}/moduli");
+        }
+    }
+
+    if ($response eq "y")
+    {
+        action("cp ${globusdir}/setup/globus/moduli ${sysconfdir}/moduli");
+    }
 }
 
 sub runkeygen
 {
+    print "\nStage 2: Generating ssh host keys..\n";
+
     if ( ! -d "${sysconfdir}" )
     {
         print "Could not find ${sysconfdir} directory... creating\n";
-        mkdir($sysconfdir, mode);
+        mkdir($sysconfdir, 16877);
+        # 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";
@@ -130,6 +223,8 @@ sub runkeygen
 
 sub fixpaths
 {
+    my $g, $h;
+
     #
     # Set up path translations for the installation files
     #
@@ -148,12 +243,6 @@ 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",
         );
 
     #
@@ -161,9 +250,6 @@ sub fixpaths
     #
 
     %files = (
-        "${bindir}/scp" => 0,
-        "${bindir}/sftp" => 0,
-        "${sbindir}/sshd" => 0,
         "${sysconfdir}/ssh_config" => 1,
         "${sysconfdir}/sshd_config" => 1,
         "${sysconfdir}/moduli" => 1,
@@ -178,7 +264,8 @@ sub fixpaths
         "${mandir}/${mansubdir}1/sftp.1" => 0,
         );
 
-    print "Translating strings in config/man files...\n";
+    print "\nStage 3: Translating strings in config and man files...\n";
+
     for my $f (keys %files)
     {
         $f =~ /(.*\/)*(.*)$/;
@@ -190,6 +277,13 @@ sub fixpaths
 
         $g = "$f.tmp";
 
+        #
+        # get the filename for $f and place it in $h.
+        #
+
+        $h = $f;
+        $h =~ s#^.*/##;
+
         #
         # Grab the current mode/uid/gid for use later
         #
@@ -198,7 +292,29 @@ 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";
+        }
+
+        #
+        # Create a backup of this file if it's flagged
+        #
+
+        if ($files{$f} == 1)
+        {
+            $result = system("cp $g ${sysconfdir}/${transbackupdir}/$h 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");
@@ -215,13 +331,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";
         }
 
         #
@@ -233,9 +351,17 @@ sub fixpaths
         chown($uid, $gid, $f);
     } # for $f
 
+    print "complete.\n";
+
     return 0;
 }
 
+print "---------------------------------------------------------------\n";
+print "$myname: Configuring package 'gsi_openssh'..\n";
+print "\n";
+print "--> NOTE: Run this as root for the intended effect. <--\n";
+
+test_dirs();
 copy_setup_files();
 runkeygen();
 fixpaths();
@@ -244,4 +370,67 @@ 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 "You are required to set the following variables in your environment\n";
+print "to ensure that the gsi_ssh package works correctly:\n";
+print "\n";
+print "\$GSI_SCP_LOC = \"${bindir}/scp.real\"\n";
+print "\$GSI_SFTP_LOC = \"${bindir}/sftp.real\"\n";
+print "\$GSI_SSH_LOC = \"${bindir}/ssh\"\n";
+print "\$GSI_SSHD_LOC = \"${sbindir}/sshd.real\"\n";
+print "\$GSI_SSH_CONFIG_LOC = \"${sysconfdir}/ssh_config\"\n";
+print "\$GSI_SSHD_CONFIG_LOC = \"${sysconfdir}/sshd_config\"\n";
+print "---------------------------------------------------------------\n";
+
+#
+# Just need a minimal action() subroutine for now..
+#
+
+sub action
+{
+    my ($command) = @_;
+
+    printf "$command\n";
+
+    my $result = system("$command 2>&1");
+
+    if (($result or $?) and $command !~ m!patch!)
+    {
+        die "ERROR: Unable to execute command: $!\n";
+    }
+}
+
+sub query_boolean
+{
+    my ($query_text, $default) = @_;
+    my $nondefault, $foo, $bar;
+
+    #
+    # Set $nondefault to the boolean opposite of $default.
+    #
+
+    if ($default eq "n")
+    {
+        $nondefault = "y";
+    }
+    else
+    {
+        $nondefault = "n";
+    }
+
+    print "${query_text} ";
+    print "[$default] ";
+
+    $foo = <STDIN>;
+    ($bar) = split //, $foo;
+
+    if ($bar ne $nondefault)
+    {
+        $bar = $default;
+    }
+
+    return $bar;
+}
+
This page took 0.047175 seconds and 4 git commands to generate.