Browse Source

Core rewritten in Perl

Benjamin Collet 12 years ago
parent
commit
878180562d
4 changed files with 61 additions and 33 deletions
  1. 30 18
      config
  2. 25 0
      lacg.pl
  3. 0 15
      run.sh
  4. 6 0
      templates/resolv.conf

+ 30 - 18
config

@@ -1,19 +1,31 @@
-[% hostname = 'template-squeeze' -%]
-[% domain   = 'fa0.org' -%]
-[% relayhost = 'smtp.fa0.org' -%]
-[% resolv = {
-  nameservers = [ '192.168.248.53' ]
-  search      = 'fa0.org'
-  }
--%]
-[% interfaces = [
-    { name      = 'eth0'
-      ip        = '192.168.42.7'
-      netmask   = '255.255.255.224'
-      gateway   = '192.168.42.1'
-      ip6       = '2001:470:c8bc:2000::7'
-      netmask6  = '64'
-      gateway6  = '2001:470:c8bc:2000:ff::'
-  }
+%templates = (
+  'hostname'    => '/etc/hostname',
+  'mailname'    => '/etc/mailname',
+  'hosts'       => '/etc/hosts',
+  'interfaces'  => '/etc/network/interfaces',
+  'resolv.conf' => '/etc/resolv.conf',
+  'main.cf'     => '/etc/postfix/main.cf',
+  'maps.cf'     => '/etc/postfix/maps.cf',
+  '70-persistent-net.rules' => '/etc/udev/rules.d/70-persistent-net.rules'
+);
+
+%data = (
+  hostname  => 'test-automation',
+  domain    => 'fa0.org',
+  relayhost =>  'smtp.fa0.org',
+  resolv    => {
+    nameservers => ['192.168.248.153', 'fd00:6b64:f3b0:153::1'],
+    search      => 'fa0.org'
+  },
+  interfaces => [
+    {
+      name      => 'eth0',
+      ip        => '192.168.42.8',
+      netmask   => '255.255.255.224',
+      gateway   => '192.168.42.1',
+      ip6       => '2001:470:c8bc:2000::8',
+      netmask6  => '64',
+      gateway6  => '2001:470:c8bc:2000:ff::'
+    }
   ]
--%]
+)

+ 25 - 0
lacg.pl

@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+
+use strict;
+use Template;
+
+my $lacg_dir = "/root/lacg";
+my $lacg_conf = sprintf('%s/%s', ($lacg_dir,"config"));
+my $lacg_templates_dir = sprintf('%s/%s', ($lacg_dir, "templates"));
+
+our %templates;
+our %data;
+require $lacg_conf;
+
+foreach my $template (keys %templates)
+{
+  printf "Writing %s\n", $templates{$template};
+  my $tt = Template->new({ABSOLUTE => 1});
+  my $tt_file = sprintf('%s/%s', ($lacg_templates_dir, $template));
+  $tt->process($tt_file, \%data, $templates{$template}) || die $tt->error;
+}
+
+print "Lasy Admin Configuration Generator is done.\n";
+print "Press enter to reboot...\n";
+<>;
+exec('reboot');

+ 0 - 15
run.sh

@@ -1,15 +0,0 @@
-#!/bin/bash
-DIR="/root/lacg/"
-CONFIG="$DIR/config"
-TPL="$DIR/templates"
-CMD=$(which tpage)
-
-$CMD --pre_process $CONFIG $TPL/hostname > /etc/hostname
-$CMD --pre_process $CONFIG $TPL/mailname > /etc/mailname
-$CMD --pre_process $CONFIG $TPL/hosts > /etc/hosts
-$CMD --pre_process $CONFIG $TPL/interfaces > /etc/network/interfaces
-$CMD --pre_process $CONFIG $TPL/main.cf > /etc/postfix/main.cf
-$CMD --pre_process $CONFIG $TPL/maps.cf > /etc/postfix/maps.cf
-$CMD --pre_process $CONFIG $TPL/70-persistent-net.rules > /etc/udev/rules.d/70-persistent-net.rules
-
-reboot

+ 6 - 0
templates/resolv.conf

@@ -0,0 +1,6 @@
+[% FOR nameserver IN resolv.nameservers -%]
+nameserver [% nameserver %]
+[% END -%]
+[% IF resolv.search -%]
+search [% resolv.search %]
+[% END -%]