]> andersk Git - gssapi-openssh.git/blob - setup/setup-openssh.pl
51edbd909fbfcf8c23e7ca1a1fd753e3725af262
[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
34 #
35 # Set up path prefixes for use in the path translations
36 #
37
38 $prefix = ${globusdir};
39 $exec_prefix = "${prefix}";
40 $bindir = "${exec_prefix}/bin";
41 $mandir = "${prefix}/man";
42 $mansubdir = "man";
43 $libexecdir = "${exec_prefix}/libexec";
44 $sysconfdir = "${prefix}/etc";
45 $piddir = "/var/run";
46 $xauth_path = "/usr/bin/X11/xauth";
47
48 sub fixpaths
49 {
50     #
51     # Set up path translations for the installation files
52     #
53
54     %def = (
55         "/etc/ssh_config" => "${sysconfdir}/ssh_config",
56         "/etc/ssh_known_hosts" => "${sysconfdir}/ssh_known_hosts",
57         "/etc/sshd_config" => "${sysconfdir}/sshd_config",
58         "/usr/libexec" => "${libexecdir}",
59         "/etc/shosts.equiv" => "${sysconfdir}/shosts.equiv",
60         "/etc/ssh_host_key" => "${sysconfdir}/ssh_host_key",
61         "/etc/ssh_host_dsa_key" => "${sysconfdir}/ssh_host_dsa_key",
62         "/etc/ssh_host_rsa_key" => "${sysconfdir}/ssh_host_rsa_key",
63         "/var/run/sshd.pid" => "${piddir}/sshd.pid",
64         "/etc/moduli" => "${sysconfdir}/moduli",
65         "/etc/sshrc" => "${sysconfdir}/sshrc",
66         "/usr/X11R6/bin/xauth" => "${xauth_path}",
67         "/usr/bin:/bin:/usr/sbin:/sbin" => "/usr/bin:/bin:/usr/sbin:/sbin:${bindir}",
68         "/path/to/scp.real" => "${bindir}/scp.real",
69         "/path/to/ssh" => "${bindir}/ssh",
70         );
71
72     #
73     # Files on which to perform path translations
74     #
75
76     @files = (
77         "${bindir}/scp",
78         "${sysconfdir}/ssh_config",
79         "${sysconfdir}/sshd_config",
80         "${sysconfdir}/moduli",
81         "${mandir}/${mansubdir}1/scp.1",
82         "${mandir}/${mansubdir}1/ssh-add.1",
83         "${mandir}/${mansubdir}1/ssh-agent.1",
84         "${mandir}/${mansubdir}1/ssh-keygen.1",
85         "${mandir}/${mansubdir}1/ssh-keyscan.1",
86         "${mandir}/${mansubdir}1/ssh.1",
87         "${mandir}/${mansubdir}8/sshd.8",
88         "${mandir}/${mansubdir}8/sftp-server.8",
89         "${mandir}/${mansubdir}1/sftp.1",
90         );
91
92     print "Translating strings in config/man files...\n";
93     for $f (@files)
94     {
95         $f =~ /(.*\/)*(.*)$/;
96         $g = "$f.tmp";
97
98         $result = system("mv $f $g");
99         if ($result != 0)
100         {
101             die "Failed to copy $f to $g!\n";
102         }
103
104         open(IN, "<$g") || die ("$0: input file $g missing!\n");
105         open(OUT, ">$f") || die ("$0: unable to open output file $f!\n");
106
107         while (<IN>)
108         {
109             for $s (keys(%def))
110             {
111                 s#$s#$def{$s}#;
112             } # for $s
113             print OUT "$_";
114         } # while <IN>
115
116         close(OUT);
117         close(IN);
118
119         $result = system("rm $g");
120         if ($result != 0)
121         {
122             die "Failed to remove $g\n";
123         }
124     } # for $f
125
126     return 0;
127 }
128
129 sub setperms()
130 {
131     $result = system("chmod 755 $bindir/scp");
132 }
133
134 sub runkeygen
135 {
136     print "Generating ssh keys (if necessary)...\n";
137     if ( -e "${sysconfdir}/ssh_host_key" )
138     {
139         print "${sysconfdir}/ssh_host_key already exists, skipping.\n";
140     }
141     else
142     {
143         # if $sysconfdir/ssh_host_key doesn't exist..
144         system("$bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N \"\"");
145     }
146
147     if ( -e "${sysconfdir}/ssh_host_dsa_key" )
148     {
149         print "${sysconfdir}/ssh_host_dsa_key already exists, skipping.\n";
150     }
151     else
152     {
153         # if $sysconfdir/ssh_host_dsa_key doesn't exist..
154         system("$bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N \"\"");
155     }
156
157     if ( -e "${sysconfdir}/ssh_host_rsa_key" )
158     {
159         print "${sysconfdir}/ssh_host_rsa_key already exists, skipping.\n";
160     }
161     else
162     {
163         # if $sysconfdir/ssh_host_rsa_key doesn't exist..
164         system("$bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N \"\"");
165     }
166
167     return 0;
168 }
169
170 fixpaths();
171 setperms();
172 runkeygen();
173
174 my $metadata = new Grid::GPT::Setup(package_name => "gsi-openssh-setup");
175
176 $metadata->finish();
This page took 0.964731 seconds and 3 git commands to generate.