source: fedkit/prep_gateway.pl @ 09f292b

compt_changes
Last change on this file since 09f292b was 09f292b, checked in by Ted Faber <faber@…>, 12 years ago

Deal with installing Linux software using apt-get on the portal

  • Property mode set to 100644
File size: 3.3 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4
5use gateway_lib;
6
7use Getopt::Long;
8use File::Copy;
9use IO::File;
10
11my $ssh_pubkey;
12my $tunnelip;
13my $peer;
14my $use_file;
15my $fed_dir = "/usr/local/federation/";
16my %opts = (
17    'ssh_pubkey=s' => \$ssh_pubkey,
18    'tunnelip' => \$tunnelip,
19    'peer=s' => \$peer,
20    'use_file' => \$use_file,
21);
22
23exit(20) unless GetOptions(%opts);
24
25if ($use_file) {
26    gateway_lib::read_config(gateway_lib::config_filename(), \%opts)
27}
28
29my $uname = `uname`;
30chomp $uname;
31
32# on portals make sure client.conf is in the override position (in fed_dir).
33my $client_conf = gateway_lib::client_conf_filename();
34
35copy($client_conf, "$fed_dir/etc/client.conf") 
36    unless $client_conf =~ /^$fed_dir/;
37
38if ($uname =~ /Linux/) {
39    # Restart sshd with tunnel params
40    gateway_lib::set_sshd_params( 
41        { 'GatewayPorts' => 'yes', 'PermitTunnel' => 'yes' } );
42    system("/etc/init.d/sshd restart");
43    gateway_lib::import_key($ssh_pubkey,'/root/.ssh/authorized_keys')
44        if $ssh_pubkey;
45    # Install bridging software if not present
46    if ( -x '/usr/bin/yum' ) {
47        system('/usr/bin/yum -y install bridge-utils');
48    }
49    elsif (-x '/usr/bin/apt-get') {
50        system('/usr/bin/apt-get -y install bridge-utils');
51    }
52    else {
53        print "Cannot install bridge utils, hope they're here.\n"
54    }
55}
56elsif ($uname =~ /FreeBSD/ ){
57    gateway_lib::set_sshd_params( 
58        { 'GatewayPorts' => 'yes', 'PermitTunnel' => 'yes' } );
59    system("/etc/rc.d/sshd restart");
60
61    gateway_lib::import_key($ssh_pubkey,'/root/.ssh/authorized_keys')
62        if $ssh_pubkey;
63
64    # Need these to make the Ethernet tap and bridge work.
65    system("kldload /boot/kernel/bridgestp.ko") 
66        if -r "/boot/kernel/bridgestp.ko"; 
67    system("kldload /boot/kernel/if_bridge.ko");
68    system("kldload /boot/kernel/if_tap.ko");
69}
70
71if ( $tunnelip ) {
72    my ($interface, $ip, $netmask, $mac, $router) = 
73        gateway_lib::deter_tunnelip();
74
75    gateway_lib::configure_outgoing_iface($interface, $ip, $netmask);
76    # Add the route to a peer.  Wait up to an hour for the peer's IP address to
77    # appear in the DNS.
78    foreach my $p (split(/\s*,\s*/, $peer)) {
79        gateway_lib::add_route($p, $router, 1, 60 *60) 
80            if $p && $router;
81    }
82}
83my $coord_fn = "$fed_dir/etc/prep_done";
84my $coord_file = new IO::File(">$coord_fn") || die "Cannot open $coord_fn";
85
86print $coord_file `date`;
87$coord_file->close();
88
89exit(0);
90
91=pod
92
93=head1 NAME
94
95B<prep_tunnel.pl> - Prepare a tunnel node for use as either a service or connectivity gateway.
96
97=head1 OPTIONS
98
99=over 8
100
101=item B<peer=>I<hostname>
102
103The other gateway providing forwarding.
104
105=item B<ssh_pubkey=>I<keyfile>
106
107A public to install as authorized.
108
109=item B<tunnelip>
110
111True if the testbed uses the DETER tunnelip extension to provide external
112connectivity information
113
114=item B<use_file>
115
116If given read additional parameters from the file in
117/proj/I<project>/exp/I<experiment>/tmp/I<hostname>.gw/conf where those are the
118current testbed project and experiment and the hostname is before the first
119dot.  The file is option: value.
120
121
122=back
123
124=head1 SYNOPSIS
125
126B<prep_gateway.pl> laods the necessary kernel modules for low-level bridging
127configures the local sshd to allow it, restarts that sshd, and installs the
128given key in root's authorized keys.
129
130If the gateway supports DETER gateway, it setablishes outside connectivity and
131adds a host rout to the given peer.
132
133=head1 AUTHORS
134
135Ted Faber <faber@isi.edu>
136
137=cut
Note: See TracBrowser for help on using the repository browser.