]> andersk Git - gssapi-openssh.git/blob - setup/setup-openssh.pl
62416aa85e712df1d4c783986e874e8069b49c7d
[gssapi-openssh.git] / setup / setup-openssh.pl
1 #
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.
6 #
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>
11 #
12
13 $gpath = $ENV{GLOBUS_LOCATION};
14 if (!defined($gpath))
15 {
16     die "GLOBUS_LOCATION needs to be set before running this script"
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
26 require Grid::GPT::Setup;
27
28 my $globusdir = $gpath;
29 my $setupdir = "$globusdir/setup/globus";
30 my $myname = "setup-openssh.pl";
31
32 print "$myname: Configuring package 'gsi_openssh'...\n";
33 print "Run this as root for the intended effect...\n";
34
35 #
36 # Set up path prefixes for use in the path translations
37 #
38
39 $prefix = ${globusdir};
40 $exec_prefix = "${prefix}";
41 $bindir = "${exec_prefix}/bin";
42 $sbindir = "${exec_prefix}/sbin";
43 $mandir = "${prefix}/man";
44 $mansubdir = "man";
45 $libexecdir = "${exec_prefix}/libexec";
46 $sysconfdir = "/etc/ssh";
47 $piddir = "/var/run";
48 $xauth_path = "/usr/bin/X11/xauth";
49
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..
105         action("$bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N \"\"");
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..
115         action("$bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N \"\"");
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..
125         action("$bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N \"\"");
126     }
127
128     return 0;
129 }
130
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}",
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",
157         );
158
159     #
160     # Files on which to perform path translations
161     #
162
163     %files = (
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,
179         );
180
181     print "Translating strings in config/man files...\n";
182     for my $f (keys %files)
183     {
184         $f =~ /(.*\/)*(.*)$/;
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
191         $g = "$f.tmp";
192
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
201         action("mv $f $g");
202
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))
209             {
210                 s#$s#$def{$s}#;
211             } # for $s
212             print OUT "$_";
213         } # while <IN>
214
215         close(OUT);
216         close(IN);
217
218         if ($file{$f} eq 0)
219         {
220             action("rm $g");
221         }
222         else
223         {
224             print "Left backup config file '$g'\n";
225         }
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);
234     } # for $f
235
236     return 0;
237 }
238
239 copy_setup_files();
240 runkeygen();
241 fixpaths();
242
243 my $metadata = new Grid::GPT::Setup(package_name => "gsi_openssh_setup");
244
245 $metadata->finish();
246
247 print "$myname: Finished configuring package 'gsi_openssh'.\n";
This page took 0.050602 seconds and 3 git commands to generate.