aredn/files/usr/local/bin/bbhn-postupgrade

74 lines
1.6 KiB
Plaintext
Raw Normal View History

#!/usr/bin/perl -w -I/www/cgi-bin
use perlfunc;
$needsrun=nvram_get("nodeupgraded");
if ( ! $needsrun ){
print "Node not upgraded, exiting\n";
exit 0;
}
#Prep some variables
$node = nvram_get("node");
$tactical = nvram_get("tactical");
$mac2 = mac2ip(get_mac("wlan0"), 0);
$dtdmac = mac2ip(get_mac("eth0"), 0);
foreach $config ("ap","client","mesh","mesh_ap","router")
{
$cfg = ();
$defaultcfg = ();
open(TMPCONFFILE, ">/tmp/.${config}_setup") or die;
foreach $line (`cat /etc/config.$config/_setup`)
{
next if $line =~ /^\s*#/;
next if $line =~ /^\s*$/;
$line =~ /^(\w+)\s*=\s*(.*)$/;
$cfg{$1} = $2;
}
foreach $line (`cat /etc/config.$config/_setup.default`)
{
next if $line =~ /^\s*#/;
next if $line =~ /^\s*$/;
$line =~ s/<NODE>/$node/;
$line =~ s/<MAC2>/$mac2/;
$line =~ s/<DTDMAC>/$dtdmac/;
$line =~ /^(\w+)\s*=\s*(.*)$/;
$defaultcfg{$1} = $2;
}
foreach $variable( sort keys %defaultcfg )
{
if ( $cfg{$variable} )
{
print TMPCONFFILE "$variable = $cfg{$variable}\n";
}
else
{
print TMPCONFFILE "$variable = $defaultcfg{$variable}\n";
}
}
close (TMPCONFFILE);
system ("mv /tmp/.${config}_setup /etc/config.$config/_setup");
print "Updated mode: $config\n";
}
$LASTMODE=nvram_get('config');
#Commit the new combined config
system ("/usr/local/bin/node-setup -a $LASTMODE");
nvram_set("nodeupgraded","0");
print "Rebooting node";
system ("reboot");