Skip to content

Commit 9b2caa6

Browse files
committed
fix module update on redmatic update, cleanup packet management
1 parent 7d5baa5 commit 9b2caa6

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

addon_files/redmatic/bin/redmatic

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ Stop () {
4141
}
4242

4343
Start () {
44+
if [ -f $ADDON_DIR/var/do_pkg_update ]; then
45+
$ADDON_DIR/bin/redmatic-pkg upgrade >> $ADDON_DIR/var/pkg-upgrade.log
46+
fi
4447
if ! grep -Fq "/etc/config/lighttpd/" $LIGHTTPD_CONF
4548
then
4649
echo "patching $LIGHTTPD_CONF"

addon_files/redmatic/bin/redmatic-pkg

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ source $ADDON_DIR/home/.profile
77

88
function usage()
99
{
10-
echo "Usage: redmatic-pkg <command> <package>"
10+
echo "Usage: redmatic-pkg <command> [package]"
1111
echo "commands:"
12-
echo " install"
13-
echo " remove"
12+
echo " install <package>"
13+
echo " install or update a package"
14+
echo " upgrade"
15+
echo " update all packages"
16+
echo " remove <package>"
1417
echo ""
1518
}
1619

@@ -26,13 +29,26 @@ function install()
2629
exit 1
2730
fi
2831

32+
if [ -f $ADDON_DIR/lib/node_modules/$PACKAGE/package.json ]; then
33+
CURRENT_VERSION=`jq -r ".version" $ADDON_DIR/lib/node_modules/$PACKAGE/package.json`
34+
if [ $CURRENT_VERSION == $VERSION ]; then
35+
echo "$PACKAGE up-to-date"
36+
exit 0
37+
else
38+
echo "$PACKAGE $CURRENT_VERSION -> $VERSION"
39+
fi
40+
fi
41+
2942
echo "Get $URL"
3043
curl $URL -o $ADDON_DIR/tmp/$1.tar.gz --fail --silent --show-error --location || exit 1
3144

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

3447
echo "Extracting $1.tar.gz"
35-
(cd $ADDON_DIR ; tar --no-same-owner -xzf tmp/$1.tar.gz && rm tmp/$1.tar.gz && echo "Done.")
48+
(cd $ADDON_DIR ; tar --no-same-owner -xzf tmp/$1.tar.gz) || exit 1
49+
50+
rm $ADDON_DIR/tmp/$1.tar.gz
51+
echo "Done."
3652
}
3753

3854
function remove()
@@ -42,6 +58,17 @@ function remove()
4258
echo "Done."
4359
}
4460

61+
function upgrade()
62+
{
63+
RESULT=0
64+
for k in $($ADDON_DIR/bin/jq -r '. | to_entries[] | "\(.key)"' $ADDON_DIR/lib/pkg-repo.json); do
65+
if [ -d $ADDON_DIR/lib/node_modules/$k ]; then
66+
$ADDON_DIR/bin/redmatic-pkg install $k 2>&1 || RESULT=1
67+
fi
68+
done
69+
exit $RESULT
70+
}
71+
4572

4673
case $1 in
4774
i | install)
@@ -52,6 +79,10 @@ case $1 in
5279
remove $2
5380
exit
5481
;;
82+
upgrade)
83+
upgrade
84+
exit
85+
;;
5586
*)
5687
usage
5788
exit 1

addon_files/redmatic/var/do_pkg_upgrade

Whitespace-only changes.

addon_files/redmatic/www/log.cgi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ if {[info exists sid] && [check_session $sid]} {
1010
catch {exec /usr/local/addons/redmatic/bin/redmaticVersions} result
1111
puts $result
1212
puts ""
13-
if {[file exists /usr/local/addons/redmatic/var/pkg-update.log]} {
14-
catch {exec cat /usr/local/addons/redmatic/var/pkg-update.log} result
13+
if {[file exists /usr/local/addons/redmatic/var/pkg-upgrade.log]} {
14+
catch {exec cat /usr/local/addons/redmatic/var/pkg-upgrade.log} result
1515
puts $result
1616
puts ""
1717
}

addon_files/update_script

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ if [ -f $CONF_DIR/rc.d/redmatic ]; then
2121
$CONF_DIR/rc.d/redmatic stop
2222
fi
2323

24+
#
25+
# Upgrade packages on update
26+
#
27+
if [ -d $RED_DIR/var ]; then
28+
touch $RED_DIR/var/do_pkg_upgrade
29+
fi
30+
2431
#
2532
# Rename extra nodes package.json on update
2633
#
@@ -110,18 +117,6 @@ if [ -d $RED_DIR/var/node_modules/redmatic-homekit ]; then
110117
rm $RED_DIR/var/package.json.bak
111118
fi
112119

113-
114-
#
115-
# Update existing modules in lib/node_modules on update
116-
#
117-
echo $(date +'[%Y-%m-%d %H:%M:%S]') > $RED_DIR/var/pkg-update.log
118-
for k in $($RED_DIR/bin/jq -r '. | to_entries[] | "\(.key)"' $RED_DIR/lib/pkg-repo.json); do
119-
if [ -d $RED_DIR/lib/node_modules/$k ]; then
120-
$RED_DIR/bin/redmatic-pkg install $k >> $RED_DIR/var/pkg-update.log 2>&1
121-
fi
122-
done
123-
124-
125120
#
126121
# Remove package-lock
127122
#

0 commit comments

Comments
 (0)