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";
32 print "$myname: Configuring package 'gsi_openssh'...\n";
33 print "Run this as root for the intended effect...\n";
36 # Set up path prefixes for use in the path translations
39 $prefix = ${globusdir};
40 $exec_prefix = "${prefix}";
41 $bindir = "${exec_prefix}/bin";
42 $sbindir = "${exec_prefix}/sbin";
43 $mandir = "${prefix}/man";
45 $libexecdir = "${exec_prefix}/libexec";
46 $sysconfdir = "/etc/ssh";
48 $xauth_path = "/usr/bin/X11/xauth";
51 # We need to make sure it's okay to copy our setup files (if some files are already
52 # present). If we do copy any files, we backup the old files so the user can (possibly)
58 my $response, $curr_time;
63 if ( -e "${sysconfdir}/ssh_config" )
65 $response = query_boolean("${sysconfdir}/ssh_config already exists. Overwrite? ", "n");
70 action("cp ${sysconfdir}/ssh_config ${sysconfdir}/ssh_config.bak_${curr_time}");
71 action("cp ${globusdir}/setup/globus/ssh_config ${sysconfdir}/ssh_config");
75 # Reset response for our new query
79 if ( -e "${sysconfdir}/sshd_config" )
81 $response = query_boolean("${sysconfdir}/sshd_config already exists. Overwrite? ", "n");
86 action("cp ${sysconfdir}/sshd_config ${sysconfdir}/sshd_config.bak_${curr_time}");
87 action("cp ${globusdir}/setup/globus/sshd_config ${sysconfdir}/sshd_config");
91 # Reset response for our new query
95 if ( -e "${sysconfdir}/moduli" )
97 $response = query_boolean("${sysconfdir}/moduli already exists. Overwrite? ", "n");
100 if ($response eq "y")
102 action("cp ${sysconfdir}/moduli ${sysconfdir}/moduli.bak_${curr_time}");
103 action("cp ${globusdir}/setup/globus/moduli ${sysconfdir}/moduli");
109 if ( ! -d "${sysconfdir}" )
111 print "Could not find ${sysconfdir} directory... creating\n";
112 mkdir($sysconfdir, 16877);
113 # 16877 should be 755, or drwxr-xr-x
116 print "Generating ssh keys (if necessary)...\n";
117 if ( -e "${sysconfdir}/ssh_host_key" )
119 print "${sysconfdir}/ssh_host_key already exists, skipping.\n";
123 # if $sysconfdir/ssh_host_key doesn't exist..
124 action("$bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N \"\"");
127 if ( -e "${sysconfdir}/ssh_host_dsa_key" )
129 print "${sysconfdir}/ssh_host_dsa_key already exists, skipping.\n";
133 # if $sysconfdir/ssh_host_dsa_key doesn't exist..
134 action("$bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N \"\"");
137 if ( -e "${sysconfdir}/ssh_host_rsa_key" )
139 print "${sysconfdir}/ssh_host_rsa_key already exists, skipping.\n";
143 # if $sysconfdir/ssh_host_rsa_key doesn't exist..
144 action("$bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N \"\"");
153 # Set up path translations for the installation files
157 "/etc/ssh_config" => "${sysconfdir}/ssh_config",
158 "/etc/ssh_known_hosts" => "${sysconfdir}/ssh_known_hosts",
159 "/etc/sshd_config" => "${sysconfdir}/sshd_config",
160 "/usr/libexec" => "${libexecdir}",
161 "/etc/shosts.equiv" => "${sysconfdir}/shosts.equiv",
162 "/etc/ssh_host_key" => "${sysconfdir}/ssh_host_key",
163 "/etc/ssh_host_dsa_key" => "${sysconfdir}/ssh_host_dsa_key",
164 "/etc/ssh_host_rsa_key" => "${sysconfdir}/ssh_host_rsa_key",
165 "/var/run/sshd.pid" => "${piddir}/sshd.pid",
166 "/etc/moduli" => "${sysconfdir}/moduli",
167 "/etc/sshrc" => "${sysconfdir}/sshrc",
168 "/usr/X11R6/bin/xauth" => "${xauth_path}",
169 "/usr/bin:/bin:/usr/sbin:/sbin" => "/usr/bin:/bin:/usr/sbin:/sbin:${bindir}",
170 "(/path/to/scp.real)" => "${bindir}/scp.real",
171 "(/path/to/ssh)" => "${bindir}/ssh",
172 "(/path/to/sftp.real)" => "${bindir}/sftp.real",
173 "(/path/to/sshd.real)" => "${sbindir}/sshd.real",
174 "(/path/to/ssh_config)" => "${sysconfdir}/ssh_config",
175 "(/path/to/sshd_config)" => "${sysconfdir}/sshd_config",
179 # Files on which to perform path translations
183 "${bindir}/scp" => 0,
184 "${bindir}/sftp" => 0,
185 "${sbindir}/sshd" => 0,
186 "${sysconfdir}/ssh_config" => 1,
187 "${sysconfdir}/sshd_config" => 1,
188 "${sysconfdir}/moduli" => 1,
189 "${mandir}/${mansubdir}1/scp.1" => 0,
190 "${mandir}/${mansubdir}1/ssh-add.1" => 0,
191 "${mandir}/${mansubdir}1/ssh-agent.1" => 0,
192 "${mandir}/${mansubdir}1/ssh-keygen.1" => 0,
193 "${mandir}/${mansubdir}1/ssh-keyscan.1" => 0,
194 "${mandir}/${mansubdir}1/ssh.1" => 0,
195 "${mandir}/${mansubdir}8/sshd.8" => 0,
196 "${mandir}/${mansubdir}8/sftp-server.8" => 0,
197 "${mandir}/${mansubdir}1/sftp.1" => 0,
200 print "Translating strings in config/man files...\n";
201 for my $f (keys %files)
203 $f =~ /(.*\/)*(.*)$/;
206 # we really should create a random filename and make sure that it
207 # doesn't already exist (based off current time_t or something)
213 # Grab the current mode/uid/gid for use later
216 $mode = (stat($f))[2];
217 $uid = (stat($f))[4];
218 $gid = (stat($f))[5];
222 open(IN, "<$g") || die ("$0: input file $g missing!\n");
223 open(OUT, ">$f") || die ("$0: unable to open output file $f!\n");
243 print "Left backup config file '$g'\n";
247 # An attempt to revert the new file back to the original file's
252 chown($uid, $gid, $f);
262 my $metadata = new Grid::GPT::Setup(package_name => "gsi_openssh_setup");
266 print "$myname: Finished configuring package 'gsi_openssh'.\n";
269 # Just need a minimal action() subroutine for now..
278 my $result = system("$command 2>&1");
280 if (($result or $?) and $command !~ m!patch!)
282 die "ERROR: Unable to execute command: $!\n";
288 my ($query_text, $default) = @_;
289 my $nondefault, $foo, $bar;
292 # Set $nondefault to the boolean opposite of $default.
304 print "${query_text} ";
310 if ($foo ne $nondefault)