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