From cccf5a2ad7f01af191cb0b390b7c3188ba0b254b Mon Sep 17 00:00:00 2001 From: Conrad Lara - KG6JEI Date: Wed, 12 Nov 2014 21:25:41 -0800 Subject: [PATCH] feature: Add the ability to upgrade in place and keep settings. By checking the "Keep Settings" box the node will run sysupgrade instead of mtd. Core settings are stored between installs and the _setup files are updated by pulling in missing items from the _setup.default files. --- files/etc/init.d/local | 2 + files/lib/upgrade/keep.d/bbhn-base | 22 +++++++++ files/usr/local/bin/bbhn-postupgrade | 73 ++++++++++++++++++++++++++++ files/www/cgi-bin/admin | 72 ++++++++++++--------------- 4 files changed, 128 insertions(+), 41 deletions(-) create mode 100644 files/lib/upgrade/keep.d/bbhn-base create mode 100755 files/usr/local/bin/bbhn-postupgrade diff --git a/files/etc/init.d/local b/files/etc/init.d/local index 2f08b314..b94bdcc1 100755 --- a/files/etc/init.d/local +++ b/files/etc/init.d/local @@ -3,6 +3,8 @@ START=99 boot() { + + [ -x /usr/local/bin/bbhn-postupgrade ] && /usr/local/bin/bbhn-postupgrade # extract kamikaze generated vlan config #CMLARA Not needed on BULLETM's maybe needed on other devices diff --git a/files/lib/upgrade/keep.d/bbhn-base b/files/lib/upgrade/keep.d/bbhn-base new file mode 100644 index 00000000..ea161827 --- /dev/null +++ b/files/lib/upgrade/keep.d/bbhn-base @@ -0,0 +1,22 @@ +/etc/config.ap/_setup +/etc/config.ap/_setup.dhcp +/etc/config.ap/_setup.ports +/etc/config.client/_setup +/etc/config.client/_setup.dhcp +/etc/config.client/_setup.ports +/etc/config.mesh/_setup +/etc/config.mesh/_setup.dhcp.dmz +/etc/config.mesh/_setup.dhcp.nat +/etc/config.mesh/_setup.ports.dmz +/etc/config.mesh/_setup.ports.nat +/etc/config.mesh/_setup.services.dmz +/etc/config.mesh/_setup.services.nat +/etc/config.mesh_ap/_setup +/etc/config.mesh_ap/_setup.dhcp +/etc/config.mesh_ap/_setup.ports +/etc/config.router/_setup +/etc/config.router/_setup.dhcp +/etc/config.router/_setup.ports +/etc/httpd.conf +/etc/local/services +/etc/local/uci/hsmmmesh diff --git a/files/usr/local/bin/bbhn-postupgrade b/files/usr/local/bin/bbhn-postupgrade new file mode 100755 index 00000000..ce3f0698 --- /dev/null +++ b/files/usr/local/bin/bbhn-postupgrade @@ -0,0 +1,73 @@ +#!/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/; + $line =~ s//$mac2/; + $line =~ s//$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"); diff --git a/files/www/cgi-bin/admin b/files/www/cgi-bin/admin index 15f69698..0648e2df 100755 --- a/files/www/cgi-bin/admin +++ b/files/www/cgi-bin/admin @@ -174,8 +174,9 @@ if($parms{button_dl_fw} and $parms{dl_fw} ne "default") } } -# install fw -- Force overwrite using MTD device -# Needs a "not $overwrite_firmware" clause once we get sysupgrade working + +# install fw + if($fw_install and -f "$tmpdir/firmware") { my $junk; @@ -185,56 +186,44 @@ if($fw_install and -f "$tmpdir/firmware") print "

The firmware is being updated.

\n"; print "

DO NOT REMOVE POWER UNTIL UPDATE IS FINISHED

\n"; print "
\n"; - print "Writing firmware

\n"; - unless($debug) { - #system "nvram unset config; nvram commit >/dev/null 2>&1"; - nvram_set("config", ""); - open(FILE, "/sbin/mtd write $tmpdir/firmware firmware 2>&1 |") or die; - while(read FILE, $junk, 7) { print "|" } - } - - print " -

The node is rebooting

+ if ( $parms{checkbox_keep_settings} ) + { + nvram_set("nodeupgraded","1"); + print " +

Firmware will be written in the background.

If you are connected to the LAN of this node you may need to acquire a new
DHCP lease and reset any name service caches you may be using.

-

Wait for the Power LED to start blinking, then stop blinking.
-When the DMZ LED turns off you can get your new DHCP lease and reconnect with
+

The node will reboot twice while the configuration is applied
+Wait for the Status 4 LED to start blinking, then stop blinking twice.
+When the Status 4 LED is solid on you can get your new DHCP lease and reconnect with
http://localnode.local.mesh:8080/

"; + open(FILE, "/sbin/sysupgrade -q $tmpdir/firmware 2>&1 |") or die; + } + else + { + print "Writing firmware

\n"; + open(FILE, "/sbin/mtd write $tmpdir/firmware firmware 2>&1 |") or die; + while(read FILE, $junk, 7) { print "|" } + print " +

The node is rebooting

+

If you are connected to the LAN of this node you may need to acquire a new
+DHCP lease and reset any name service caches you may be using.

+

Wait for the Status 4 LED to start blinking, then stop blinking.
+When the Status 4 LED is solid on you can get your new DHCP lease and reconnect with
+http://localnode.local.mesh:8080/

+
+"; + system "/sbin/reboot" unless $debug; - system "/sbin/reboot" unless $debug; + } + } exit; } -# CMLARA: Prepwork for using sysupgrade --- it has some issues with the page not returning that need to be worked on -# install fw -- use sysupgrade - -#if($fw_install and -f "$tmpdir/firmware" and not $overwrite_firmware ) -#{ -# my $junk; -# http_header(); -# html_header("FIRMWARE UPDATE IN PROGRESS", 1); -# print "
\n"; -# print "

The firmware is being updated.



\n"; -# print "

DO NOT REMOVE POWER UNTIL UPDATE IS FINISHED



\n"; -# print "

Wait for the Power LED to start blinking, then stop blinking.
\n"; -# print "When the DMZ LED turns off you can reconnect your browser to the mesh node.

\n"; -# print "

\n"; -# print "Writing firmware

\n"; -# unless($debug) -# { -# open(FILE, "/sbin/sysupgrade -q $tmpdir/firmware 2>&1 |") or die; -# while(read FILE, $junk, 7) { print "|" } -# print "

REBOOTING

\n"; -# print "Click here when the blinking stops and the DMZ LED turns off\n"; -# system "/sbin/reboot"; -# } -# exit; -#} - # install patch if($patch_install and -f "$tmpdir/firmware") @@ -498,6 +487,7 @@ foreach(@fw_images) print "\n"; print "\n"; print "\n"; +print "Keep Settings\n"; print "\n"; print "\n";