2022-09-21 17:48:01 -04:00
|
|
|
#!/usr/bin/env bash
|
2022-10-06 12:29:34 -04:00
|
|
|
RELEASE=$(curl -s https://api.github.com/repos/zwave-js/zwave-js-ui/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
|
2022-09-21 17:48:01 -04:00
|
|
|
set -e
|
2022-10-06 12:29:34 -04:00
|
|
|
YW=`echo "\033[33m"`
|
2022-09-21 17:48:01 -04:00
|
|
|
RD=`echo "\033[01;31m"`
|
|
|
|
BL=`echo "\033[36m"`
|
|
|
|
GN=`echo "\033[1;92m"`
|
|
|
|
CL=`echo "\033[m"`
|
2022-10-06 12:29:34 -04:00
|
|
|
RETRY_NUM=10
|
|
|
|
RETRY_EVERY=3
|
|
|
|
NUM=$RETRY_NUM
|
|
|
|
CM="${GN}✓${CL}"
|
|
|
|
CROSS="${RD}✗${CL}"
|
|
|
|
BFR="\\r\\033[K"
|
|
|
|
HOLD="-"
|
2022-09-21 17:48:01 -04:00
|
|
|
set -o errexit
|
|
|
|
set -o errtrace
|
|
|
|
set -o nounset
|
|
|
|
set -o pipefail
|
|
|
|
shopt -s expand_aliases
|
|
|
|
alias die='EXIT=$? LINE=$LINENO error_exit'
|
|
|
|
trap die ERR
|
|
|
|
|
|
|
|
function error_exit() {
|
|
|
|
trap - ERR
|
|
|
|
local reason="Unknown failure occured."
|
|
|
|
local msg="${1:-$reason}"
|
|
|
|
local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
|
|
|
|
echo -e "$flag $msg" 1>&2
|
|
|
|
exit $EXIT
|
|
|
|
}
|
2022-10-06 12:29:34 -04:00
|
|
|
function msg_info() {
|
|
|
|
local msg="$1"
|
|
|
|
echo -ne " ${HOLD} ${YW}${msg}..."
|
|
|
|
}
|
|
|
|
|
|
|
|
function msg_ok() {
|
|
|
|
local msg="$1"
|
|
|
|
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function msg_error() {
|
|
|
|
local msg="$1"
|
|
|
|
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
|
|
|
|
}
|
2022-09-30 10:01:35 -04:00
|
|
|
clear
|
2022-10-06 12:29:34 -04:00
|
|
|
cat << "EOF"
|
|
|
|
_____ _______ __ ______
|
|
|
|
/__ /_ ______ __ _____ / / ___/ / / / / _/
|
|
|
|
/ /| | /| / / __ `/ | / / _ \ __ / /\__ \ / / / // /
|
|
|
|
/ /_| |/ |/ / /_/ /| |/ / __/ / /_/ /___/ / / /_/ // /
|
|
|
|
/____/__/|__/\__,_/ |___/\___/ \____//____/ \____/___/
|
|
|
|
UPDATE
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2022-09-30 10:01:35 -04:00
|
|
|
while true; do
|
2022-10-06 12:29:34 -04:00
|
|
|
read -p "This will update ZWave JS UI to $RELEASE. Proceed(y/n)?" yn
|
2022-09-30 10:01:35 -04:00
|
|
|
case $yn in
|
|
|
|
[Yy]* ) break;;
|
|
|
|
[Nn]* ) exit;;
|
|
|
|
* ) echo "Please answer yes or no.";;
|
|
|
|
esac
|
|
|
|
done
|
2022-10-06 12:29:34 -04:00
|
|
|
if [ ! -d /opt/zwave-js-ui ]; then msg_error "No Zwave JS UI Install Detected!"; exit; fi
|
2022-09-21 17:48:01 -04:00
|
|
|
|
2022-10-06 12:29:34 -04:00
|
|
|
msg_info "Stopping Z-wave JS UI"
|
2022-09-21 17:48:01 -04:00
|
|
|
systemctl stop zwave-js-ui.service
|
2022-10-06 12:29:34 -04:00
|
|
|
msg_ok "Stopped Z-wave JS UI"
|
|
|
|
|
|
|
|
msg_info "Updating Z-wave JS UI"
|
2022-10-05 20:37:33 -04:00
|
|
|
wget https://github.com/zwave-js/zwave-js-ui/releases/download/${RELEASE}/zwave-js-ui-${RELEASE}-linux.zip &>/dev/null
|
2022-10-05 21:52:35 -04:00
|
|
|
unzip zwave-js-ui-${RELEASE}-linux.zip &>/dev/null
|
2022-10-05 21:39:18 -04:00
|
|
|
\cp -R zwave-js-ui-linux /opt/zwave-js-ui
|
2022-10-06 12:29:34 -04:00
|
|
|
msg_ok "Updated Z-wave JS UI"
|
2022-10-05 21:09:02 -04:00
|
|
|
|
2022-10-06 12:29:34 -04:00
|
|
|
msg_info "Updating Z-wave JS UI service file"
|
2022-10-05 21:09:02 -04:00
|
|
|
cat << EOF > /etc/systemd/system/zwave-js-ui.service
|
|
|
|
[Unit]
|
|
|
|
Description=zwave-js-ui
|
|
|
|
Wants=network-online.target
|
|
|
|
After=network-online.target
|
|
|
|
[Service]
|
|
|
|
User=root
|
|
|
|
WorkingDirectory=/opt/zwave-js-ui
|
|
|
|
ExecStart=/opt/zwave-js-ui/zwave-js-ui-linux
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
2022-10-06 12:29:34 -04:00
|
|
|
systemctl daemon-reload
|
|
|
|
msg_ok "Updated Z-wave JS UI service file"
|
2022-09-21 17:48:01 -04:00
|
|
|
|
2022-10-06 12:29:34 -04:00
|
|
|
msg_info "Cleanup"
|
2022-10-05 21:52:35 -04:00
|
|
|
rm -rf zwave-js-ui-${RELEASE}-linux.zip zwave-js-ui-linux store
|
2022-10-06 12:29:34 -04:00
|
|
|
msg_ok "Cleaned"
|
|
|
|
|
|
|
|
msg_info "Starting Z-wave JS UI"
|
2022-10-05 21:09:02 -04:00
|
|
|
systemctl enable --now zwave-js-ui.service
|
2022-10-06 12:29:34 -04:00
|
|
|
msg_info "Started Z-wave JS UI"
|
2022-09-21 17:48:01 -04:00
|
|
|
|
2022-10-06 12:29:34 -04:00
|
|
|
msg_ok "Completed Successfully!\n"
|