Skip to content

Commit

Permalink
fix module update on redmatic update, cleanup packet management
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Mar 24, 2019
1 parent 7d5baa5 commit 9b2caa6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
3 changes: 3 additions & 0 deletions addon_files/redmatic/bin/redmatic
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Stop () {
}

Start () {
if [ -f $ADDON_DIR/var/do_pkg_update ]; then
$ADDON_DIR/bin/redmatic-pkg upgrade >> $ADDON_DIR/var/pkg-upgrade.log
fi
if ! grep -Fq "/etc/config/lighttpd/" $LIGHTTPD_CONF
then
echo "patching $LIGHTTPD_CONF"
Expand Down
39 changes: 35 additions & 4 deletions addon_files/redmatic/bin/redmatic-pkg
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ source $ADDON_DIR/home/.profile

function usage()
{
echo "Usage: redmatic-pkg <command> <package>"
echo "Usage: redmatic-pkg <command> [package]"
echo "commands:"
echo " install"
echo " remove"
echo " install <package>"
echo " install or update a package"
echo " upgrade"
echo " update all packages"
echo " remove <package>"
echo ""
}

Expand All @@ -26,13 +29,26 @@ function install()
exit 1
fi

if [ -f $ADDON_DIR/lib/node_modules/$PACKAGE/package.json ]; then
CURRENT_VERSION=`jq -r ".version" $ADDON_DIR/lib/node_modules/$PACKAGE/package.json`
if [ $CURRENT_VERSION == $VERSION ]; then
echo "$PACKAGE up-to-date"
exit 0
else
echo "$PACKAGE $CURRENT_VERSION -> $VERSION"
fi
fi

echo "Get $URL"
curl $URL -o $ADDON_DIR/tmp/$1.tar.gz --fail --silent --show-error --location || exit 1

rm -r $ADDON_DIR/lib/node_modules/$PACKAGE 2> /dev/null

echo "Extracting $1.tar.gz"
(cd $ADDON_DIR ; tar --no-same-owner -xzf tmp/$1.tar.gz && rm tmp/$1.tar.gz && echo "Done.")
(cd $ADDON_DIR ; tar --no-same-owner -xzf tmp/$1.tar.gz) || exit 1

rm $ADDON_DIR/tmp/$1.tar.gz
echo "Done."
}

function remove()
Expand All @@ -42,6 +58,17 @@ function remove()
echo "Done."
}

function upgrade()
{
RESULT=0
for k in $($ADDON_DIR/bin/jq -r '. | to_entries[] | "\(.key)"' $ADDON_DIR/lib/pkg-repo.json); do
if [ -d $ADDON_DIR/lib/node_modules/$k ]; then
$ADDON_DIR/bin/redmatic-pkg install $k 2>&1 || RESULT=1
fi
done
exit $RESULT
}


case $1 in
i | install)
Expand All @@ -52,6 +79,10 @@ case $1 in
remove $2
exit
;;
upgrade)
upgrade
exit
;;
*)
usage
exit 1
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions addon_files/redmatic/www/log.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ if {[info exists sid] && [check_session $sid]} {
catch {exec /usr/local/addons/redmatic/bin/redmaticVersions} result
puts $result
puts ""
if {[file exists /usr/local/addons/redmatic/var/pkg-update.log]} {
catch {exec cat /usr/local/addons/redmatic/var/pkg-update.log} result
if {[file exists /usr/local/addons/redmatic/var/pkg-upgrade.log]} {
catch {exec cat /usr/local/addons/redmatic/var/pkg-upgrade.log} result
puts $result
puts ""
}
Expand Down
19 changes: 7 additions & 12 deletions addon_files/update_script
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ if [ -f $CONF_DIR/rc.d/redmatic ]; then
$CONF_DIR/rc.d/redmatic stop
fi

#
# Upgrade packages on update
#
if [ -d $RED_DIR/var ]; then
touch $RED_DIR/var/do_pkg_upgrade
fi

#
# Rename extra nodes package.json on update
#
Expand Down Expand Up @@ -110,18 +117,6 @@ if [ -d $RED_DIR/var/node_modules/redmatic-homekit ]; then
rm $RED_DIR/var/package.json.bak
fi


#
# Update existing modules in lib/node_modules on update
#
echo $(date +'[%Y-%m-%d %H:%M:%S]') > $RED_DIR/var/pkg-update.log
for k in $($RED_DIR/bin/jq -r '. | to_entries[] | "\(.key)"' $RED_DIR/lib/pkg-repo.json); do
if [ -d $RED_DIR/lib/node_modules/$k ]; then
$RED_DIR/bin/redmatic-pkg install $k >> $RED_DIR/var/pkg-update.log 2>&1
fi
done


#
# Remove package-lock
#
Expand Down

0 comments on commit 9b2caa6

Please sign in to comment.