diff options
Diffstat (limited to 'bootstrap')
-rwxr-xr-x | bootstrap/fetch-debinstall.sh | 17 | ||||
-rwxr-xr-x | bootstrap/make-bind-include.pl | 51 | ||||
-rwxr-xr-x | bootstrap/make-dhcpd-include.pl | 18 | ||||
-rwxr-xr-x | bootstrap/make-missing-conf.pl | 176 | ||||
-rwxr-xr-x | bootstrap/make-pxeboot.sh | 2 | ||||
-rwxr-xr-x | bootstrap/update-baseservice.sh | 14 |
6 files changed, 271 insertions, 7 deletions
diff --git a/bootstrap/fetch-debinstall.sh b/bootstrap/fetch-debinstall.sh new file mode 100755 index 0000000..069e39a --- /dev/null +++ b/bootstrap/fetch-debinstall.sh @@ -0,0 +1,17 @@ +#!/bin/bash -xe +INSTALLER_DEST=$1 +DEBINSTROOT=http://ftp.no.debian.org/debian/dists + +mkdir -p ${INSTALLER_DEST}/{squeeze,wheezy}/{amd64,i386} +for DIST in squeeze wheezy +do + for ARCH in i386 amd64; + do + for FILE in initrd.gz linux + do + wget ${DEBINSTROOT}/${DIST}/main/installer-${ARCH}/current/images/netboot/debian-installer/${ARCH}/${FILE} \ + -O ${INSTALLER_DEST}/${DIST}/${ARCH}/${FILE} + done + done +done + diff --git a/bootstrap/make-bind-include.pl b/bootstrap/make-bind-include.pl new file mode 100755 index 0000000..d688dec --- /dev/null +++ b/bootstrap/make-bind-include.pl @@ -0,0 +1,51 @@ +#!/usr/bin/perl -I /root/tgmanage + +# TODO: Port this to the "master|slave base" parameter syntax! + +use strict; + +unless ( (($#ARGV == 0 ) || ( $#ARGV == 1)) + && (( $ARGV[0] eq "master" ) || ( $ARGV[0] eq "slave" )) ) +{ + print STDERR "Invalid usage!\ncat netnames.txt | $0 <master|slave> [basedir]\n"; + exit 1; +} + +my $role = $ARGV[0]; + +my $base = "/etc"; +$base = $ARGV[1] if $#ARGV == 1; +$base .= "/" if not $base =~ m/\/$/ and not $base eq ""; + +my $bind_base = $base . "bind/"; +my $masterinclude = $bind_base . "named.master-include.conf"; +my $slaveinclude = $bind_base . "named.slave-include.conf"; + +my $glob; +my @configs; + +if ( $role eq "master" ) +{ + $glob = $bind_base . "conf-master/*.conf"; + @configs = glob($glob); + + open CONF, ">" . $masterinclude or die ( $! . " " . $masterinclude); + foreach my $config ( @configs ) + { + print CONF "include \"" . $config . "\";\n"; + } + close CONF; +} + +if ( $role eq "slave" ) +{ + $glob = $bind_base . "conf-slave/*.conf"; + @configs = glob($glob); + + open CONF, ">" . $slaveinclude or die ( $! . " " . $slaveinclude); + foreach my $config ( @configs ) + { + print CONF "include \"" . $config . "\";\n"; + } + close CONF; +} diff --git a/bootstrap/make-dhcpd-include.pl b/bootstrap/make-dhcpd-include.pl new file mode 100755 index 0000000..ded5551 --- /dev/null +++ b/bootstrap/make-dhcpd-include.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl -I /root/tgmanage +use strict; +my $base = "/etc"; +$base = $ARGV[0] if $#ARGV > -1; +$base .= "/" if not $base =~ m/\/$/ and not $base eq ""; + +my $dhcpd_base = $base . "dhcp/"; +my $includeconfig = $dhcpd_base . "generated-include.conf"; + +my $glob = $dhcpd_base . "conf.d/*.conf"; +my @configs = glob($glob); + +open CONF, ">" . $includeconfig or die ( $! . " " . $includeconfig); +foreach my $config ( @configs ) +{ + print CONF "include \"" . $config . "\";\n"; +} +close CONF; diff --git a/bootstrap/make-missing-conf.pl b/bootstrap/make-missing-conf.pl new file mode 100755 index 0000000..598964f --- /dev/null +++ b/bootstrap/make-missing-conf.pl @@ -0,0 +1,176 @@ +#!/usr/bin/perl -I /root/tgmanage +use strict; + +BEGIN { + require "include/config.pm"; + eval { + require "include/config.local.pm"; + }; +} + + +use Net::IP; +use Net::IP qw(:PROC); + +my $serial = strftime("%Y%m%d", localtime(time())) . "01"; + +unless ( (($#ARGV == 0 ) || ( $#ARGV == 1)) + && (( $ARGV[0] eq "master" ) || ( $ARGV[0] eq "slave" )) ) +{ + print STDERR "Invalid usage!\ncat netnames.txt | $0 <master|slave> [basedir]\n"; + exit 1; +} + +my $role = $ARGV[0]; + +my $base = "/etc"; +$base = $ARGV[1] if $#ARGV == 1; +$base .= "/" if not $base =~ m/\/$/ and not $base eq ""; + + +print STDERR "Role is " . $role . "\n"; +print STDERR "Base dir is " . $base . "\n"; + +my $bind_base = $base . "bind/"; +my $dhcpd_base = $base . "dhcp/"; + +my $dhcp_dynconf_dir = $dhcpd_base . "conf.d/"; +my $bind_conf_master = $bind_base . "conf-master/"; +my $bind_conf_slave = $bind_base . "conf-slave/"; + +my $tgname = $nms::config::tgname; + +my $pri_hostname = $nms::config::pri_hostname; +my $pri_v4 = $nms::config::pri_v4; +my $pri_v6 = $nms::config::pri_v6; + +my $sec_hostname = $nms::config::sec_hostname; +my $sec_v4 = $nms::config::sec_v4; +my $sec_v6 = $nms::config::sec_v6; + +my $ddns_key = $nms::config::ddns_key; + +my $ddns_to = $nms::config::ddns_to; + +my $base_ipv4 = new Net::IP( $nms::config::base_ipv4net ); +my ($cp_oct, $cs_oct, $ct_oct) = ($nms::config::base_ipv4net =~ m/^(\d+)\.(\d+)\.(\d+)\..*/); + +while ( <STDIN> ) +{ + next if ( $_ =~ m/^#/); + my $line = $_; + chomp $line; + die ("Invalid format on input") if not $line =~ m/^(\d+)\.(\d+)\.(\d+)\.(\d+)\s+(\d+)\s+([\w|-]+)\s*.*/; + my ( $p_oct, $s_oct, $t_oct, $f_oct, $size, $name ) = ( $1, $2, $3, $4, $5, $6 ); + + + my $dhconfig = $dhcp_dynconf_dir . $name . ".conf"; + my $master_config = $bind_conf_master . $name . ".conf"; + my $slave_config = $bind_conf_slave . $name . ".conf"; + my $zone_file = $bind_base . "dynamic/$name.$tgname.gathering.org.zone"; + + my $net_base = $p_oct . "." . $s_oct . "." . $t_oct; + my $net = $net_base . "." . $f_oct; + my $range = new Net::IP( $net . "/" . $size ) or die ("oopxos"); + + # Create configuration files for DHCP on master/primary + if ( ( not -f $dhconfig ) && ( $role eq "master" ) ) + { + print STDERR "Creating file " . $dhconfig . "\n"; + my $numhosts = $range->size(); + my $mask = $range->mask(); + my $router = $net_base . "." . ($f_oct+1); + my $first = $net_base . "." . ( $f_oct + 5 ); + + my $last = $first; + if ( $size < 24 ) + { + # Net::IP iteration is crazyslow. So, we stopped using iterations. + my $last_ip = $range->last_ip(); + $last_ip =~ m/(\d+)\.(\d+)\.(\d+)\.(\d+)/; + $last = sprintf("%d.%d.%d.%d", $1, $2, $3, $4-2); + } + else { $last = $net_base . "." . ( $f_oct + $numhosts - 2 ); } + + #print STDERR "Name : " . $name . "\n"; + #print STDERR "Net : " . $net . "\n"; + #print STDERR "Mask : " . $mask . "\n"; + #print STDERR "Router : " . $router . "\n"; + #print STDERR "Size : " . $size . "\n"; + #print STDERR "Numhosts : " . $numhosts . "\n"; + #print STDERR "First : " . $first . "\n"; + #print STDERR "Last : " . $last . "\n"; + + open DFILE, ">" . $dhconfig or die ( $! . " " . $dhconfig); + + print DFILE "zone $name.$tgname.gathering.org {\n"; + print DFILE " primary $ddns_to;\n"; + print DFILE " key DHCP_UPDATER;\n"; + print DFILE "}\n\n"; + + print DFILE "subnet $net netmask $mask {\n"; + print DFILE " authoritative;\n"; + print DFILE " option routers $router;\n"; + print DFILE " option domain-name \"$name.$tgname.gathering.org\";\n"; + print DFILE " ddns-domainname \"$name.$tgname.gathering.org\";\n"; + print DFILE " range $first $last;\n"; + print DFILE " ignore client-updates;\n"; + print DFILE "}\n\n"; + + close DFILE; + } + + # Create zone files for bind9 on master/primary + if ( ( not -f $zone_file ) && ( $role eq "master" ) ) + { + print STDERR "Creating file " . $zone_file . "\n"; + open ZFILE, ">" . $zone_file or die ( $! . " " . $zone_file); + print ZFILE << "EOF"; +; Base reverse zones are updated from dhcpd -- DO NOT TOUCH! +\$TTL 3600 +@ IN SOA $pri_hostname.$tgname.gathering.org. abuse.gathering.org. ( + $serial ; serial + 3600 ; refresh + 1800 ; retry + 608400 ; expire + 3600 ) ; minimum and default TTL + + IN NS $pri_hostname.$tgname.gathering.org. + IN NS $sec_hostname.$tgname.gathering.org. +\$ORIGIN $name.$tgname.gathering.org. +EOF + close ZFILE; + } + + + # Create bind9 configuration files for zones. + my $bind_file = ""; + $bind_file = $master_config if ( $role eq "master"); + $bind_file = $slave_config if ( $role eq "slave"); + die ("WTF, role does not match 'master' or 'slave'" ) if ( $bind_file eq ""); + + if ( not -f $bind_file ) + { + print STDERR "Creating file " . $bind_file . "\n"; + open NFILE, ">" . $bind_file or die ( $! . " " . $bind_file); + + print NFILE "zone \"$name.$tgname.gathering.org\" {\n"; + if ( $role eq "master" ) { + print NFILE " type master;\n"; + print NFILE " notify yes;\n"; + print NFILE " allow-update { key DHCP_UPDATER; };\n"; + print NFILE " file \"dynamic/$name.$tgname.gathering.org.zone\";\n"; + } + else + { + print NFILE " type slave;\n"; + print NFILE " notify no;\n"; + print NFILE " masters { bootstrap; };\n"; + print NFILE " file \"slave/$name.$tgname.gathering.org.zone\";\n"; + } + print NFILE " allow-transfer { ns-xfr; };\n"; + print NFILE "};\n"; + + close NFILE; + } +} diff --git a/bootstrap/make-pxeboot.sh b/bootstrap/make-pxeboot.sh index 4a9e271..e9ad8a6 100755 --- a/bootstrap/make-pxeboot.sh +++ b/bootstrap/make-pxeboot.sh @@ -25,7 +25,7 @@ mkdir -p /var/lib/tftpboot # This should be done by bootstrap/update-tools ... cp -R ~/tgmanage/pxe/* /var/lib/tftpboot -~/tgmanage/tools/fetch-debinstall.sh /var/lib/tftpboot/debian +~/tgmanage/bootstrap/fetch-debinstall.sh /var/lib/tftpboot/debian # tools/fetch-ubuntulive.sh <- this tool does not exist xD # NOTE! The pxe/ directory contains an 'ubuntu' menu... # The files required to booting Ubuntu installer or live diff --git a/bootstrap/update-baseservice.sh b/bootstrap/update-baseservice.sh index 94c3875..c3c0c7e 100755 --- a/bootstrap/update-baseservice.sh +++ b/bootstrap/update-baseservice.sh @@ -16,14 +16,16 @@ then exit 1; fi; -cat netlist.txt | ssh -l root ${PRIMARY} "~/tgmanage/tools/make-missing-conf.pl master ${BASE}" -ssh -l root ${PRIMARY} "~/tgmanage/tools/make-dhcpd-include.pl ${BASE}" -ssh -l root ${PRIMARY} "~/tgmanage/tools/make-bind-include.pl master ${BASE}" +cd ~/tgmanage + +cat netlist.txt | ssh -l root ${PRIMARY} "~/tgmanage/bootstrap/make-missing-conf.pl master ${BASE}" +ssh -l root ${PRIMARY} "~/tgmanage/bootstrap/make-bind-include.pl master ${BASE}" +ssh -l root ${PRIMARY} "~/tgmanage/bootstrap/make-dhcpd-include.pl ${BASE}" set +e ssh -l root ${PRIMARY} "chown bind.bind /etc/bind/dynamic/*.zone"; set -e -cat netlist.txt | ssh -l root ${SECONDARY} "~/tgmanage/tools/make-missing-conf.pl slave ${BASE}" -ssh -l root ${SECONDARY} "~/tgmanage/tools/make-bind-include.pl slave ${BASE}" -ssh -l root ${SECONDARY} "~/tgmanage/tools/make-dhcpd-include.pl ${BASE}" +cat netlist.txt | ssh -l root ${SECONDARY} "~/tgmanage/bootstrap/make-missing-conf.pl slave ${BASE}" +ssh -l root ${SECONDARY} "~/tgmanage/bootstrap/make-bind-include.pl slave ${BASE}" +ssh -l root ${SECONDARY} "~/tgmanage/bootstrap/make-dhcpd-include.pl ${BASE}" |