#!/usr/bin/perl package Serverconf; require "__WIZ_HOME__/common/scripts/Vareqval.pm"; use MDK::Common; use strict; sub do_it_last { my $file = "/etc/sysconfig/mdk_serv"; MDK::Common::cp_af($file, $file.".orig"); my $date = `date`; open(NEW, "> $file"); print NEW "#mdk server basic info $date mdk_serv_version=1.0 wiz_device=$ENV{wiz_device} wiz_host_name=$ENV{wiz_host_name} wiz_domain_name=$ENV{wiz_domain_name}"; } sub do_it { my $old_ip; my $date = `date`; my $file = "/etc/sysconfig/network"; MDK::Common::cp_af($file, $file . ".orig"); my %mdk = Vareqval->get($file); my $wiz_ip_netmask = "255.255.255.0"; $mdk{FORWARD_IPV4} = "yes"; $mdk{HOSTNAME} = $ENV{wiz_host_name} if defined $ENV{wiz_host_name} or die "wiz_host_name not in env"; my $hostname = $mdk{HOSTNAME}; $mdk{DOMAINNAME} = $ENV{wiz_domain_name} if defined $ENV{wiz_host_name} or die "wiz_domain_name not in env"; $mdk{NETWORKING} = "yes"; $mdk{GATEWAYDEV} = $ENV{wiz_extn_device} if defined $ENV{wiz_extn_device} or die "wiz_extn_device not in env"; $mdk{GATEWAY} = $ENV{wiz_extn_gateway} if defined $ENV{wiz_extn_gateway} or die "wiz_extn_gateway not in env"; Vareqval->commit($file, \%mdk); $file = "/etc/sysconfig/network-scripts/ifcfg-$ENV{wiz_device}" if defined $ENV{wiz_device} or die "wiz_device not in env"; if (-f $file) { MDK::Common::cp_af($file, $file . ".orig"); %mdk = Vareqval->get($file); $old_ip = $mdk{IPADDR} if defined $mdk{IPADDR} or die "IPADDR not found in $file"; } else { system("touch $file"); %mdk = Vareqval->get($file); } # starting chg_val sequence $mdk{DEVICE} = $ENV{wiz_device}; $mdk{BOOTPROTO} = "none"; $mdk{IPADDR} = $ENV{wiz_ip_server} if defined $ENV{wiz_ip_server} or die "IPADDR not found in $file"; my $new_ip = $mdk{IPADDR}; $mdk{NETMASK} = $wiz_ip_netmask; $mdk{NETWORK} = $ENV{wiz_ip_net} if defined $ENV{wiz_ip_net} or die "NETWORK not found in $file"; $mdk{ONBOOT} = "yes"; $mdk{IPXNETNUM_802_2} = ""; $mdk{IPXPRIMARY_802_2} = "no"; $mdk{IPXACTIVE_802_2} = "no"; $mdk{IPXNETNUM_802_3} = ""; $mdk{IPXPRIMARY_802_3} = "no"; $mdk{IPXACTIVE_802_3} = "no"; $mdk{IPXNETNUM_ETHERII} = ""; $mdk{IPXPRIMARY_ETHERII} = "no"; $mdk{IPXACTIVE_ETHERII} = "no"; $mdk{IPXNETNUM_SNAP} = ""; $mdk{IPXPRIMARY_SNAP} = "no"; $mdk{IPXACTIVE_SNAP} = "no"; # chg_val sequence ended Vareqval->commit($file, \%mdk); $file = "/etc/HOSTNAME"; MDK::Common::cp_af($file, $file . ".orig"); open(NEW, "> $file") or die "can not open $file"; print NEW "$hostname"; close(NEW) or die "can not close $file"; system("hostname $hostname"); my ($hostalias) = ($hostname =~ /^([^.]*)\..*$/); $file = "/etc/hosts"; MDK::Common::cp_af($file, $file . ".orig"); if (defined $old_ip && $old_ip ne $new_ip) { my $tmp = `mktemp /tmp/Serverconf.XXXXXX`; chomp($tmp); open(OLD, "< $file") or die "can not open $file"; open(NEW, "> $tmp") or die "can not open $tmp"; while () { if (/^\s*(?!\#)*\s*$old_ip.*$/) { print NEW "# removed by mdk_serv script on $date #$_ $new_ip\t$hostname\t$hostalias\n"; next; } print NEW $_; } close OLD; close NEW; system("mv $tmp $file"); } else { open(NEW, ">> $file"); print NEW "$new_ip\t$hostname\t$hostalias\n"; close NEW; } do_it_last(); system("/etc/rc.d/init.d/network stop"); system("/etc/rc.d/init.d/network start"); 10; } 1;