Public Jet Config Script

From JetResources
Jump to: navigation, search

Parent

Jumpstart Configuration Script

This is a script which will check and configure the jumpstart environment, including tweaking JET configs to suit the example.com standards.

It does a number of things automatically for you:

Creates the jumpstart media, patch and package tree
</DD>
Updates the JET /opt/SUNWjet/etc/jumpstart.conf configuration file
</DD>
Updates the JET /opt/SUNWjet/Products/<module>/<module>.conf configuration files with various values
</DD>
Adds the NFS shares required
</DD>
Puts the hook into /opt/SUNWjet/Products/zones/postinstall for the zone sysidcfg script
</DD>
Adds a final reboot to /opt/SUNWjet/Utils/S99jumpstart
</DD>
Adds the latest Sun Explorer version (5.10) to /opt/SUNWjet/Products/explo/package.matrix
</DD>
Tweaks some file permissions in /etc (a personal habit)
</DD>
Updates host template files in /opt/SUNWjet/Templates
</DD>
It's this last step which I find to be the most useful part of this script. Each time you mess with the JET /opt/SUNWjet/Products/base_config/solaris/base_config.conf file you have to rebuild the host templates and thus re-edit them too. Having this script do it for you takes care of some of the repetitive work in setting up hosts. #!/usr/bin/perl ############################################################################# # Program  : jumpstart_config.pl # Author  : Mark Ashley mark at ibiblio dot org # Version  : 1.4 # Initial Date  : 4th December 2007 # Modified Date : 9th January 2008 # Purpose  : Setup Jumpstart environment. Can be safely re-run any time. ############################################################################# use POSIX; $JS_TOP_DIR = '/data/jumpstart'; $JET_TOP_DIR = '/opt/SUNWjet'; # Current version of Sun Explorer my $explo_ver="5.10"; ($c_kernel, $c_hostname, $c_release, $c_version, $c_hardware) = uname(); $| = 1; $uid = 0; $gid = 0; my $verbose = 0; if ($ARGV[0] eq '-v') { $verbose++; } if ($ARGV[0] eq '--verbose') { $verbose++; } if ($ARGV[0] eq '-d') { $debug++; } if ($ARGV[0] eq '--debug') { $debug++; } if ($ARGV[0] eq '-h') { &usage; exit(0); } if ($ARGV[0] eq '--help') { &usage; exit(0); } # &create_dir($JS_TOP_DIR, $uid, $gid); &create_dir("${JS_TOP_DIR}/media", $uid, $gid); &create_dir("${JS_TOP_DIR}/pkgs", $uid, $gid); &create_dir("${JS_TOP_DIR}/patches", $uid, $gid); # &setup_jumpstart_conf("JS_PKG_DIR", "${JS_TOP_DIR}/pkgs"); &setup_jumpstart_conf("JS_PATCH_DIR", "${JS_TOP_DIR}/patches"); &setup_jumpstart_conf("JS_SOLARIS_DIR", "${JS_TOP_DIR}/media"); &setup_jumpstart_conf("JS_DHCP_VENDOR", '"SUNW.Sun-Fire-T200 SUNW.Netra-T2000 SUNW.Sun-Fire-T1000 SUNW.Sun-Fire-V490 SUNW.Ultra-5_10 SUNW.Ultra-30 SUNW.UltraSPARC-IIi-cEngine SUNW.Sun-Fire-880 SUNW.Netra-440 SUNW.Netra-240 SUNW.Sun-Fire-V240 SUNW.Sun-Fire-V440 SUNW.UltraAX-i2 SUNW.i86pc"'); &setup_jumpstart_conf("JS_CLIENT_MANAGEMENT", '"dhcp grub"'); # &setup_dhcp_conf("DHCPDIR", "\"${JS_TOP_DIR}/media\""); # &setup_module_conf("explo", "explo_product_version", '"5.10"'); &setup_module_conf("explo", "explo_override_old_installs", '"yes"'); &setup_module_conf("explo", "explo_CRONTAB_RUN", '"yes"'); &setup_module_conf("explo", "explo_CRONTAB_HOUR", '"1"'); &setup_module_conf("explo", "explo_CRONTAB_MINUTE", '"1"'); &setup_module_conf("explo", "explo_CRONTAB_WEEKDAY", '"1"'); &setup_module_conf("explo", "explo_CONTRACT_ID", '"Unknown"'); &setup_module_conf("explo", "explo_CUSTOMER_NAME", '"Example Company"'); &setup_module_conf("explo", "explo_USER_NAME", '"Mark Ashley"'); &setup_module_conf("explo", "explo_USER_EMAIL", '"mark at ibiblio dot org"'); &setup_module_conf("explo", "explo_PHONE", '"+1-800-EAT-FOOD"'); &setup_module_conf("explo", "explo_ADDRESS_1", '"123 Smith St"'); &setup_module_conf("explo", "explo_ADDRESS_CITY", '"Sydney"'); &setup_module_conf("explo", "explo_ADDRESS_STATE", '"NSW"'); &setup_module_conf("explo", "explo_ADDRESS_COUNTRY", '"Australia"'); &setup_module_conf("explo", "explo_ADDRESS_ZIP", '"2000"'); &setup_module_conf("explo", "explo_RUN", '"Y"'); &setup_module_conf("explo", "explo_GEO", '"APAC"'); &setup_module_conf("explo", "explo_ADDRESS_COUNTRY_CODE", '"AU"'); &setup_explo_version; # &setup_base_conf("solaris", "base_config_sysidcfg_timeserver", '"192.168.100.14"'); # &setup_base_conf("solariszone", "base_config_sysidcfg_nameservice", '"DNS { domain_name=test.example.com name_server=192.168.100.14 search=test.example.com }"'); &setup_base_conf("solariszone", "base_config_dns_domain", '"test.example.com"'); &setup_base_conf("solariszone", "base_config_dns_nameservers", '"192.168.100.14"'); &setup_base_conf("solariszone", "base_config_sysidcfg_timeserver", '"192.168.100.14"'); &setup_base_conf("solariszone", "base_config_dns_searchpath", '"test.example.com example.com"'); &setup_base_conf("solariszone", "base_config_enable_rootlogin", '"yes"'); &setup_base_conf("solariszone", "base_config_zone_whole_root_zone", '"yes"'); &setup_base_conf("solariszone", "custom_packages", '"SMCsudo"'); # &setup_module_conf("zones", "zones_default_path", '"/data/zone"'); # &setup_module_conf("sds", "sds_device_numbers", '"/:d10:d11:d12 /var:d20:d21:d22 /data:d30:d31:d32"'); # &setup_module_conf("san", "san_product_version", '"default"'); # &setup_module_conf("custom", "custom_packages", '"SMCsudo"'); if ($c_hostname eq "jumphost") { # Test machines only &setup_module_conf("custom", "custom_files", '"my_custom.tar:o:/var/tmp/my_custom.tar no_zone_sysidcfg:o:/var/tmp/no_zone_sysidcfg"'); &setup_module_conf("custom", "custom_scripts_n", '"install_root_config install_sysadmin_config install_sudo_config"'); } # &setup_jumpstart_share($JS_TOP_DIR); &add_post_zone_script; # &setup_host_conf("hostd01", "base_config_sysidcfg_default_route", '"192.168.205.1"'); &setup_host_conf("hostd01", "base_config_nodename", '"hostd01"'); &setup_host_conf("hostd01", "base_config_defaultrouter", '"192.168.205.1"'); &setup_host_conf("hostd01", "zones_names", '"hostd01-zone1"'); # &setup_host_conf("hostd02", "base_config_sysidcfg_default_route", '"192.168.205.1"'); &setup_host_conf("hostd02", "base_config_nodename", '"hostd02"'); &setup_host_conf("hostd02", "base_config_defaultrouter", '"192.168.205.1"'); &setup_host_conf("hostd02", "zones_names", '"hostd02-zone1"'); # &setup_host_conf("hosta01", "base_config_client_allocation", '"grub"'); &setup_host_conf("hosta01", "base_config_sysidcfg_default_route", '"192.168.204.1"'); &setup_host_conf("hosta01", "base_config_nodename", '"hosta01"'); &setup_host_conf("hosta01", "zones_names", '"hosta01-zone1 hosta01-zone2 hosta01-zone3 hosta01-zone4"'); &setup_host_conf("hosta01", "base_config_ipmp_networkifs", '"nge0_nge1 e1000g0_e1000g1"'); &setup_host_conf("hosta01", "base_config_ipmp_networkif_nge0_nge1", '"ipmp0 sp 192.168.204.4 192.168.204.5 26 hosta01 192.168.204.6"'); &setup_host_conf("hosta01", "base_config_ipmp_networkif_e1000g0_e1000g1", '"ipmp1 sp 192.168.105.35 192.168.105.36 27 hosta01-stor 192.168.105.37"'); # &setup_host_conf("hosta01-zone1", "custom_packages", '""'); &setup_host_conf("hosta01-zone1", "base_config_nodename", '"hosta01-zone1"'); &setup_host_conf("hosta01-zone2", "custom_packages", '""'); &setup_host_conf("hosta01-zone2", "base_config_nodename", '"hosta01-zone2"'); &setup_host_conf("hosta01-zone3", "custom_packages", '""'); &setup_host_conf("hosta01-zone3", "base_config_nodename", '"hosta01-zone3"'); &setup_host_conf("hosta01-zone4", "custom_packages", '""'); &setup_host_conf("hosta01-zone4", "base_config_nodename", '"hosta01-zone4"'); # &setup_host_conf("hosta01-zone4", "base_config_networkifs", '"nge0_5 255.255.255.192 hosta01-zone4 192.168.204.60"'); # &setup_host_conf("hosta01-zone1", "base_config_networkifs", '"nge0_2 255.255.255.192 hosta01-zone1 192.168.204.7"'); # &setup_host_conf("hosta01-zone2", "base_config_networkifs", '"nge0_3 255.255.255.192 hosta01-zone2 192.168.204.58"'); # &setup_host_conf("hosta01-zone3", "base_config_networkifs", '"nge0_4 255.255.255.192 hosta01-zone3 192.168.204.59"'); # &setup_host_conf("hostas1", "base_config_client_allocation", '"grub"'); &setup_host_conf("hostas1", "base_config_sysidcfg_default_route", '"192.168.204.1"'); &setup_host_conf("hostas1", "base_config_nodename", '"hostas1"'); &setup_host_conf("hostas1", "base_config_defaultrouter", '"192.168.204.1"'); &setup_host_conf("hostas1", "zones_names", '"hostas1-svt hostas1-svt2"'); # &setup_host_conf("hostf01", "base_config_sysidcfg_default_route", '"192.168.174.65"'); &setup_host_conf("hostf01", "base_config_nodename", '"hostf01"'); &setup_host_conf("hostf01", "base_config_defaultrouter", '"192.168.174.65"'); &setup_host_conf("hostf01", "zones_names", '"hostf01-zone1 hostf01-zone2 hostf01-zone3 hostf01-zone4"'); &setup_host_conf("hostf01", "base_config_ipmp_networkifs", '"e1000g0_e1000g1 e1000g2_e1000g3"'); &setup_host_conf("hostf01", "base_config_ipmp_networkif_e1000g0_e1000g1", '"ipmp0 s 192.168.174.68 192.168.174.69 26 hostf01 192.168.174.70"'); &setup_host_conf("hostf01", "base_config_ipmp_networkif_e1000g2_e1000g3", '"ipmp1 s 192.168.105.3 192.168.105.4 27 hostf01-stor 192.168.105.5"'); &setup_host_conf("hostf01-zone1", "custom_packages", '""'); &setup_host_conf("hostf01-zone1", "base_config_nodename", '"hostf01-zone1"'); # &setup_host_conf("hostf01-zone1", "base_config_networkifs", '"e1000g0_2 255.255.255.192 hostf01-zone1 192.168.174.71"'); &setup_host_conf("hostf01-zone2", "custom_packages", '""'); &setup_host_conf("hostf01-zone2", "base_config_nodename", '"hostf01-zone2"'); # &setup_host_conf("hostf01-zone2", "base_config_networkifs", '"e1000g0_3 255.255.255.192 hostf01-zone2 192.168.174.122"'); &setup_host_conf("hostf01-zone3", "custom_packages", '""'); &setup_host_conf("hostf01-zone3", "base_config_nodename", '"hostf01-zone3"'); # &setup_host_conf("hostf01-zone3", "base_config_networkifs", '"e1000g0_4 255.255.255.192 hostf01-zone3 192.168.174.123"'); &setup_host_conf("hostf01-zone4", "custom_packages", '""'); &setup_host_conf("hostf01-zone4", "base_config_nodename", '"hostf01-zone4"'); # &setup_host_conf("hostf01-zone4", "base_config_networkifs", '"e1000g0_5 255.255.255.192 hostf01-zone4 192.168.174.124"'); # chmod 0644, "/etc/hosts", "/etc/services", "/etc/passwd", "/etc/rpc"; chmod 0644, "/etc/group", "/etc/netmasks", "/etc/networks"; # exit(0); ############################################################################# sub create_dir { my ($dir, $uid, $gid) = @_; if (! -d $dir) { mkdir $dir, 0755; } chown $uid, $gid, $dir; } sub usage { print STDOUT "$0 -v : verbose output\n"; print STDOUT "$0 -h : this help\n"; } sub setup_jumpstart_conf { # Adjust settings for JET jumpstart.conf my ($var, $setting) = @_; &mod_file_value("${JET_TOP_DIR}/etc/jumpstart.conf", $var, $setting); } sub setup_dhcp_conf { # Adjust settings for JET dhcp.conf my ($var, $setting) = @_; &mod_file_value("${JET_TOP_DIR}/etc/dhcp.conf", $var, $setting); } sub setup_base_conf { # Tweak module values to Example Company values my ($config, $var, $setting) = @_; if (! -d "${JET_TOP_DIR}/Products/base_config") { print STDOUT "WARNING: JET base_config module not present in ${JET_TOP_DIR}/Products\n"; return; } if ($config eq "solaris") { &mod_file_value("${JET_TOP_DIR}/Products/base_config/solaris/base_config.conf", $var, $setting); } if ($config eq "solariszone") { &mod_file_value("${JET_TOP_DIR}/Products/base_config/solariszone/base_config.conf", $var, $setting); } } sub setup_module_conf { # Tweak module values to Example Company values my ($module, $var, $setting) = @_; if (! -d "${JET_TOP_DIR}/Products/${module}") { print STDOUT "WARNING: JET ${module} module not present in ${JET_TOP_DIR}/Products\n"; return; } &mod_file_value("${JET_TOP_DIR}/Products/${module}/${module}.conf", $var, $setting); } sub setup_host_conf { # Tweak host values to Example Company values my ($host, $var, $setting) = @_; if (! -f "${JET_TOP_DIR}/Templates/${host}") { return; } my $done = &mod_file_value("${JET_TOP_DIR}/Templates/${host}", $var, $setting); if (! $done) { open(CONFNEW, ">>${JET_TOP_DIR}/Templates/${host}"); print CONFNEW "${var}=${setting}\n"; close(CONFNEW); } } 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 add_post_zone_script { my $found = 0; open(PI, "/opt/SUNWjet/Products/zones/postinstall"); while (<PI>) { if (/no_zone_sysidcfg/) { $found++; } } close(PI); if (!$found) { open(PI, ">>/opt/SUNWjet/Products/zones/postinstall"); print PI "/var/tmp/no_zone_sysidcfg\n"; } close(PI); } sub setup_jumpstart_share { # Add NFS shares for jumpstart server my ($js_share) = @_; my $found_share = 0; open(DFSTAB, "/etc/dfs/dfstab"); while (<DFSTAB>) { chomp; next if (/^#/); if ($debug) { print STDOUT "dfstab: $_\n"; } if (/ ${js_share}$/) { $found_share++; if ($debug) { print STDOUT "dfstab: found ${js_share} share\n"; } } } close(DFSTAB); if (! $found_share) { open(DFSTAB, ">>/etc/dfs/dfstab"); print DFSTAB "share -F nfs -o ro,anon=0 ${js_share}\n"; close(DFSTAB); `/usr/sbin/unshareall`; `/usr/sbin/shareall`; } } sub setup_explo_version { # Add current SUNWexplo version to explo package.matrix if (! -d "${JET_TOP_DIR}/Products/explo") { print STDOUT "WARNING: JET explo module not present in ${JET_TOP_DIR}/Products\n"; return; } my $os_rev = `/bin/uname -r`; chomp($os_rev); my $explo_ver_found = 0; open(PKGMATRIX, "${JET_TOP_DIR}/Products/explo/package.matrix"); while (<PKGMATRIX>) { chomp; if (/^${os_rev}:${explo_ver}:/) { $explo_ver_found++; } } close(PKGMATRIX); if (! $explo_ver_found) { open(PKGMATRIX, ">>${JET_TOP_DIR}/Products/explo/package.matrix"); print PKGMATRIX "${os_rev}:${explo_ver}:SUNWexplo SUNWexplu\n"; close(PKGMATRIX); } }