Skip to content

Commit

Permalink
addon update check
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Apr 30, 2018
1 parent 8793e52 commit 27d2c5f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions addon_files/node-red/node-red
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ case "$1" in
echo "Info: <ul><li><a href="https://github.com/hobbyquaker/ccu-addon-node-red">ccu-addon-node-red on Github</a></li></ul>"
echo "Name: Node-RED"
echo "Version: $ADDON_VERSION"
echo "Update: /addons/check_update_node_red.cgi"
echo "Operations: restart uninstall"
;;

Expand All @@ -75,6 +76,7 @@ case "$1" in
rm $CONF_DIR/lighttpd/node-red.conf
rm $CONF_DIR/rc.d/node-red
rm /usr/local/bin/node-red-admin
rm /usr/local/etc/config/addons/www/check_update_node_red.cgi
;;

*)
Expand Down
27 changes: 27 additions & 0 deletions addon_files/node-red/update_check.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env tclsh

set checkURL "https://api.github.com/repos/hobbyquaker/ccu-addon-node-red/releases/latest"
set downloadURL "https://github.com/hobbyquaker/ccu-addon-node-red/releases/latest"

catch {
set input $env(QUERY_STRING)
set pairs [split $input &]
foreach pair $pairs {
if {0 != [regexp "^(\[^=]*)=(.*)$" $pair dummy varname val]} {
set $varname $val
}
}
}

if { [info exists cmd ] && $cmd == "download"} {
puts "<html><head><meta http-equiv='refresh' content='0; url=$downloadURL' /></head></html>"
} else {
catch {
[regexp "tag_name\": \"v(\[0-9\]+\.\[0-9\]+\.\[0-9\]+)" [ exec /usr/bin/env wget -qO- --no-check-certificate $checkURL ] dummy newversion]
}
if { [info exists newversion] } {
puts -nonewline $newversion
} else {
puts -nonewline "n/a"
}
}
2 changes: 2 additions & 0 deletions addon_files/update_script
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ if [ ! -f $RED_DIR/var/flows.json ]; then
mv $RED_DIR/var/example-flows.json $RED_DIR/var/flows.json
fi

ln -s $RED_DIR/update_check.tcl /usr/local/etc/config/addons/www/check_update_node_red.cgi

touch $CONF_DIR/hm_addons.cfg
sed -i '/node-red/d' $CONF_DIR/hm_addons.cfg
x=$(tail -c 1 $CONF_DIR/hm_addons.cfg)
Expand Down

0 comments on commit 27d2c5f

Please sign in to comment.