summaryrefslogtreecommitdiffstats
path: root/server_wizard/scripts/Serverconf.pm
blob: 4f70e74a27c66746587016198a7155d9056ab7b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/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 (<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;
	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;