Skip to content

Commit 2ed2a32

Browse files
authored
Merge pull request #50 from YIO-Remote/feature/app-plugin-update
Initial YIO app plugin update script to install GitHub binary releases.
2 parents adb5cca + bf5cdbf commit 2ed2a32

File tree

14 files changed

+269
-38
lines changed

14 files changed

+269
-38
lines changed
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
#!/bin/bash
2+
#------------------------------------------------------------------------------
3+
# YIO app plugin updater script.
4+
# Called from main the update.sh script and remote-software.
5+
#
6+
# Copyright (C) 2020 Markus Zehnder <business@markuszehnder.ch>
7+
#
8+
# This file is part of the YIO-Remote software project.
9+
#
10+
# YIO-Remote software is free software: you can redistribute it and/or modify
11+
# it under the terms of the GNU General Public License as published by
12+
# the Free Software Foundation, either version 3 of the License, or
13+
# (at your option) any later version.
14+
#
15+
# YIO-Remote software is distributed in the hope that it will be useful,
16+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
# GNU General Public License for more details.
19+
#
20+
# You should have received a copy of the GNU General Public License
21+
# along with YIO-Remote software. If not, see <https://www.gnu.org/licenses/>.
22+
#
23+
# SPDX-License-Identifier: GPL-3.0-or-later
24+
#------------------------------------------------------------------------------
25+
26+
. /etc/profile.d/yio.sh
27+
. $(dirname $0)/lib/common.bash
28+
. $(dirname $0)/lib/util.bash
29+
30+
#------------------------------------------------------------------------------
31+
# Start of script
32+
33+
# check command line arguments
34+
if [ $# -eq 0 ]; then
35+
echo "Usage: $0 update.(version|zip|tar)"
36+
echo " Updates a YIO remote app plugin with the provided update marker file or archive."
37+
echo " The archive may be a zip or tar archive. See wiki for update archive format."
38+
echo " The archive and optional marker file are deleted after a success update!"
39+
exit 1
40+
fi
41+
42+
if [[ $(id -u) -ne 0 ]] ; then
43+
echo "Must be run as root"
44+
exit 1
45+
fi
46+
47+
# handle update marker file which contains a reference to the update archive
48+
if [[ $1 == *.version ]]; then
49+
MARKER_FILE=$1
50+
if [[ ! -f $MARKER_FILE ]]; then
51+
echo "Update marker file not found: $MARKER_FILE"
52+
exit 1
53+
fi
54+
UPDATE_FILE=$(cat "$MARKER_FILE" | awk '/^Update/{print $3}')
55+
if [[ -z $UPDATE_FILE ]]; then
56+
echo "Marker file doesn't contain update archive file reference!"
57+
exit 1
58+
fi
59+
else
60+
UPDATE_FILE=$1
61+
fi
62+
63+
# verify environment
64+
if [[ ! -f $UPDATE_FILE ]]; then
65+
echo "Update archive file not found: $UPDATE_FILE"
66+
exit 1
67+
fi
68+
69+
if [[ $UPDATE_FILE != *.tar && $UPDATE_FILE != *.zip ]]; then
70+
echo "Only tar and zip update archive files are supported: $UPDATE_FILE"
71+
exit 1
72+
fi
73+
74+
assertEnvVariable "YIO_HOME" $YIO_HOME
75+
assertEnvVariable "YIO_PLUGIN_DIR" $YIO_PLUGIN_DIR
76+
assertEnvVariable "YIO_LOG_DIR_UPDATE" $YIO_LOG_DIR_UPDATE
77+
78+
if [[ ! -d $YIO_HOME ]]; then
79+
echo "Installation target does not exist: $YIO_HOME"
80+
exit 1
81+
fi
82+
83+
# TODO check free space?
84+
85+
YIO_SPLASH_DIR=${YIO_MEDIA_DIR}/splash
86+
# write update log into dedicated update log file
87+
mkdir -p $YIO_LOG_DIR_UPDATE
88+
LOGFILE=${YIO_LOG_DIR_UPDATE}/plugin-update.log
89+
90+
echo "Writing update log file: $LOGFILE"
91+
echo "YIO Remote App Plugin Update Log" > $LOGFILE
92+
log "Update archive: $UPDATE_FILE"
93+
log "Installation directory: $YIO_PLUGIN_DIR"
94+
95+
#------------------------------------------------------------------------------
96+
# Start update process!
97+
#------------------------------------------------------------------------------
98+
99+
ensureScreenIsOn "${YIO_SPLASH_DIR}/update.png"
100+
101+
#------------------------------------------------------------------------------
102+
# Extract update archive to temp location
103+
#------------------------------------------------------------------------------
104+
105+
# use ${YIO_HOME} base dir for atomic file operation (/tmp might be on another partition)
106+
TMPDIR=${YIO_HOME}/app-plugin-$(date +"%Y%m%d%H%M%S")
107+
log "Extracting archive to temporary folder: $TMPDIR"
108+
mkdir -p ${TMPDIR} >> $LOGFILE 2>&1
109+
110+
if [[ $UPDATE_FILE == *.tar ]]; then
111+
tar tf "$UPDATE_FILE" > /dev/null || {
112+
log "Invalid tar archive: $UPDATE_FILE"
113+
exit 1
114+
}
115+
116+
tar -xf "$UPDATE_FILE" -C ${TMPDIR} >> $LOGFILE 2>&1
117+
elif [[ $UPDATE_FILE == *.zip ]]; then
118+
unzip -l "$UPDATE_FILE" > /dev/null || {
119+
log "Invalid zip archive: $UPDATE_FILE"
120+
exit 1
121+
}
122+
123+
unzip "$UPDATE_FILE" -d ${TMPDIR} >> $LOGFILE 2>&1
124+
else
125+
log "Only tar and zip update archive files are supported: $UPDATE_FILE"
126+
exit 1
127+
fi
128+
129+
cd ${TMPDIR}
130+
if [[ ! -f md5sums || ! -f app.tar.gz ]]; then
131+
log "Invalid app plugin update archive: $UPDATE_FILE"
132+
exit 1
133+
fi
134+
135+
md5sum -c md5sums >> $LOGFILE 2>&1
136+
gunzip -c app.tar.gz | tar -x >> $LOGFILE 2>&1
137+
#cp version.txt app/ >> $LOGFILE 2>&1
138+
rm app.tar.gz
139+
140+
if [[ ! -d ${TMPDIR}/app/plugins ]]; then
141+
log "Missing plugins folder in app plugin update archive: $UPDATE_FILE"
142+
exit 1
143+
fi
144+
145+
if [[ -f ${TMPDIR}/hooks/pre-install.sh ]]; then
146+
log "Running pre-install script: ${TMPDIR}/hooks/pre-install.sh"
147+
${TMPDIR}/pre-install.sh >> $LOGFILE 2>&1
148+
fi
149+
150+
#------------------------------------------------------------------------------
151+
# Replace old backup with the current app version
152+
#------------------------------------------------------------------------------
153+
log "Stopping remote app..."
154+
killall -9 remote >> $LOGFILE 2>&1 && sleep 2 || true
155+
#stopService app >> $LOGFILE 2>&1#
156+
157+
#fbv -d 1 "${YIO_SPLASH_DIR}/update.png"
158+
159+
if [[ -d $YIO_PLUGIN_DIR ]]; then
160+
YIO_BACKUP=${YIO_HOME}/app-plugins-previous
161+
162+
if [[ -d $YIO_BACKUP ]]; then
163+
log "Removing previous app plugins backup: '$YIO_BACKUP'"
164+
rm -rf "${YIO_BACKUP}" >> $LOGFILE 2>&1
165+
fi
166+
167+
log "Backing up current plugins to: '$YIO_BACKUP'"
168+
cp -r "$YIO_PLUGIN_DIR" "$YIO_BACKUP" >> $LOGFILE 2>&1
169+
else
170+
log "Remote app plugin directory doesn't exist: '$YIO_PLUGIN_DIR'. Skipping backup."
171+
fi
172+
173+
mkdir -p $YIO_PLUGIN_DIR >> $LOGFILE 2>&1
174+
175+
#------------------------------------------------------------------------------
176+
# Activate new plugin
177+
#------------------------------------------------------------------------------
178+
mv ${TMPDIR}/app/plugins/* "$YIO_PLUGIN_DIR" >> $LOGFILE 2>&1
179+
log "Update ($TMPDIR) is now available in the plugin directory ($YIO_PLUGIN_DIR)"
180+
181+
if [[ -f ${TMPDIR}/hooks/post-install.sh ]]; then
182+
log "Running post-install script: ${TMPDIR}/hooks/post-install.sh"
183+
${TMPDIR}/post-install.sh >> $LOGFILE 2>&1
184+
fi
185+
186+
log "Deleting update archive files and temporary folder"
187+
rm -rf $TMPDIR >> $LOGFILE 2>&1
188+
rm "$UPDATE_FILE" >> $LOGFILE 2>&1
189+
if [[ -f $MARKER_FILE ]]; then
190+
rm -f $MARKER_FILE
191+
fi
192+
193+
fbv -d 1 "${YIO_SPLASH_DIR}/splash.png"
194+
195+
#TODO rather reboot? If yes: it would be a good time to check & repair file systems
196+
log "Update finished! Launching app..."
197+
198+
# 'systemctl start app' doesn't work reliably!?
199+
# startService app
200+
$YIO_HOME/app-launch.sh >> /dev/null 2>&1

overlay/opt/yio/scripts/app-update.sh

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,6 @@
2727
. /etc/profile.d/yio.sh
2828
. $(dirname $0)/lib/common.bash
2929

30-
ensureScreenIsOn() {
31-
# TODO improve sledge hammer approach
32-
# FIXME this doesn't fully work if screen is put in standby from the YIO app.
33-
# It's not waking up instantly but much later when the update is almost finished!?
34-
35-
# make sure the screen and backlight are on, otherwise we'll end up with a dark screen!
36-
${YIO_HOME}/scripts/sharp-init
37-
38-
if [[ -f $1 ]]; then
39-
fbv -d 1 "$1"
40-
fi
41-
42-
gpio -g mode 12 pwm
43-
gpio pwm-ms
44-
gpio pwmc 1000
45-
gpio pwmr 100
46-
gpio -g pwm 12 100
47-
}
48-
4930
# TODO function to clean up in case of update error!
5031
# We don't want to end up in an update loop trying to install a corrupt archive
5132

@@ -208,4 +189,4 @@ log "Update finished! Launching app..."
208189

209190
fbv -d 1 "${YIO_SPLASH_DIR}/splash.png"
210191

211-
$YIO_HOME/app-launch.sh &
192+
$YIO_HOME/app-launch.sh >> /dev/null 2>&1

overlay/opt/yio/scripts/lib/common.bash

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ assertEnvVariable() {
3535
fi
3636
}
3737

38+
assertInstalled() {
39+
command -v $1 >/dev/null 2>&1 || {
40+
echo >&2 "Program $1 not installed. Aborting.";
41+
exit 1;
42+
}
43+
}
44+
3845
# Retrieve the latest release version from GitHub for the given repository.
3946
# Parameters:
4047
# $1: YIO GitHub repository. E.g. web-configurator, remote-software, etc.
@@ -117,3 +124,22 @@ confirm() {
117124
;;
118125
esac
119126
}
127+
128+
ensureScreenIsOn() {
129+
# TODO improve sledge hammer approach
130+
# FIXME this doesn't fully work if screen is put in standby from the YIO app.
131+
# It's not waking up instantly but much later when the update is almost finished!?
132+
133+
# make sure the screen and backlight are on, otherwise we'll end up with a dark screen!
134+
${YIO_HOME}/scripts/sharp-init
135+
136+
if [[ -f $1 ]]; then
137+
fbv -d 1 "$1"
138+
fi
139+
140+
gpio -g mode 12 pwm
141+
gpio pwm-ms
142+
gpio pwmc 1000
143+
gpio pwmr 100
144+
gpio -g pwm 12 100
145+
}

overlay/opt/yio/scripts/update.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ $0 COMPONENT PARAMETERS
4040
COMPONENT:
4141
app remote-software application
4242
web web-configurator
43+
plugin integration plugin
4344
os remote-os (NOT YET IMPLEMENTED)
44-
plugin integration plugin (NOT YET IMPLEMTED)
4545
4646
PARAMETERS:
4747
FILE.(version|zip|tar) update marker file or archive
@@ -88,14 +88,23 @@ appendReleaseInfo() {
8888
getLatestRelease $2
8989
if [[ ! -z $3 && -f ${3}/version.txt ]]; then
9090
LOCAL_VERSION=$(< ${3}/version.txt)
91-
elif [[ ! -z $4 && -f $4 ]]; then
92-
# TODO query plugin metadata. Probably need to write a little qt utility...
93-
LOCAL_VERSION=x
91+
fi
92+
echo "$2,$LATEST_RELEASE,$LOCAL_VERSION" >> $1
93+
}
94+
95+
appendPluginReleaseInfo() {
96+
local LOCAL_VERSION=-
97+
getLatestRelease $2
98+
if [[ -f $3 ]]; then
99+
LOCAL_VERSION=`qtplugininfo --full-json -f compact $3 | jq '.MetaData.version' | tr -d '"'`
94100
fi
95101
echo "$2,$LATEST_RELEASE,$LOCAL_VERSION" >> $1
96102
}
97103

98104
checkReleases() {
105+
assertInstalled qtplugininfo
106+
assertInstalled jq
107+
99108
echo "Retrieving version information from GitHub..."
100109
local VERSION_FILE=/tmp/versions.txt
101110
echo "Component,GitHub,Installed" > $VERSION_FILE
@@ -108,7 +117,7 @@ checkReleases() {
108117
local PROJECT=$(awk -F, '{print $1}' <<< $item)
109118
local LIBFILE=${YIO_PLUGIN_DIR}/$(awk -F, '{print $2}' <<< $item)
110119

111-
appendReleaseInfo $VERSION_FILE $PROJECT "" $LIBFILE
120+
appendPluginReleaseInfo $VERSION_FILE $PROJECT $LIBFILE
112121
done
113122

114123
echo ""
@@ -203,8 +212,8 @@ case "$COMPONENT" in
203212
exit 1
204213
;;
205214
plugin)
206-
echo "plugin NOT YET IMPLEMENTED!"
207-
exit 1
215+
$DIR/app-plugin-update.sh $@ || exit $?
216+
exit 0
208217
;;
209218
*)
210219
echo "Invalid component: $COMPONENT"

rpi0/defconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ BR2_LINUX_KERNEL_LZO=y
2727
BR2_LINUX_KERNEL_DTS_SUPPORT=y
2828
BR2_LINUX_KERNEL_INTREE_DTS_NAME="bcm2708-rpi-0-w"
2929
BR2_PACKAGE_FFMPEG=y
30+
BR2_PACKAGE_JQ=y
3031
BR2_PACKAGE_FBV=y
3132
BR2_PACKAGE_QT5=y
3233
BR2_PACKAGE_QT5BASE_DEFAULT_QPA="eglfs"
34+
BR2_PACKAGE_QT5TOOLS_QTPLUGININFO=y
3335
BR2_PACKAGE_RPI_BT_FIRMWARE=y
3436
BR2_PACKAGE_RPI_FIRMWARE=y
3537
BR2_PACKAGE_RPI_FIRMWARE_INSTALL_VCDBG=y

yio-remote/Config.in

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,34 @@ if BR2_PACKAGE_YIO_REMOTE
3131
# Custom versions can be enabled with: BR2_PACKAGE_YIO_REMOTE_CUSTOM_VERSION
3232
config BR2_PACKAGE_YIO_REMOTE_SOFTWARE_VERSION_DEF
3333
string
34-
default "v0.4.3"
34+
default "v0.5.2"
3535
config BR2_PACKAGE_YIO_WEB_CONFIGURATOR_VERSION_DEF
3636
string
37-
default "v0.1.8"
37+
default "v0.2.0"
3838
config BR2_PACKAGE_YIO_INTEGRATION_DOCK_VERSION_DEF
3939
string
40-
default "v0.5.2"
40+
default "v0.6.0"
4141
config BR2_PACKAGE_YIO_INTEGRATION_HOMEASSISTANT_VERSION_DEF
4242
string
43-
default "v0.4.7"
43+
default "v0.5.0"
4444
config BR2_PACKAGE_YIO_INTEGRATION_HOMEY_VERSION_DEF
4545
string
46-
default "v0.4.2"
46+
default "v0.5.0"
4747
config BR2_PACKAGE_YIO_INTEGRATION_OPENHAB_VERSION_DEF
4848
string
49-
default "v0.4.1"
49+
default "v0.5.0"
5050
config BR2_PACKAGE_YIO_INTEGRATION_SPOTIFY_VERSION_DEF
5151
string
52-
default "v0.4.1"
52+
default "v0.5.0"
5353
config BR2_PACKAGE_YIO_INTEGRATION_BANGOLUFSEN_VERSION_DEF
5454
string
55-
default "v0.1.0"
55+
default "v0.2.0"
5656
config BR2_PACKAGE_YIO_INTEGRATION_OPENWEATHER_VERSION_DEF
5757
string
58-
default "v0.4.1"
58+
default "v0.5.0"
5959
config BR2_PACKAGE_YIO_INTEGRATION_ROON_VERSION_DEF
6060
string
61-
default "v0.3.1"
61+
default "v0.4.0"
6262

6363
choice
6464
prompt "Source"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sha256 d9dbf6800113a607226fa62b3da6caaee4365d2896527e8804ff14dc340b9bd9 YIO-integration.dock-v0.6.0-RPi0-debug.tar
2+
sha256 a9f1f197aae9c4f9f2646e83e4208377c6f80fd1033bdd1ed2b6bd39ae09c414 YIO-integration.dock-v0.6.0-RPi0-release.tar
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sha256 6e991f1a78ac48bdc7f4746cc64da516bcc797ead0c5d6fe9e3e02a24570b124 YIO-integration.home-assistant-v0.5.0-RPi0-debug.tar
2+
sha256 0edb033d3edef1e67e87a24a77b75a0e4907fbef16208fbb0a4217be406613ea YIO-integration.home-assistant-v0.5.0-RPi0-release.tar
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sha256 7ec1c979f42709fae1044a5fff8deb10e579809dafbd03802b6380b914ad1880 YIO-integration.homey-v0.5.0-RPi0-debug.tar
2+
sha256 be75d7ebf4171849061abcada2811816e3b1fec3b1dfebc29f351a6eec90200a YIO-integration.homey-v0.5.0-RPi0-release.tar
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sha256 b805d883a8c8b7d9486d1917c80dc55b6872be42684bda7507c679651013f116 YIO-integration.openweather-v0.5.0-RPi0-debug.tar
2+
sha256 42d2176701f37a1913f7248aa7c8869c78590b240e314120a8d9174ca9e59db3 YIO-integration.openweather-v0.5.0-RPi0-release.tar
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sha256 544a598c52bf022a404b5d977065da42305fa9cd4699398c04815bfe5391e3bc YIO-integration.roon-v0.4.0-RPi0-debug.tar
2+
sha256 5eb03192426e6211bd8fa314fc14c6aa9f7b2b8a6e75ed2b16322f51628b9418 YIO-integration.roon-v0.4.0-RPi0-release.tar

0 commit comments

Comments
 (0)