]>
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 | |
4f276ad7 | 9 | $gpath = $ENV{GLOBUS_LOCATION}; |
ad71c979 | 10 | if (!defined($gpath)) |
11 | { | |
53a54c67 | 12 | die "GLOBUS_LOCATION needs to be set before running this script" |
ad71c979 | 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 | ||
4f276ad7 | 22 | require Grid::GPT::Setup; |
23 | ||
ad71c979 | 24 | my $globusdir = $gpath; |
25 | my $setupdir = "$globusdir/setup/globus"; | |
26 | my $myname = "setup-openssh.pl"; | |
27 | ||
4f276ad7 | 28 | print "$myname: Configuring gsi-openssh package"; |
ad71c979 | 29 | |
20d3226a | 30 | # |
31 | # Set up path prefixes for use in the path translations | |
32 | # | |
33 | ||
d0a1bda7 | 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"; | |
20d3226a | 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 | ||
20d3226a | 66 | # |
67 | # Files on which to perform path translations | |
68 | # | |
69 | ||
70 | @files = ( | |
d0a1bda7 | 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", | |
20d3226a | 83 | ); |
84 | ||
4f276ad7 | 85 | print "Translating strings in config/man files...\n"; |
20d3226a | 86 | for $f (@files) |
87 | { | |
88 | $f =~ /(.*\/)*(.*)$/; | |
d0a1bda7 | 89 | $g = "$f.tmp"; |
20d3226a | 90 | |
53a54c67 | 91 | $result = system("mv $f $g"); |
d0a1bda7 | 92 | if ($result != 0) |
20d3226a | 93 | { |
d0a1bda7 | 94 | die "Failed to copy $f to $g!\n"; |
20d3226a | 95 | } |
20d3226a | 96 | |
d0a1bda7 | 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)) | |
20d3226a | 103 | { |
d0a1bda7 | 104 | s#$s#$def{$s}#; |
105 | } # for $s | |
106 | print OUT "$_"; | |
107 | } # while <IN> | |
20d3226a | 108 | |
d0a1bda7 | 109 | close(OUT); |
20d3226a | 110 | close(IN); |
d0a1bda7 | 111 | |
112 | $result = system("rm $g"); | |
113 | if ($result != 0) | |
114 | { | |
115 | die "Failed to remove $g\n"; | |
116 | } | |
20d3226a | 117 | } # for $f |
118 | ||
119 | return 0; | |
120 | } | |
121 | ||
122 | sub runkeygen | |
123 | { | |
4f276ad7 | 124 | print "Generating ssh keys (if necessary)...\n"; |
20d3226a | 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(); | |
20d3226a | 159 | runkeygen(); |
ad71c979 | 160 | |
4f276ad7 | 161 | my $metadata = new Grid::GPT::Setup(package_name => "gsi-openssh-setup"); |
162 | ||
53a54c67 | 163 | $metadata->finish(); |