JET no zone sysidcfg

From JetResources
Revision as of 06:55, 10 January 2008 by Jetmark (Talk | contribs) (Public JET no zone sysidcfg moved to JET no zone sysidcfg)

(diff) ←Older revision | view current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Parent

no_zone_sysidcfg

#!/usr/bin/perl
#
# Program      : no_zone_sysidcfg
# Author       : Mark Ashley 
# Version      : 1.2
# Initial Date : 8th January 2008
# Modify Date  : 9th January 2008
# Purpose      : Do all the post zone install steps needed to avoid the sysidcfg firing up
#                This allows the zones to fully install by themselves. Why doesn't JET do this?

opendir(ZONES, "/data/zone");
my @zones = grep(!/^\./, readdir(ZONES));
closedir(ZONES);

foreach my $zone (@zones) {
    &setup_tz($zone);
    &setup_dns($zone);
    &setup_nfs($zone);
    &setup_nodename($zone);
    &setup_power_mgmt($zone);
    &setup_sysid_state($zone);
}

exit(0);

##############################################################################################

sub setup_tz {
    my ($zone) = @_;
    &mod_file_value("/data/zone/${zone}/root/etc/TIMEZONE", "TZ", "Australia/NSW");
}

sub setup_dns {
    my ($zone) = @_;
    my $file = "/data/zone/${zone}/root/etc/resolv.conf";
    open(RESOLV, ">${file}");
    print RESOLV "domain test.example.com\n";
    print RESOLV "nameserver 192.168.100.14\n";
    print RESOLV "search test.example.com example.com\n";
    close(RESOLV);
    chmod 0644, $file;
    &cp("/data/zone/${zone}/root/etc/nsswitch.dns", "/data/zone/${zone}/root/etc/nsswitch.conf");
}

sub setup_nfs {
    my ($zone) = @_;
    &mod_file_value("/data/zone/${zone}/root/etc/default/nfs", "NFSMAPIP_DOMAIN", "test.example.com");
    open(DONE, ">/data/zone/${zone}/root/etc/.NFS4inst_state.domain");
    close(DONE);
}

sub setup_power_mgmt {
    my ($zone) = @_;
    open(DONT, ">/data/zone/${zone}/root/noautoshutdown");
    close(DONT);
}

sub setup_nodename {
    my ($zone) = @_;
    my $file = "/data/zone/${zone}/root/etc/nodename";
    open(NODENAME, ">${file}");
    print NODENAME "${zone}\n";
    close(NODENAME);
    chmod 0644, $file;
}

sub setup_sysid_state {
    my ($zone) = @_;
    my $file = "/data/zone/${zone}/root/etc/.sysIDtool.state";
    open(SYSID, ">${file}");
    print SYSID "1       # System previously configured?\n";
    print SYSID "0       # Bootparams succeeded?\n";
    print SYSID "1       # System is on a network?\n";
    print SYSID "0       # Extended network information gathered?\n";
    print SYSID "1       # Autobinder succeeded?\n";
    print SYSID "1       # Network has subnets?\n";
    print SYSID "1       # root password prompted for?\n";
    print SYSID "1       # locale and term prompted for?\n";
    print SYSID "1       # security policy in place\n";
    print SYSID "1       # NFSv4 domain configured\n";
    print SYSID "xterms\n";
    close(SYSID);
    chmod 0644, $file;
    unlink("/data/zone/${zone}/root/etc/.UNCONFIGURED");
}

sub mod_file_value {
    my ($file, $var, $setting) = @_;
    if (! -f $file) { return; }
    if ($debug) { print STDOUT "Editing ${file}\n"; }
    my $found = 0;
    open(CONF, $file);
    open(CONFNEW, ">${file}.temp");
    while (<CONF>) {
        if ($debug) { print STDOUT "conf: $_"; }
        if (/^${var}=/) { # Found our setting, fix it.
            print CONFNEW "${var}=${setting}\n";
            if ($debug) { print STDOUT "conf_fix: ${var}=${setting}\n"; }
            $found++;
        } else {
            print CONFNEW $_;
        }
    }
    close(CONF);
    close(CONFNEW);
    rename("${file}.temp", $file);
    chmod 0644, $file;
    return($found);
}

sub cp {
    my($infile, $outfile) = @_;
    if (!-f $infile) {
        print STDOUT "Error: $infile does not exist!\n";
        exit(1);
    }
    open(CPIN, $infile) || die "Error during copy: opening $infile: $!";
    open(CPOUT, ">$outfile") || die "Error during copy: opening $outfile: $!";
    while(<CPIN>) { print CPOUT $_; }
    close(CPIN);
    close(CPOUT);
    chmod 0644, $outfile;
}