]>
Commit | Line | Data |
---|---|---|
20d3226a | 1 | #!/usr/bin/perl -w |
2 | # | |
701aa556 | 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 | # | |
20d3226a | 8 | |
53a54c67 | 9 | require Grid::GPT::Setup; |
10 | ||
11 | my $metadata = new Grid::GPT::Setup(package_name => "gsi-openssh-setup"); | |
12 | ||
13 | $gpath = $ENV{GLOBUS_LCATION}; | |
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 | ||
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 | ||
20d3226a | 32 | # |
33 | # Set up path prefixes for use in the path translations | |
34 | # | |
35 | ||
d0a1bda7 | 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"; | |
20d3226a | 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 | ||
20d3226a | 68 | # |
69 | # Files on which to perform path translations | |
70 | # | |
71 | ||
72 | @files = ( | |
d0a1bda7 | 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", | |
20d3226a | 85 | ); |
86 | ||
701aa556 | 87 | print "\nTranslating strings in config/man files..\n"; |
20d3226a | 88 | for $f (@files) |
89 | { | |
90 | $f =~ /(.*\/)*(.*)$/; | |
d0a1bda7 | 91 | $g = "$f.tmp"; |
20d3226a | 92 | |
53a54c67 | 93 | $result = system("mv $f $g"); |
d0a1bda7 | 94 | if ($result != 0) |
20d3226a | 95 | { |
d0a1bda7 | 96 | die "Failed to copy $f to $g!\n"; |
20d3226a | 97 | } |
20d3226a | 98 | |
d0a1bda7 | 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)) | |
20d3226a | 105 | { |
d0a1bda7 | 106 | s#$s#$def{$s}#; |
107 | } # for $s | |
108 | print OUT "$_"; | |
109 | } # while <IN> | |
20d3226a | 110 | |
d0a1bda7 | 111 | close(OUT); |
20d3226a | 112 | close(IN); |
d0a1bda7 | 113 | |
114 | $result = system("rm $g"); | |
115 | if ($result != 0) | |
116 | { | |
117 | die "Failed to remove $g\n"; | |
118 | } | |
20d3226a | 119 | } # for $f |
120 | ||
121 | return 0; | |
122 | } | |
123 | ||
124 | sub runkeygen | |
125 | { | |
701aa556 | 126 | print "\nGenerating ssh keys (if necessary)..\n"; |
20d3226a | 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(); | |
20d3226a | 161 | runkeygen(); |
ad71c979 | 162 | |
53a54c67 | 163 | $metadata->finish(); |