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 # Just need a minimal action() subroutine for now..
60 my $result = system("$command 2>&1");
62 if (($result or $?) and $command !~ m!patch!)
64 die "ERROR: Unable to execute command: $!\n";
70 if ( -e "${sysconfdir}/ssh_config" )
72 print "${sysconfdir}/ssh_config already exists, skipping.\n";
76 action("cp ${globusdir}/setup/globus/ssh_config ${sysconfdir}/ssh_config");
79 if ( -e "${sysconfdir}/sshd_config" )
81 print "${sysconfdir}/sshd_config already exists, skipping.\n";
85 action("cp ${globusdir}/setup/globus/sshd_config ${sysconfdir}/sshd_config");
91 if ( ! -d "${sysconfdir}" )
93 print "Could not find ${sysconfdir} directory... creating\n";
94 mkdir($sysconfdir, mode);
97 print "Generating ssh keys (if necessary)...\n";
98 if ( -e "${sysconfdir}/ssh_host_key" )
100 print "${sysconfdir}/ssh_host_key already exists, skipping.\n";
104 # if $sysconfdir/ssh_host_key doesn't exist..
105 action("$bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N \"\"");
108 if ( -e "${sysconfdir}/ssh_host_dsa_key" )
110 print "${sysconfdir}/ssh_host_dsa_key already exists, skipping.\n";
114 # if $sysconfdir/ssh_host_dsa_key doesn't exist..
115 action("$bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N \"\"");
118 if ( -e "${sysconfdir}/ssh_host_rsa_key" )
120 print "${sysconfdir}/ssh_host_rsa_key already exists, skipping.\n";
124 # if $sysconfdir/ssh_host_rsa_key doesn't exist..
125 action("$bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N \"\"");
134 # Set up path translations for the installation files
138 "/etc/ssh_config" => "${sysconfdir}/ssh_config",
139 "/etc/ssh_known_hosts" => "${sysconfdir}/ssh_known_hosts",
140 "/etc/sshd_config" => "${sysconfdir}/sshd_config",
141 "/usr/libexec" => "${libexecdir}",
142 "/etc/shosts.equiv" => "${sysconfdir}/shosts.equiv",
143 "/etc/ssh_host_key" => "${sysconfdir}/ssh_host_key",
144 "/etc/ssh_host_dsa_key" => "${sysconfdir}/ssh_host_dsa_key",
145 "/etc/ssh_host_rsa_key" => "${sysconfdir}/ssh_host_rsa_key",
146 "/var/run/sshd.pid" => "${piddir}/sshd.pid",
147 "/etc/moduli" => "${sysconfdir}/moduli",
148 "/etc/sshrc" => "${sysconfdir}/sshrc",
149 "/usr/X11R6/bin/xauth" => "${xauth_path}",
150 "/usr/bin:/bin:/usr/sbin:/sbin" => "/usr/bin:/bin:/usr/sbin:/sbin:${bindir}",
151 "(/path/to/scp.real)" => "${bindir}/scp.real",
152 "(/path/to/ssh)" => "${bindir}/ssh",
153 "(/path/to/sftp.real)" => "${bindir}/sftp.real",
154 "(/path/to/sshd.real)" => "${sbindir}/sshd.real",
155 "(/path/to/ssh_config)" => "${sysconfdir}/ssh_config",
156 "(/path/to/sshd_config)" => "${sysconfdir}/sshd_config",
160 # Files on which to perform path translations
164 "${bindir}/scp" => 0,
165 "${bindir}/sftp" => 0,
166 "${sbindir}/sshd" => 0,
167 "${sysconfdir}/ssh_config" => 1,
168 "${sysconfdir}/sshd_config" => 1,
169 "${sysconfdir}/moduli" => 1,
170 "${mandir}/${mansubdir}1/scp.1" => 0,
171 "${mandir}/${mansubdir}1/ssh-add.1" => 0,
172 "${mandir}/${mansubdir}1/ssh-agent.1" => 0,
173 "${mandir}/${mansubdir}1/ssh-keygen.1" => 0,
174 "${mandir}/${mansubdir}1/ssh-keyscan.1" => 0,
175 "${mandir}/${mansubdir}1/ssh.1" => 0,
176 "${mandir}/${mansubdir}8/sshd.8" => 0,
177 "${mandir}/${mansubdir}8/sftp-server.8" => 0,
178 "${mandir}/${mansubdir}1/sftp.1" => 0,
181 print "Translating strings in config/man files...\n";
182 for my $f (keys %files)
184 $f =~ /(.*\/)*(.*)$/;
187 # we really should create a random filename and make sure that it
188 # doesn't already exist (based off current time_t or something)
194 # Grab the current mode/uid/gid for use later
197 $mode = (stat($f))[2];
198 $uid = (stat($f))[4];
199 $gid = (stat($f))[5];
203 open(IN, "<$g") || die ("$0: input file $g missing!\n");
204 open(OUT, ">$f") || die ("$0: unable to open output file $f!\n");
224 print "Left backup config file '$g'\n";
228 # An attempt to revert the new file back to the original file's
233 chown($uid, $gid, $f);
243 my $metadata = new Grid::GPT::Setup(package_name => "gsi_openssh_setup");
247 print "$myname: Finished configuring package 'gsi_openssh'.\n";