Skip to content

Commit bca0732

Browse files
authored
Introduce "update grom github" feature
1 parent 7f69e91 commit bca0732

File tree

2 files changed

+102
-5
lines changed

2 files changed

+102
-5
lines changed

wizard-run

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
#
44
# EdgeMAX Wizard "OLSRd_V1" created 03/2016 by Onetrix.net for FunkFeuer.at
5-
# Version [cpo0903e/20170317]
5+
# Version [cpo0903f/20170322]
6+
# ^-- previous line is used frombmk-webstatus-package as version identification, dont remove "Version "
67
#
78
# Github repository: https://github.com/vchrizz/ER-wizard-OLSRd_V1/
89
#
@@ -63,6 +64,11 @@ olsrdmirror="http://ftp.de.debian.org/debian/pool/main/o/olsrd/olsrd_0.6.6.2-1_$
6364
olsrdplgmirror="http://ftp.de.debian.org/debian/pool/main/o/olsrd/olsrd-plugins_0.6.6.2-1_$arch.deb"
6465
olsrdsetupscriptfile="/config/scripts/post-config.d/olsrd_setup.sh"
6566

67+
#define update sources on github
68+
gitowner="vchrizz"
69+
gitrepo="ER-wizard-OLSRd_V1"
70+
gitbranch="master"
71+
6672
#
6773
# DO NOT EDIT BELOW HERE !
6874
#
@@ -19453,14 +19459,46 @@ load () {
1945319459
fi
1945419460
olsrd6plugins=$olsrd6plugins$olsrd6plgtxtinfo$olsrd6plgjsoninfo$olsrd6plghttpinfo
1945519461

19462+
####### wizard version check against github
19463+
#
19464+
olsrdwizard=""
19465+
for i in $(find /config/wizard/feature/ -name wizard.html | grep -i olsr); do
19466+
if [[ $(head $i -n 10 | grep 'OLSRd_V1') ]]; then
19467+
olsrdwizard=$i
19468+
break
19469+
fi
19470+
done
19471+
if [ ! $olsrdwizard ]; then
19472+
updatetext="error: OLSRd_V1 wizard.html not found!" >>$log 2>>$log
19473+
else
19474+
CURRENTVERSION=$(head -n 8 $olsrdwizard | grep -i versioninfo= | awk -F"=" {'print $2'})
19475+
if [ $((onlinecheck)) = 0 ]; then
19476+
GITVERSION=$(curl -sL https://raw.githubusercontent.com/$gitowner/$gitrepo/$gitbranch/wizard.html | head -n 8 | grep -i versioninfo= | awk -F"=" {'print $2'})
19477+
if [ "$GITVERSION" ] && [ "$CURRENTVERSION" ]; then
19478+
if [ $(($GITVERSION)) \> $(($CURRENTVERSION)) ]; then
19479+
updatetext="new version available: "$GITVERSION", current: "$CURRENTVERSION >>$log 2>>$log
19480+
else
19481+
updatetext="current version "$CURRENTVERSION" is up-to-date" >>$log 2>>$log
19482+
fi
19483+
else
19484+
updatetext="version info not available. git:"$GITVERSION", current: "$CURRENTVERSION"." >>$log 2>>$log
19485+
fi
19486+
else
19487+
updatetext="version info not available. git:OFFLINE, current: "$CURRENTVERSION"." >>$log 2>>$log
19488+
fi
19489+
fi
19490+
updatestatus='"updatestatus":"'$updatetext'"'
19491+
# end
19492+
####### wizard version check against github
19493+
1945619494
#
1945719495
# get all variables together for output
1945819496
#
1945919497
ipv4conf="$olsrd4enabled$olsrd4runonboot$olsrd4ip4broadcast$olsrd4hna$olsrd4lqmult$olsrd4plugins\"olsrd4config\":[$olsrd4interfaces]"
1946019498
#ipv6conf="$olsrd6enabled$olsrd6runonboot$olsrd6ip6multicastsite$olsrd6ip6multicastglobal$olsrd6hna$olsrd6lqmult\"olsrd6config\":[$olsrd6interfaces]"
1946119499
ipv6conf="$olsrd6enabled$olsrd6runonboot$olsrd6hna$olsrd6lqmult$olsrd6plugins\"olsrd6config\":[$olsrd6interfaces]"
1946219500
###echo -n "{\"success\":\"1\",\"data\":{ \"olsrdstatus\":[{$olsrdpkgstatus,$olsrddaemonstatus}],$ipv4conf,$ipv6conf },"
19463-
echo -n "{\"success\":\"1\",\"data\":{ $olsrdpkgstatus,$olsrddaemonstatus,$olsrdsetupscript,$ipv4conf,$ipv6conf },"
19501+
echo -n "{\"success\":\"1\",\"data\":{ $olsrdpkgstatus,$olsrddaemonstatus,$olsrdsetupscript,$updatestatus,$ipv4conf,$ipv6conf },"
1946419502
#echo "\"definition\":{ \"olsrd4interface\":$ilist, \"ipv4address\":$ipv4list, \"olsrd6interface\":$ilist, \"ipv6address\":$ipv6list }}"
1946519503
echo "\"definition\":{ }}"
1946619504
}
@@ -19783,6 +19821,45 @@ ENDSCRIPTCONTENT
1978319821
fi
1978419822
fi
1978519823

19824+
####### wizard manual update from github
19825+
# update wizard from github
19826+
# load actual sources (ignoring releases)
19827+
updatefromgithub=$(jq -M -r '.updatefromgithub' $INPUT)
19828+
if [[ "$updatefromgithub" == "on" ]]; then
19829+
echo "update from github requested" >>$log 2>>$log
19830+
olsrdwizard=""
19831+
for i in $(find /config/wizard/feature/ -name wizard.html | grep -i olsr); do
19832+
if [[ $(head $i -n 10 | grep 'OLSRd_V1') ]]; then
19833+
olsrdwizard=$i
19834+
break
19835+
fi
19836+
done
19837+
if [ ! $olsrdwizard ]; then
19838+
echo "error: OLSRd_V1 wizard.html not found!" >>$log 2>>$log
19839+
elif [ $((onlinecheck)) != 0 ]; then
19840+
echo "currently offline" >>$log 2>>$log
19841+
else
19842+
curl -sL -o /tmp/ER-wizard-OLSRd_V1_latest.tar.gz --connect-timeout 2 https://api.github.com/repos/$gitowner/$gitrepo/tarball >>$log 2>>$log
19843+
tar -xvzf /tmp/ER-wizard-OLSRd_V1_latest.tar.gz -C /tmp >/tmp/result.txt 2>>$log
19844+
rm -f /tmp/ER-wizard-OLSRd_V1_latest.tar.gz >>$log 2>>$log
19845+
while read LINE; do
19846+
set $LINE
19847+
if [ $(basename $LINE) == "wizard-run" ] || [ $(basename $LINE) == "wizard.html" ] || [ $(basename $LINE) == "validator.json" ]; then W=1; else W=2; fi
19848+
[ -f "/tmp/"$LINE ] && [ $W == "1" ] && cp "/tmp/"$LINE $(dirname $olsrdwizard)"/"$(basename $LINE) >>$log 2>>$log
19849+
done < /tmp/result.txt
19850+
rm /tmp/result.txt >>$log 2>>$log
19851+
rm -Rf /tmp/$gitowner-$gitrepo* >>$log 2>>$log
19852+
chmod 755 $(dirname $olsrdwizard)"/"wizard-run >>$log 2>>$log
19853+
# before current WebGui session will break due to olsrd-install/restart, send success to browser
19854+
echo "{\"success\":\"1\"}"
19855+
ret="99"
19856+
$(dirname $olsrdwizard)"/"wizard-run load >>$log 2>>$log
19857+
echo "EdgeMAX OLSRd_V1 Wizard stopped $(date +%H:%M:%S.%N)" >> $log
19858+
fi
19859+
fi
19860+
# end
19861+
####### wizard manual update from github
19862+
1978619863
olsrdrestartnow=$(jq -M -r '.olsrdrestartnow' $INPUT)
1978719864
olsrdrestart6now=$(jq -M -r '.olsrdrestart6now' $INPUT)
1978819865
if [[ "$olsrdrestartnow" == "on" ]]; then
@@ -19797,7 +19874,12 @@ ENDSCRIPTCONTENT
1979719874
# for debugging purposes
1979819875
cp $INPUT /tmp/result.json
1979919876

19800-
echo '{"success":"1"}'
19877+
if [ "$ret" == "99" ]; then
19878+
echo "result already sent, so do nothing here" >/dev/null
19879+
else
19880+
echo '{"success":"1"}'
19881+
fi
19882+
1980119883
}
1980219884

