X-Git-Url: http://andersk.mit.edu/gitweb/gssapi-openssh.git/blobdiff_plain/79d118e567fa96179efb174d7e516a5ff31a7f21..refs/heads/OPENSSH_4_3P2_HPN:/setup/setup-openssh.pl diff --git a/setup/setup-openssh.pl b/setup/setup-openssh.pl index 8c31cd1..bf506c8 100644 --- a/setup/setup-openssh.pl +++ b/setup/setup-openssh.pl @@ -4,12 +4,23 @@ # performing actions that originally occurred during the package's # 'make install' phase. # -# Large parts adapted from 'fixpath', a tool found in openssh-3.0.2p1. +# Parts adapted from 'fixpath', a tool found in openssh-3.0.2p1. # # Send comments/fixes/suggestions to: # Chase Phillips # +# +# 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 +32,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; @@ -49,9 +67,19 @@ $xauth_path = "/usr/bin/X11/xauth"; # $curr_time = time(); -$backupdir = "globus_backup_${curr_time}"; -$confbackupdir = "$backupdir/s1_conf"; -$transbackupdir = "$backupdir/s3_trans"; +$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 @@ -61,9 +89,7 @@ $transbackupdir = "$backupdir/s3_trans"; sub test_dirs { - my $composite; - - print "\nPreparatory: checking for existence of critical directories\n"; + print "\nPreparatory: Checking for existence of critical directories..\n"; # # Remember to put in check for /etc @@ -73,11 +99,10 @@ sub test_dirs # Test for /etc/ssh # - $composite = $sysconfdir; - if ( ! -d "$composite" ) + if ( ! -d "$sysconfdir" ) { - print "Could not find directory: '${composite}'.. creating.\n"; - mkdir($composite, 16877); + print "Could not find directory: '${sysconfdir}'.. creating.\n"; + mkdir($sysconfdir, 16877); # 16877 should be 755, or drwxr-xr-x } @@ -85,101 +110,61 @@ sub test_dirs # Test for /etc/ssh/globus_backup_ # - $composite = "$sysconfdir/$backupdir"; - if ( ! -d "${composite}" ) - { - print "Could not find directory: '${composite}'.. creating.\n"; - mkdir($composite, 16877); - } - - # - # Test for /etc/ssh/globus_backup_/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_/s2_trans - # - - $composite = "$sysconfdir/$transbackupdir"; - if ( ! -d "${composite}" ) + if ( ! -d "${backupdir}" ) { - print "Could not find directory: '${composite}'.. creating.\n"; - mkdir($composite, 16877); + print "Could not find directory: '${backupdir}'.. creating.\n"; + mkdir($backupdir, 16877); } return 0; } -sub copy_setup_files +sub backup_files { - my $response; - - print "\nStage 1: Copying configuration files into '${sysconfdir}'..\n"; + print "\nStage 1: Backing up configuration files to '${backupdir}/'..\n"; - $response = "y"; if ( -e "${sysconfdir}/ssh_config" ) { - $response = query_boolean("${sysconfdir}/ssh_config already exists. Overwrite?", "n"); - if ($response eq "y") - { - action("cp ${sysconfdir}/ssh_config ${sysconfdir}/${confbackupdir}/ssh_config"); - } + action("cp ${sysconfdir}/ssh_config ${backupdir}/ssh_config"); } - - if ($response eq "y") + else { - action("cp ${globusdir}/setup/globus/ssh_config ${sysconfdir}/ssh_config"); + print "${sysconfdir}/ssh_config does not exist.\n"; } - # - # Reset response for our new query - # - - $response = "y"; if ( -e "${sysconfdir}/sshd_config" ) { - $response = query_boolean("${sysconfdir}/sshd_config already exists. Overwrite?", "n"); - if ($response eq "y") - { - action("cp ${sysconfdir}/sshd_config ${sysconfdir}/${confbackupdir}/sshd_config"); - } + action("cp ${sysconfdir}/sshd_config ${backupdir}/sshd_config"); } - - if ($response eq "y") + else { - action("cp ${globusdir}/setup/globus/sshd_config ${sysconfdir}/sshd_config"); + print "${sysconfdir}/sshd_config does not exist.\n"; } - # - # 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"); - } + action("cp ${sysconfdir}/moduli ${backupdir}/moduli"); } - - if ($response eq "y") + else { - 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 2: Generating ssh host keys..\n"; + print "\nStage 3: Generating ssh host keys..\n"; if ( ! -d "${sysconfdir}" ) { @@ -225,6 +210,8 @@ sub fixpaths { my $g, $h; + print "\nStage 4: Translating strings in config and man files..\n"; + # # Set up path translations for the installation files # @@ -249,24 +236,22 @@ sub fixpaths # Files on which to perform path translations # - %files = ( - "${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 "\nStage 3: Translating strings in config and man files...\n"; - - for my $f (keys %files) + for my $f (@files) { $f =~ /(.*\/)*(.*)$/; @@ -278,7 +263,7 @@ sub fixpaths $g = "$f.tmp"; # - # get the filename for $f and place it in $h. + # What is $f's filename? (taken from the qualified path) # $h = $f; @@ -302,20 +287,6 @@ sub fixpaths 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"); @@ -349,19 +320,45 @@ sub fixpaths chmod($mode, $f); chown($uid, $gid, $f); - } # for $f - print "complete.\n"; + print "$h\n"; + } # for $f return 0; } print "---------------------------------------------------------------\n"; -print "$myname: Configuring package 'gsi_openssh'..\n"; +print "$myname: Configuring package gsi_openssh..\n"; +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 "--> NOTE: Run this as root for the intended effect. <--\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(); @@ -373,15 +370,12 @@ $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 "I see that you have your GLOBUS_LOCATION environmental variable\n"; +print "set to:\n"; +print " $gpath\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 "Remember to keep this variable set (correctly) when you want\n"; +print "to use the executables that came with this package.\n"; print "---------------------------------------------------------------\n"; # @@ -426,11 +420,24 @@ sub query_boolean $foo = ; ($bar) = split //, $foo; - if ($bar ne $nondefault) + if ( grep(/\s/, $bar) ) { + # this is debatable. all whitespace means 'default' + + $bar = $default; + } + elsif ($bar ne $default) + { + # everything else means 'nondefault'. + + $bar = $nondefault; + } + else + { + # extraneous step. to get here, $bar should be eq to $default anyway. + $bar = $default; } return $bar; } -