]>
Commit | Line | Data |
---|---|---|
20d3226a | 1 | # |
1eab725d | 2 | # setup-openssh.pl: |
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. | |
701aa556 | 6 | # |
1eab725d | 7 | # Large parts adapted from 'fixpath', a tool found in openssh-3.0.2p1. |
8 | # | |
9 | # Send comments/fixes/suggestions to: | |
10 | # Chase Phillips <cphillip@ncsa.uiuc.edu> | |
701aa556 | 11 | # |
20d3226a | 12 | |
4f276ad7 | 13 | $gpath = $ENV{GLOBUS_LOCATION}; |
ad71c979 | 14 | if (!defined($gpath)) |
15 | { | |
53a54c67 | 16 | die "GLOBUS_LOCATION needs to be set before running this script" |
ad71c979 | 17 | } |
18 | ||
19 | # | |
20 | # i'm including this because other perl scripts in the gpt setup directories | |
21 | # do so | |
22 | # | |
23 | ||
24 | @INC = (@INC, "$gpath/lib/perl"); | |
25 | ||
4f276ad7 | 26 | require Grid::GPT::Setup; |
27 | ||
ad71c979 | 28 | my $globusdir = $gpath; |
29 | my $setupdir = "$globusdir/setup/globus"; | |
30 | my $myname = "setup-openssh.pl"; | |
31 | ||
9ef2f439 | 32 | print "$myname: Configuring package 'gsi_openssh'...\n"; |
1a1f62a4 | 33 | print "Run this as root for the intended effect...\n"; |
ad71c979 | 34 | |
20d3226a | 35 | # |
36 | # Set up path prefixes for use in the path translations | |
37 | # | |
38 | ||
d0a1bda7 | 39 | $prefix = ${globusdir}; |
40 | $exec_prefix = "${prefix}"; | |
41 | $bindir = "${exec_prefix}/bin"; | |
7c25a6d7 | 42 | $sbindir = "${exec_prefix}/sbin"; |
d0a1bda7 | 43 | $mandir = "${prefix}/man"; |
44 | $mansubdir = "man"; | |
45 | $libexecdir = "${exec_prefix}/libexec"; | |
1a1f62a4 | 46 | $sysconfdir = "/etc/ssh"; |
20d3226a | 47 | $piddir = "/var/run"; |
48 | $xauth_path = "/usr/bin/X11/xauth"; | |
49 | ||
1a1f62a4 | 50 | # |
51 | # Just need a minimal action() subroutine for now.. | |
52 | # | |
53 | ||
54 | sub action | |
55 | { | |
56 | my $command = @_; | |
57 | ||
58 | printf "$command\n"; | |
59 | ||
60 | my $result = system("$command 2>&1"); | |
61 | ||
62 | if (($result or $?) and $command !~ m!patch!) | |
63 | { | |
64 | die "ERROR: Unable to execute command: $!\n"; | |
65 | } | |
66 | } | |
67 | ||
68 | sub copy_setup_files | |
69 | { | |
70 | if ( -e "${sysconfdir}/ssh_config" ) | |
71 | { | |
72 | print "${sysconfdir}/ssh_config already exists, skipping.\n"; | |
73 | } | |
74 | else | |
75 | { | |
76 | action("cp ${globusdir}/setup/globus/ssh_config ${sysconfdir}/ssh_config"); | |
77 | } | |
78 | ||
79 | if ( -e "${sysconfdir}/sshd_config" ) | |
80 | { | |
81 | print "${sysconfdir}/sshd_config already exists, skipping.\n"; | |
82 | } | |
83 | else | |
84 | { | |
85 | action("cp ${globusdir}/setup/globus/sshd_config ${sysconfdir}/sshd_config"); | |
86 | } | |
87 | } | |
88 | ||
89 | sub runkeygen | |
90 | { | |
91 | if ( ! -d "${sysconfdir}" ) | |
92 | { | |
93 | print "Could not find ${sysconfdir} directory... creating\n"; | |
94 | mkdir($sysconfdir, mode); | |
95 | } | |
96 | ||
97 | print "Generating ssh keys (if necessary)...\n"; | |
98 | if ( -e "${sysconfdir}/ssh_host_key" ) | |
99 | { | |
100 | print "${sysconfdir}/ssh_host_key already exists, skipping.\n"; | |
101 | } | |
102 | else | |
103 | { | |
104 | # if $sysconfdir/ssh_host_key doesn't exist.. | |
11b9a41c | 105 | action("$bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N \"\""); |
1a1f62a4 | 106 | } |
107 | ||
108 | if ( -e "${sysconfdir}/ssh_host_dsa_key" ) | |
109 | { | |
110 | print "${sysconfdir}/ssh_host_dsa_key already exists, skipping.\n"; | |
111 | } | |
112 | else | |
113 | { | |
114 | # if $sysconfdir/ssh_host_dsa_key doesn't exist.. | |
11b9a41c | 115 | action("$bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N \"\""); |
1a1f62a4 | 116 | } |
117 | ||
118 | if ( -e "${sysconfdir}/ssh_host_rsa_key" ) | |
119 | { | |
120 | print "${sysconfdir}/ssh_host_rsa_key already exists, skipping.\n"; | |
121 | } | |
122 | else | |
123 | { | |
124 | # if $sysconfdir/ssh_host_rsa_key doesn't exist.. | |
11b9a41c | 125 | action("$bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N \"\""); |
1a1f62a4 | 126 | } |
127 | ||
128 | return 0; | |
129 | } | |
130 | ||
20d3226a | 131 | sub fixpaths |
132 | { | |
133 | # | |
134 | # Set up path translations for the installation files | |
135 | # | |
136 | ||
137 | %def = ( | |
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}", | |
44c96d90 | 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", | |
20d3226a | 157 | ); |
158 | ||
20d3226a | 159 | # |
160 | # Files on which to perform path translations | |
161 | # | |
162 | ||
1a1f62a4 | 163 | %files = ( |
11b9a41c | 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, | |
20d3226a | 179 | ); |
180 | ||
4f276ad7 | 181 | print "Translating strings in config/man files...\n"; |
1a1f62a4 | 182 | for my $f (keys %files) |
20d3226a | 183 | { |
184 | $f =~ /(.*\/)*(.*)$/; | |
7536fc6f | 185 | |
186 | # | |
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) | |
189 | # | |
190 | ||
d0a1bda7 | 191 | $g = "$f.tmp"; |
20d3226a | 192 | |
7536fc6f | 193 | # |
194 | # Grab the current mode/uid/gid for use later | |
195 | # | |
196 | ||
197 | $mode = (stat($f))[2]; | |
198 | $uid = (stat($f))[4]; | |
199 | $gid = (stat($f))[5]; | |
200 | ||
1a1f62a4 | 201 | action("mv $f $g"); |
20d3226a | 202 | |
d0a1bda7 | 203 | open(IN, "<$g") || die ("$0: input file $g missing!\n"); |
204 | open(OUT, ">$f") || die ("$0: unable to open output file $f!\n"); | |
205 | ||
206 | while (<IN>) | |
207 | { | |
208 | for $s (keys(%def)) | |
20d3226a | 209 | { |
d0a1bda7 | 210 | s#$s#$def{$s}#; |
211 | } # for $s | |
212 | print OUT "$_"; | |
213 | } # while <IN> | |
20d3226a | 214 | |
d0a1bda7 | 215 | close(OUT); |
20d3226a | 216 | close(IN); |
d0a1bda7 | 217 | |
1a1f62a4 | 218 | if ($file{$f} eq 0) |
219 | { | |
220 | action("rm $g"); | |
221 | } | |
222 | else | |
d0a1bda7 | 223 | { |
1a1f62a4 | 224 | print "Left backup config file '$g'\n"; |
d0a1bda7 | 225 | } |
7536fc6f | 226 | |
227 | # | |
228 | # An attempt to revert the new file back to the original file's | |
229 | # mode/uid/gid | |
230 | # | |
231 | ||
232 | chmod($mode, $f); | |
233 | chown($uid, $gid, $f); | |
20d3226a | 234 | } # for $f |
235 | ||
236 | return 0; | |
237 | } | |
238 | ||
11b9a41c | 239 | copy_setup_files(); |
1a1f62a4 | 240 | runkeygen(); |
11b9a41c | 241 | fixpaths(); |
ad71c979 | 242 | |
472ec086 | 243 | my $metadata = new Grid::GPT::Setup(package_name => "gsi_openssh_setup"); |
4f276ad7 | 244 | |
53a54c67 | 245 | $metadata->finish(); |
9ef2f439 | 246 | |
247 | print "$myname: Finished configuring package 'gsi_openssh'.\n"; |