1980319885
case "$ACTION" in

wizard.html

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<!--
22
33
EdgeMAX Wizard "OLSRd_V1" created 03/2016 by Onetrix.net for FunkFeuer.at
4-
54
Works on EdgeRouter and EdgeRouter X / X-SFP (system version 1.7.0+)
5+
versioninfo=201703220
6+
^-- use version identifier as number: YYYYMMDDX whereas X can be intraday-version
67
78
-->
89
<div class="instructions">
@@ -12,13 +13,15 @@ <h3>Optimized Link State Routing Protocol</h3>
1213
</div>
1314
<legend style="position:absolute;right:0px;padding:5px;">
1415
<center>EdgeMAX Wizard "OLSRd_V1" created 2016<br>by <a href="http://onetrix.net" target="_blank">Onetrix.net</a> for <a href="http://funkfeuer.at" target="_blank">FunkFeuer.at</a>
15-
<br>Version [cpo0903e/20170317]</center>
16+
<br>Version [cpo0903f/20170322]</center>
1617
</legend>
1718
<div style="padding:15px;border: 1px solid lightgray;width:648px">
1819
<table border="0">
1920
<tr><td style="vertical-align:middle">Package Status:</td><td><input style="right:10px" id="pkgstatus" name="pkgstatus" type="text" size="80" disabled /></td></tr>
2021
<tr><td style="vertical-align:middle">Daemon Status:</td><td><input style="right:10px" id="daemonstatus" name="daemonstatus" type="text" size="80" disabled /></td></tr>
22+
<tr><td style="vertical-align:middle">Update Info:</td><td><input style="right:10px" id="updatestatus" name="updatestatus" type="text" size="80" disabled /></td></tr>
2123
<tr><td><div><span><input id="olsrdsetupscript" name="olsrdsetupscript" type="checkbox" />&nbsp;</span></div><div><span class="text" data-infotip='When updating the Firmware, OLSR package gets lost (only data from /config/ directory will be copied over to newly installed system). Enable this Setup-Script to install and setup OLSRd with your current running-configuration after a Firmware upgrade. WARNING: DO NOT remove OLSRd Wizard if Setup-Script is enabled because it uses functions from this Wizard for setup.'>Setup Script</span></div></td></tr>
24+
<tr><td><div><span><input id="updatefromgithub" name="updatefromgithub" type="checkbox" />&nbsp;</span></div><div><span class="text" data-infotip='When checken, the wizard will download and install the current version from github. During this process, olsr daemons will update and restart as well - this will interupt current connections for a couple of seconds. You need to refresh the EdgeRouter WebUI afterwards, as the browser session will need a restart.'>Upgrade Wizard on 'Apply'.</span></div></td></tr>
2225
</table>
2326
</div>
2427
<fieldset id="ipv4olsrd" name="ipv4olsrd" class="primary expanded">
@@ -201,6 +204,16 @@ <h3>Optimized Link State Routing Protocol</h3>
201204
input.style.color = "green";
202205
enable();
203206
}
207+
var input = document.getElementById('updatestatus');
208+
input.style.color = "black";
209+
document.getElementById('updatefromgithub').disabled = true;
210+
if (input.value.match(/new version available/)) {
211+
document.getElementById('updatefromgithub').disabled = false;
212+
input.style.color = "red";
213+
} else if (input.value.match(/up-to-date/)) {
214+
input.style.color = "green";
215+
}
216+
document.getElementById('updatestatus').disabled = true;
204217
}
205218
document.onsubmit=function(){
206219
var input = document.getElementById('pkgstatus');
@@ -211,5 +224,7 @@ <h3>Optimized Link State Routing Protocol</h3>
211224
}
212225
document.getElementById('pkgstatus').disabled = true;
213226
document.getElementById('daemonstatus').disabled = true;
227+
document.getElementById('updatefromgithub').disabled = true;
228+
document.getElementById('updatestatus').disabled = true;
214229
}
215230
</script>

0 commit comments

Comments
 (0)