]> andersk Git - gssapi-openssh.git/blob - setup/setup-openssh.pl
9e67f03c790f22c55d43ec481cf70d2839d15137
[gssapi-openssh.git] / setup / setup-openssh.pl
1 #!/usr/bin/perl -w
2 #
3 # setup-openssh.pl - substitutes variables into text files and runs
4 #                     ssh key gen programs
5 #
6 # adapted from 'fixpath', located in the openssh-3.0.2p1 package
7 #
8
9 my $gpath = $ENV{GPT_LOCATION};
10 if (!defined($gpath))
11 {
12     $gpath = $ENV{GLOBUS_LCATION};
13 }
14 if (!defined($gpath))
15 {
16     die "GPT_LOCATION or 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 my $globusdir = $gpath;
27 my $setupdir = "$globusdir/setup/globus";
28 my $myname = "setup-openssh.pl";
29
30 print "$myname: Configuring gsi-openssh package\n";
31
32 #
33 # Set up path prefixes for use in the path translations
34 #
35
36 $prefix = ${globusdir};
37 $exec_prefix = "${prefix}";
38 $bindir = "${exec_prefix}/bin";
39 $mandir = "${prefix}/man";
40 $mansubdir = "man";
41 $libexecdir = "${exec_prefix}/libexec";
42 $sysconfdir = "${prefix}/etc";
43 $piddir = "/var/run";
44 $xauth_path = "/usr/bin/X11/xauth";
45
46 sub fixpaths
47 {
48     #
49     # Set up path translations for the installation files
50     #
51
52     %def = (
53         "/etc/ssh_config" => "${sysconfdir}/ssh_config",
54         "/etc/ssh_known_hosts" => "${sysconfdir}/ssh_known_hosts",
55         "/etc/sshd_config" => "${sysconfdir}/sshd_config",
56         "/usr/libexec" => "${libexecdir}",
57         "/etc/shosts.equiv" => "${sysconfdir}/shosts.equiv",
58         "/etc/ssh_host_key" => "${sysconfdir}/ssh_host_key",
59         "/etc/ssh_host_dsa_key" => "${sysconfdir}/ssh_host_dsa_key",
60         "/etc/ssh_host_rsa_key" => "${sysconfdir}/ssh_host_rsa_key",
61         "/var/run/sshd.pid" => "${piddir}/sshd.pid",
62         "/etc/moduli" => "${sysconfdir}/moduli",
63         "/etc/sshrc" => "${sysconfdir}/sshrc",
64         "/usr/X11R6/bin/xauth" => "${xauth_path}",
65         "/usr/bin:/bin:/usr/sbin:/sbin" => "/usr/bin:/bin:/usr/sbin:/sbin:${bindir}",
66         );
67
68     #
69     # Files on which to perform path translations
70     #
71
72     @files = (
73         "${sysconfdir}/ssh_config",
74         "${sysconfdir}/sshd_config",
75         "${sysconfdir}/moduli",
76         "${mandir}/${mansubdir}1/scp.1",
77         "${mandir}/${mansubdir}1/ssh-add.1",
78         "${mandir}/${mansubdir}1/ssh-agent.1",
79         "${mandir}/${mansubdir}1/ssh-keygen.1",
80         "${mandir}/${mansubdir}1/ssh-keyscan.1",
81         "${mandir}/${mansubdir}1/ssh.1",
82         "${mandir}/${mansubdir}8/sshd.8",
83         "${mandir}/${mansubdir}8/sftp-server.8",
84         "${mandir}/${mansubdir}1/sftp.1",
85         );
86
87     print "\nTranslating strings in config/man files..\n";
88     for $f (@files)
89     {
90         $f =~ /(.*\/)*(.*)$/;
91         $g = "$f.tmp";
92
93         $result = system("cp $f $g");
94         if ($result != 0)
95         {
96             die "Failed to copy $f to $g!\n";
97         }
98
99         open(IN, "<$g") || die ("$0: input file $g missing!\n");
100         open(OUT, ">$f") || die ("$0: unable to open output file $f!\n");
101
102         while (<IN>)
103         {
104             for $s (keys(%def))
105             {
106                 s#$s#$def{$s}#;
107             } # for $s
108             print OUT "$_";
109         } # while <IN>
110
111         close(OUT);
112         close(IN);
113
114         $result = system("rm $g");
115         if ($result != 0)
116         {
117             die "Failed to remove $g\n";
118         }
119     } # for $f
120
121     return 0;
122 }
123
124 sub runkeygen
125 {
126     print "\nGenerating ssh keys (if necessary)..\n";
127     if ( -e "${sysconfdir}/ssh_host_key" )
128     {
129         print "${sysconfdir}/ssh_host_key already exists, skipping.\n";
130     }
131     else
132     {
133         # if $sysconfdir/ssh_host_key doesn't exist..
134         system("$bindir/ssh-keygen -t rsa1 -f $sysconfdir/ssh_host_key -N \"\"");
135     }
136
137     if ( -e "${sysconfdir}/ssh_host_dsa_key" )
138     {
139         print "${sysconfdir}/ssh_host_dsa_key already exists, skipping.\n";
140     }
141     else
142     {
143         # if $sysconfdir/ssh_host_dsa_key doesn't exist..
144         system("$bindir/ssh-keygen -t dsa -f $sysconfdir/ssh_host_dsa_key -N \"\"");
145     }
146
147     if ( -e "${sysconfdir}/ssh_host_rsa_key" )
148     {
149         print "${sysconfdir}/ssh_host_rsa_key already exists, skipping.\n";
150     }
151     else
152     {
153         # if $sysconfdir/ssh_host_rsa_key doesn't exist..
154         system("$bindir/ssh-keygen -t rsa -f $sysconfdir/ssh_host_rsa_key -N \"\"");
155     }
156
157     return 0;
158 }
159
160 fixpaths();
161 runkeygen();
162
163 exit 0;
This page took 0.034844 seconds and 3 git commands to generate.