3 # Adapts the installed gsi-ssh environment to the current machine,
4 # performing actions that originally occurred during the package's
5 # 'make install' phase.
7 # Parts adapted from 'fixpath', a tool found in openssh-3.0.2p1.
9 # Send comments/fixes/suggestions to:
10 # Chase Phillips <cphillip@ncsa.uiuc.edu>
14 # Get user's GPT_LOCATION since we may be installing this using a new(er)
18 $gptpath = $ENV{GPT_LOCATION};
21 # And the old standby..
24 $gpath = $ENV{GLOBUS_LOCATION};
27 die "GLOBUS_LOCATION needs to be set before running this script"
31 # i'm including this because other perl scripts in the gpt setup directories
35 if (defined($gptpath))
37 @INC = (@INC, "$gptpath/lib/perl", "$gpath/lib/perl");
41 @INC = (@INC, "$gpath/lib/perl");
44 require Grid::GPT::Setup;
46 my $globusdir = $gpath;
47 my $setupdir = "$globusdir/setup/globus";
48 my $myname = "setup-openssh.pl";
51 # Set up path prefixes for use in the path translations
54 $prefix = ${globusdir};
55 $exec_prefix = "${prefix}";
56 $bindir = "${exec_prefix}/bin";
57 $sbindir = "${exec_prefix}/sbin";
58 $mandir = "${prefix}/man";
60 $libexecdir = "${exec_prefix}/libexec";
61 $sysconfdir = "/etc/ssh";
63 $xauth_path = "/usr/bin/X11/xauth";
66 # Backup-related variables
70 $backupdir = "/etc/ssh/globus_backup_${curr_time}";
73 # Check that we are running as root
80 print "--> NOTE: You must be root to run this script! <--\n";
85 # We need to make sure it's okay to copy our setup files (if some files are already
86 # present). If we do copy any files, we backup the old files so the user can (possibly)
92 print "\nPreparatory: Checking for existence of critical directories..\n";
95 # Remember to put in check for /etc
102 if ( ! -d "$sysconfdir" )
104 print "Could not find directory: '${sysconfdir}'.. creating.\n";
105 mkdir($sysconfdir, 16877);
106 # 16877 should be 755, or drwxr-xr-x
110 # Test for /etc/ssh/globus_backup_<curr>
113 if ( ! -d "${backupdir}" )
115 print "Could not find directory: '${backupdir}'.. creating.\n";
116 mkdir($backupdir, 16877);
124 print "\nStage 1: Backing up configuration files to '${backupdir}/'..\n";
126 if ( -e "${sysconfdir}/ssh_config" )
128 action("cp ${sysconfdir}/ssh_config ${backupdir}/ssh_config");
132 print "${sysconfdir}/ssh_config does not exist.\n";
135 if ( -e "${sysconfdir}/sshd_config" )
137 action("cp ${sysconfdir}/sshd_config ${backupdir}/sshd_config");
141 print "${sysconfdir}/sshd_config does not exist.\n";
144 if ( -e "${sysconfdir}/moduli" )
146 action("cp ${sysconfdir}/moduli ${backupdir}/moduli");
150 print "${sysconfdir}/moduli does not exist.\n";
158 print "\nStage 2: Copying configuration files into '${sysconfdir}'..\n";
160 action("cp ${globusdir}/setup/globus/ssh_config ${sysconfdir}/ssh_config");
161 action("cp ${globusdir}/setup/globus/sshd_config ${sysconfdir}/sshd_config");
162 action("cp ${globusdir}/setup/globus/moduli ${sysconfdir}/moduli");
167 print "\nStage 3: Generating ssh host keys..\n";
169 if ( ! -d "${sysconfdir}" )
171 print "Could not find ${sysconfdir} directory... creating\n";
172 mkdir($sysconfdir, 16877);
173 # 16877 should be 755, or drwxr-xr-x
176 if ( -e "${sysconfdir}/ssh_host_key" )
178 print "${sysconfdir}/ssh_host_key already exists, skipping.\n";
182 # if $sysconfdir/ssh_host_key doesn't exist..
183 action("$bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N \"\"");
186 if ( -e "${sysconfdir}/ssh_host_dsa_key" )
188 print "${sysconfdir}/ssh_host_dsa_key already exists, skipping.\n";
192 # if $sysconfdir/ssh_host_dsa_key doesn't exist..
193 action("$bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N \"\"");
196 if ( -e "${sysconfdir}/ssh_host_rsa_key" )
198 print "${sysconfdir}/ssh_host_rsa_key already exists, skipping.\n";
202 # if $sysconfdir/ssh_host_rsa_key doesn't exist..
203 action("$bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N \"\"");
213 print "\nStage 4: Translating strings in config and man files..\n";
216 # Set up path translations for the installation files
220 "/etc/ssh_config" => "${sysconfdir}/ssh_config",
221 "/etc/ssh_known_hosts" => "${sysconfdir}/ssh_known_hosts",
222 "/etc/sshd_config" => "${sysconfdir}/sshd_config",
223 "/usr/libexec" => "${libexecdir}",
224 "/etc/shosts.equiv" => "${sysconfdir}/shosts.equiv",
225 "/etc/ssh_host_key" => "${sysconfdir}/ssh_host_key",
226 "/etc/ssh_host_dsa_key" => "${sysconfdir}/ssh_host_dsa_key",
227 "/etc/ssh_host_rsa_key" => "${sysconfdir}/ssh_host_rsa_key",
228 "/var/run/sshd.pid" => "${piddir}/sshd.pid",
229 "/etc/moduli" => "${sysconfdir}/moduli",
230 "/etc/sshrc" => "${sysconfdir}/sshrc",
231 "/usr/X11R6/bin/xauth" => "${xauth_path}",
232 "/usr/bin:/bin:/usr/sbin:/sbin" => "/usr/bin:/bin:/usr/sbin:/sbin:${bindir}",
236 # Files on which to perform path translations
240 "${sysconfdir}/ssh_config",
241 "${sysconfdir}/sshd_config",
242 "${sysconfdir}/moduli",
243 "${mandir}/${mansubdir}1/scp.1",
244 "${mandir}/${mansubdir}1/ssh-add.1",
245 "${mandir}/${mansubdir}1/ssh-agent.1",
246 "${mandir}/${mansubdir}1/ssh-keygen.1",
247 "${mandir}/${mansubdir}1/ssh-keyscan.1",
248 "${mandir}/${mansubdir}1/ssh.1",
249 "${mandir}/${mansubdir}8/sshd.8",
250 "${mandir}/${mansubdir}8/sftp-server.8",
251 "${mandir}/${mansubdir}1/sftp.1",
256 $f =~ /(.*\/)*(.*)$/;
259 # we really should create a random filename and make sure that it
260 # doesn't already exist (based off current time_t or something)
266 # What is $f's filename? (taken from the qualified path)
273 # Grab the current mode/uid/gid for use later
276 $mode = (stat($f))[2];
277 $uid = (stat($f))[4];
278 $gid = (stat($f))[5];
281 # Move $f into a .tmp file for the translation step
284 $result = system("mv $f $g 2>&1");
287 die "ERROR: Unable to execute command: $!\n";
290 open(IN, "<$g") || die ("$0: input file $g missing!\n");
291 open(OUT, ">$f") || die ("$0: unable to open output file $f!\n");
306 # Remove the old .tmp file
309 $result = system("rm $g 2>&1");
313 die "ERROR: Unable to execute command: $!\n";
317 # An attempt to revert the new file back to the original file's
322 chown($uid, $gid, $f);
330 print "---------------------------------------------------------------\n";
331 print "$myname: Configuring package gsi_openssh..\n";
333 print "Hi, I'm the setup script for the gsi_openssh package! There\n";
334 print "are some last minute details that I've got to set straight\n";
335 print "in the config and man files, along with generating the ssh keys\n";
336 print "for this machine (if it doesn't already have them).\n";
338 print "I like to install my config-related files in:\n";
339 print " ${sysconfdir}/\n";
341 print "These files may overwrite your previously existing configuration\n";
342 print "files. If you choose to continue, you will find a backup of\n";
343 print "those original files in:\n";
344 print " ${backupdir}/\n";
346 print "Your host keys will remain untouched if they are already present.\n";
347 print "If they aren't present, this script will generate them for you.\n";
350 $response = query_boolean("Do you wish to continue with the setup package?","y");
352 if ($response eq "n")
355 print "Okay.. exiting gsi_openssh setup.\n";
366 my $metadata = new Grid::GPT::Setup(package_name => "gsi_openssh_setup");
371 print "$myname: Finished configuring package 'gsi_openssh'.\n";
373 print "I see that you have your GLOBUS_LOCATION environmental variable\n";
377 print "Remember to keep this variable set (correctly) when you want\n";
378 print "to use the executables that came with this package.\n";
379 print "---------------------------------------------------------------\n";
382 # Just need a minimal action() subroutine for now..
391 my $result = system("$command 2>&1");
393 if (($result or $?) and $command !~ m!patch!)
395 die "ERROR: Unable to execute command: $!\n";
401 my ($query_text, $default) = @_;
402 my $nondefault, $foo, $bar;
405 # Set $nondefault to the boolean opposite of $default.
417 print "${query_text} ";
421 ($bar) = split //, $foo;
423 if ( grep(/\s/, $bar) )
425 # this is debatable. all whitespace means 'default'
429 elsif ($bar ne $default)
431 # everything else means 'nondefault'.
437 # extraneous step. to get here, $bar should be eq to $default anyway.