zigbee2mqtt/update.sh
rbswift f224ef7b7c
chore: Improve update script in case of local changes (#18837)
* Stash local changes to prevent update failing

Call git stash to stash any local changes that would prevent the update.sh script from failing

* Update update.sh

changed to git checkout package-lock.json
2023-09-02 09:08:09 +02:00

41 lines
1021 B
Bash
Executable File

#!/bin/bash -e
if [ -d data-backup ]; then
echo "ERROR: Backup directory exists. May be previous restoring was failed?"
echo "1. Save 'data-backup' and 'data' dirs to safe location to make possibility to restore config later."
echo "2. Manually delete 'data-backup' dir and try again."
exit 1
fi
if which systemctl 2> /dev/null > /dev/null; then
echo "Stopping Zigbee2MQTT..."
sudo systemctl stop zigbee2mqtt
else
echo "Skipped stopping Zigbee2MQTT, no systemctl found"
fi
echo "Creating backup of configuration..."
cp -R data data-backup
echo "Checking out changes to package-lock.json..."
git checkout package-lock.json
echo "Updating..."
git pull
echo "Installing dependencies..."
npm ci
echo "Restore configuration..."
cp -R data-backup/* data
rm -rf data-backup
if which systemctl 2> /dev/null > /dev/null; then
echo "Starting Zigbee2MQTT..."
sudo systemctl start zigbee2mqtt
else
echo "Skipped starting Zigbee2MQTT, no systemctl found"
fi
echo "Done!"