5 # Adapts the installed gsi-ssh environment to the current machine,
6 # performing actions that originally occurred during the package's
7 # 'make install' phase.
9 # Parts adapted from 'fixpath', a tool found in openssh-3.0.2p1.
11 # Send comments/fixes/suggestions to:
12 # Chase Phillips <cphillip@ncsa.uiuc.edu>
15 printf("setup-openssh.pl: Configuring gsi-openssh package\n");
18 # Get user's GPT_LOCATION since we may be installing this using a new(er)
22 $gptpath = $ENV{GPT_LOCATION};
25 # And the old standby..
28 $gpath = $ENV{GLOBUS_LOCATION};
31 die "GLOBUS_LOCATION needs to be set before running this script"
35 # i'm including this because other perl scripts in the gpt setup directories
39 if (defined($gptpath))
41 @INC = (@INC, "$gptpath/lib/perl", "$gpath/lib/perl");
45 @INC = (@INC, "$gpath/lib/perl");
48 require Grid::GPT::Setup;
50 my $globusdir = $gpath;
51 my $setupdir = "$globusdir/setup/globus";
52 my $myname = "setup-openssh.pl";
55 # Set up path prefixes for use in the path translations
58 $prefix = ${globusdir};
59 $exec_prefix = "${prefix}";
60 $bindir = "${exec_prefix}/bin";
61 $sbindir = "${exec_prefix}/sbin";
62 $mandir = "${prefix}/man";
64 $libexecdir = "${exec_prefix}/libexec";
65 $sysconfdir = "/etc/ssh";
67 $xauth_path = "/usr/bin/X11/xauth";
70 # Backup-related variables
74 $backupdir = "/etc/ssh/globus_backup_${curr_time}";
77 # Check that we are running as root
84 print "--> NOTE: You must be root to run this script! <--\n";
89 # We need to make sure it's okay to copy our setup files (if some files are already
90 # present). If we do copy any files, we backup the old files so the user can (possibly)
96 print "\nPreparatory: Checking for existence of critical directories..\n";
99 # Remember to put in check for /etc
106 if ( ! -d "$sysconfdir" )
108 print "Could not find directory: '${sysconfdir}'.. creating.\n";
109 mkdir($sysconfdir, 16877);
110 # 16877 should be 755, or drwxr-xr-x
114 # Test for /etc/ssh/globus_backup_<curr>
117 if ( ! -d "${backupdir}" )
119 print "Could not find directory: '${backupdir}'.. creating.\n";
120 mkdir($backupdir, 16877);
128 print "\nStage 1: Backing up configuration files to '${backupdir}/'..\n";
130 if ( -e "${sysconfdir}/ssh_config" )
132 action("cp ${sysconfdir}/ssh_config ${backupdir}/ssh_config");
136 print "${sysconfdir}/ssh_config does not exist.\n";
139 if ( -e "${sysconfdir}/sshd_config" )
141 action("cp ${sysconfdir}/sshd_config ${backupdir}/sshd_config");
145 print "${sysconfdir}/sshd_config does not exist.\n";
148 if ( -e "${sysconfdir}/moduli" )
150 action("cp ${sysconfdir}/moduli ${backupdir}/moduli");
154 print "${sysconfdir}/moduli does not exist.\n";
162 print "\nStage 2: Copying configuration files into '${sysconfdir}'..\n";
164 action("cp ${globusdir}/setup/globus/ssh_config ${sysconfdir}/ssh_config");
165 action("cp ${globusdir}/setup/globus/sshd_config ${sysconfdir}/sshd_config");
166 action("cp ${globusdir}/setup/globus/moduli ${sysconfdir}/moduli");
171 print "\nStage 3: Generating ssh host keys..\n";
173 if ( ! -d "${sysconfdir}" )
175 print "Could not find ${sysconfdir} directory... creating\n";
176 mkdir($sysconfdir, 16877);
177 # 16877 should be 755, or drwxr-xr-x
180 if ( -e "${sysconfdir}/ssh_host_key" )
182 print "${sysconfdir}/ssh_host_key already exists, skipping.\n";
186 # if $sysconfdir/ssh_host_key doesn't exist..
187 action("$bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N \"\"");
190 if ( -e "${sysconfdir}/ssh_host_dsa_key" )
192 print "${sysconfdir}/ssh_host_dsa_key already exists, skipping.\n";
196 # if $sysconfdir/ssh_host_dsa_key doesn't exist..
197 action("$bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N \"\"");
200 if ( -e "${sysconfdir}/ssh_host_rsa_key" )
202 print "${sysconfdir}/ssh_host_rsa_key already exists, skipping.\n";
206 # if $sysconfdir/ssh_host_rsa_key doesn't exist..
207 action("$bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N \"\"");
217 print "\nStage 4: Translating strings in config and man files..\n";
220 # Set up path translations for the installation files
224 "/etc/ssh_config" => "${sysconfdir}/ssh_config",
225 "/etc/ssh_known_hosts" => "${sysconfdir}/ssh_known_hosts",
226 "/etc/sshd_config" => "${sysconfdir}/sshd_config",
227 "/usr/libexec" => "${libexecdir}",
228 "/etc/shosts.equiv" => "${sysconfdir}/shosts.equiv",
229 "/etc/ssh_host_key" => "${sysconfdir}/ssh_host_key",
230 "/etc/ssh_host_dsa_key" => "${sysconfdir}/ssh_host_dsa_key",
231 "/etc/ssh_host_rsa_key" => "${sysconfdir}/ssh_host_rsa_key",
232 "/var/run/sshd.pid" => "${piddir}/sshd.pid",
233 "/etc/moduli" => "${sysconfdir}/moduli",
234 "/etc/sshrc" => "${sysconfdir}/sshrc",
235 "/usr/X11R6/bin/xauth" => "${xauth_path}",
236 "/usr/bin:/bin:/usr/sbin:/sbin" => "/usr/bin:/bin:/usr/sbin:/sbin:${bindir}",
240 # Files on which to perform path translations
244 "${sysconfdir}/ssh_config",
245 "${sysconfdir}/sshd_config",
246 "${sysconfdir}/moduli",
247 "${mandir}/${mansubdir}1/scp.1",
248 "${mandir}/${mansubdir}1/ssh-add.1",
249 "${mandir}/${mansubdir}1/ssh-agent.1",
250 "${mandir}/${mansubdir}1/ssh-keygen.1",
251 "${mandir}/${mansubdir}1/ssh-keyscan.1",
252 "${mandir}/${mansubdir}1/ssh.1",
253 "${mandir}/${mansubdir}8/sshd.8",
254 "${mandir}/${mansubdir}8/sftp-server.8",
255 "${mandir}/${mansubdir}1/sftp.1",
260 $f =~ /(.*\/)*(.*)$/;
263 # we really should create a random filename and make sure that it
264 # doesn't already exist (based off current time_t or something)
270 # What is $f's filename? (taken from the qualified path)
277 # Grab the current mode/uid/gid for use later
280 $mode = (stat($f))[2];
281 $uid = (stat($f))[4];
282 $gid = (stat($f))[5];
285 # Move $f into a .tmp file for the translation step
288 $result = system("mv $f $g 2>&1");
291 die "ERROR: Unable to execute command: $!\n";
294 open(IN, "<$g") || die ("$0: input file $g missing!\n");
295 open(OUT, ">$f") || die ("$0: unable to open output file $f!\n");
310 # Remove the old .tmp file
313 $result = system("rm $g 2>&1");
317 die "ERROR: Unable to execute command: $!\n";
321 # An attempt to revert the new file back to the original file's
326 chown($uid, $gid, $f);
334 print "---------------------------------------------------------------\n";
335 print "Hi, I'm the setup script for the gsi_openssh package! There\n";
336 print "are some last minute details that I've got to set straight\n";
337 print "in the config and man files, along with generating the ssh keys\n";
338 print "for this machine (if it doesn't already have them).\n";
340 print "I like to install my config-related files in:\n";
341 print " ${sysconfdir}/\n";
343 print "These files may overwrite your previously existing configuration\n";
344 print "files. If you choose to continue, you will find a backup of\n";
345 print "those original files in:\n";
346 print " ${backupdir}/\n";
348 print "Your host keys will remain untouched if they are already present.\n";
349 print "If they aren't present, this script will generate them for you.\n";
352 $response = query_boolean("Do you wish to continue with the setup package?","y");
354 if ($response eq "n")
357 print "Okay.. exiting gsi_openssh setup.\n";
368 my $metadata = new Grid::GPT::Setup(package_name => "gsi_openssh_setup");
373 print "$myname: Finished configuring package 'gsi_openssh'.\n";
375 print "I see that you have your GLOBUS_LOCATION environmental variable\n";
379 print "Remember to keep this variable set (correctly) when you want\n";
380 print "to use the executables that came with this package.\n";
382 print "Additionally, you may need to set LD_LIBRARY_PATH to point to\n";
383 print "the location in which your globus libraries reside. For example:\n";
385 print " export LD_LIBRARY_PATH=\"$gpath/lib\"\n";
387 print "---------------------------------------------------------------\n";
390 # Just need a minimal action() subroutine for now..
399 my $result = system("$command 2>&1");
401 if (($result or $?) and $command !~ m!patch!)
403 die "ERROR: Unable to execute command: $!\n";
409 my ($query_text, $default) = @_;
410 my $nondefault, $foo, $bar;
413 # Set $nondefault to the boolean opposite of $default.
425 print "${query_text} ";
429 ($bar) = split //, $foo;
431 if ( grep(/\s/, $bar) )
433 # this is debatable. all whitespace means 'default'
437 elsif ($bar ne $default)
439 # everything else means 'nondefault'.
445 # extraneous step. to get here, $bar should be eq to $default anyway.