diff options
Diffstat (limited to 'server_wizard/scripts/Serverconf.pm')
-rw-r--r-- | server_wizard/scripts/Serverconf.pm | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/server_wizard/scripts/Serverconf.pm b/server_wizard/scripts/Serverconf.pm new file mode 100644 index 00000000..29bd4803 --- /dev/null +++ b/server_wizard/scripts/Serverconf.pm @@ -0,0 +1,108 @@ +#!/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 $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); + my $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`; + open(OLD, "< $file") or die "can not open $file"; + open(NEW, "> $tmp") or die "can not open $tmp"; + while (<OLD>) { + 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, 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"); +} |