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 # Large 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>
13 $gpath = $ENV{GLOBUS_LOCATION};
16 die "GLOBUS_LOCATION needs to be set before running this script"
20 # i'm including this because other perl scripts in the gpt setup directories
24 @INC = (@INC, "$gpath/lib/perl");
26 require Grid::GPT::Setup;
28 my $globusdir = $gpath;
29 my $setupdir = "$globusdir/setup/globus";
30 my $myname = "setup-openssh.pl";
33 # Set up path prefixes for use in the path translations
36 $prefix = ${globusdir};
37 $exec_prefix = "${prefix}";
38 $bindir = "${exec_prefix}/bin";
39 $sbindir = "${exec_prefix}/sbin";
40 $mandir = "${prefix}/man";
42 $libexecdir = "${exec_prefix}/libexec";
43 $sysconfdir = "/etc/ssh";
45 $xauth_path = "/usr/bin/X11/xauth";
48 # Backup-related variables
52 $backupdir = "/etc/ssh/globus_backup_${curr_time}";
55 # Check that we are running as root
62 print "--> NOTE: You must be root to run this script! <--\n";
67 # We need to make sure it's okay to copy our setup files (if some files are already
68 # present). If we do copy any files, we backup the old files so the user can (possibly)
74 print "\nPreparatory: Checking for existence of critical directories..\n";
77 # Remember to put in check for /etc
84 if ( ! -d "$sysconfdir" )
86 print "Could not find directory: '${sysconfdir}'.. creating.\n";
87 mkdir($sysconfdir, 16877);
88 # 16877 should be 755, or drwxr-xr-x
92 # Test for /etc/ssh/globus_backup_<curr>
95 if ( ! -d "${backupdir}" )
97 print "Could not find directory: '${backupdir}'.. creating.\n";
98 mkdir($backupdir, 16877);
106 print "\nStage 1: Backing up configuration files to '${backupdir}/'..\n";
108 if ( -e "${sysconfdir}/ssh_config" )
110 action("cp ${sysconfdir}/ssh_config ${backupdir}/ssh_config");
114 print "${sysconfdir}/ssh_config does not exist.\n";
117 if ( -e "${sysconfdir}/sshd_config" )
119 action("cp ${sysconfdir}/sshd_config ${backupdir}/sshd_config");
123 print "${sysconfdir}/sshd_config does not exist.\n";
126 if ( -e "${sysconfdir}/moduli" )
128 action("cp ${sysconfdir}/moduli ${backupdir}/moduli");
132 print "${sysconfdir}/moduli does not exist.\n";
140 print "\nStage 2: Copying configuration files into '${sysconfdir}'..\n";
142 action("cp ${globusdir}/setup/globus/ssh_config ${sysconfdir}/ssh_config");
143 action("cp ${globusdir}/setup/globus/sshd_config ${sysconfdir}/sshd_config");
144 action("cp ${globusdir}/setup/globus/moduli ${sysconfdir}/moduli");
149 print "\nStage 3: Generating ssh host keys..\n";
151 if ( ! -d "${sysconfdir}" )
153 print "Could not find ${sysconfdir} directory... creating\n";
154 mkdir($sysconfdir, 16877);
155 # 16877 should be 755, or drwxr-xr-x
158 if ( -e "${sysconfdir}/ssh_host_key" )
160 print "${sysconfdir}/ssh_host_key already exists, skipping.\n";
164 # if $sysconfdir/ssh_host_key doesn't exist..
165 action("$bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N \"\"");
168 if ( -e "${sysconfdir}/ssh_host_dsa_key" )
170 print "${sysconfdir}/ssh_host_dsa_key already exists, skipping.\n";
174 # if $sysconfdir/ssh_host_dsa_key doesn't exist..
175 action("$bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N \"\"");
178 if ( -e "${sysconfdir}/ssh_host_rsa_key" )
180 print "${sysconfdir}/ssh_host_rsa_key already exists, skipping.\n";
184 # if $sysconfdir/ssh_host_rsa_key doesn't exist..
185 action("$bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N \"\"");
195 print "\nStage 4: Translating strings in config and man files..\n";
198 # Set up path translations for the installation files
202 "/etc/ssh_config" => "${sysconfdir}/ssh_config",
203 "/etc/ssh_known_hosts" => "${sysconfdir}/ssh_known_hosts",
204 "/etc/sshd_config" => "${sysconfdir}/sshd_config",
205 "/usr/libexec" => "${libexecdir}",
206 "/etc/shosts.equiv" => "${sysconfdir}/shosts.equiv",
207 "/etc/ssh_host_key" => "${sysconfdir}/ssh_host_key",
208 "/etc/ssh_host_dsa_key" => "${sysconfdir}/ssh_host_dsa_key",
209 "/etc/ssh_host_rsa_key" => "${sysconfdir}/ssh_host_rsa_key",
210 "/var/run/sshd.pid" => "${piddir}/sshd.pid",
211 "/etc/moduli" => "${sysconfdir}/moduli",
212 "/etc/sshrc" => "${sysconfdir}/sshrc",
213 "/usr/X11R6/bin/xauth" => "${xauth_path}",
214 "/usr/bin:/bin:/usr/sbin:/sbin" => "/usr/bin:/bin:/usr/sbin:/sbin:${bindir}",
218 # Files on which to perform path translations
222 "${sysconfdir}/ssh_config",
223 "${sysconfdir}/sshd_config",
224 "${sysconfdir}/moduli",
225 "${mandir}/${mansubdir}1/scp.1",
226 "${mandir}/${mansubdir}1/ssh-add.1",
227 "${mandir}/${mansubdir}1/ssh-agent.1",
228 "${mandir}/${mansubdir}1/ssh-keygen.1",
229 "${mandir}/${mansubdir}1/ssh-keyscan.1",
230 "${mandir}/${mansubdir}1/ssh.1",
231 "${mandir}/${mansubdir}8/sshd.8",
232 "${mandir}/${mansubdir}8/sftp-server.8",
233 "${mandir}/${mansubdir}1/sftp.1",
238 $f =~ /(.*\/)*(.*)$/;
241 # we really should create a random filename and make sure that it
242 # doesn't already exist (based off current time_t or something)
248 # Grab the current mode/uid/gid for use later
251 $mode = (stat($f))[2];
252 $uid = (stat($f))[4];
253 $gid = (stat($f))[5];
256 # Move $f into a .tmp file for the translation step
259 $result = system("mv $f $g 2>&1");
262 die "ERROR: Unable to execute command: $!\n";
265 open(IN, "<$g") || die ("$0: input file $g missing!\n");
266 open(OUT, ">$f") || die ("$0: unable to open output file $f!\n");
281 # Remove the old .tmp file
284 $result = system("rm $g 2>&1");
288 die "ERROR: Unable to execute command: $!\n";
292 # An attempt to revert the new file back to the original file's
297 chown($uid, $gid, $f);
303 print "---------------------------------------------------------------\n";
304 print "$myname: Configuring package gsi_openssh..\n";
306 print "Hi, I'm the setup script for the gsi_openssh package! There\n";
307 print "are some last minute details that I've got to set straight\n";
308 print "in the config and man files, along with generating the ssh keys\n";
309 print "for this machine (if it doesn't already have them).\n";
311 print "I like to install my config-related files in:\n";
312 print " ${sysconfdir}\n";
313 print "and, if you choose to continue, you will find a backup of the\n";
314 print "original files in:\n";
315 print " ${backupdir}/\n";
317 print "Your host keys will remain untouched if they are already present.\n";
318 print "If they aren't present, this script will generate them for you.\n";
321 $response = query_boolean("Do you wish to continue with the setup package?","y");
323 if ($response eq "n")
326 print "Okay.. exiting gsi_openssh setup.\n";
337 my $metadata = new Grid::GPT::Setup(package_name => "gsi_openssh_setup");
342 print "$myname: Finished configuring package 'gsi_openssh'.\n";
344 print "I see that you have your GLOBUS_LOCATION environmental variable\n";
348 print "Remember to keep this variable set (correctly) when you want\n";
349 print "to use the executables that came with this package.\n";
350 print "---------------------------------------------------------------\n";
353 # Just need a minimal action() subroutine for now..
362 my $result = system("$command 2>&1");
364 if (($result or $?) and $command !~ m!patch!)
366 die "ERROR: Unable to execute command: $!\n";
372 my ($query_text, $default) = @_;
373 my $nondefault, $foo, $bar;
376 # Set $nondefault to the boolean opposite of $default.
388 print "${query_text} ";
392 ($bar) = split //, $foo;
394 if ($bar ne $nondefault)