planktoscope/scripts/bash/update.sh

64 lines
2.2 KiB
Bash
Raw Normal View History

2020-11-25 16:58:32 +01:00
#!/bin/bash
2020-11-27 11:53:21 +01:00
log="logger -t update.sh -s "
2020-11-25 16:58:32 +01:00
2021-05-06 16:13:17 +02:00
if [[ $# == 1 ]]; then
BRANCH=$1
else
BRANCH="master"
fi
${log} "Updating the main repository to branch $BRANCH"
function restart(){
sudo nginx -t && sudo systemctl reload nginx
sudo systemctl restart nodered.service
}
2020-11-30 02:46:40 +01:00
function update(){
2021-05-06 16:13:17 +02:00
cd /home/pi/PlanktonScope || { echo "/home/pi/PlanktonScope does not exist"; exit 1; }
2020-11-30 02:46:40 +01:00
sudo killall -15 raspimjpeg
sudo killall -15 python3
git stash
git merge
git checkout stash@'{0}' -- config.json hardware.json
# TODO we need to change this to drop stash@{1} if changes made to the flow are to be restored by the user
git stash drop
}
2021-05-06 16:13:17 +02:00
function special_before(){
cd /home/pi/.node-red || { echo "/home/pi/.node-red does not exist"; exit 1; }
npm install copy-dependencies
2021-05-11 02:31:51 +02:00
pip3 install --update adafruit-blinka adafruit-platformdetect loguru Pillow pyserial smbus2 matplotlib morphocut adafruit-circuitpython-motor adafruit-circuitpython-motorkit adafruit-circuitpython-pca9685 numpy paho-mqtt
2021-05-06 16:13:17 +02:00
${log} "Nothing else special to do before updating!"
}
function special_after(){
cd /home/pi/.node-red || { echo "/home/pi/.node-red does not exist"; exit 1; }
node_modules/copy-dependencies/index.js projects/PlanktonScope ./
# updating and installing now whatever module has been added to package.json
npm update
sudo pip3 install -U -r /home/pi/PlanktonScope/requirements.txt
2021-05-06 16:13:17 +02:00
${log} "Nothing else special to do after updating!"
2020-12-01 21:12:29 +01:00
}
2020-11-25 16:58:32 +01:00
2021-05-06 16:13:17 +02:00
cd /home/pi/PlanktonScope || { echo "/home/pi/PlanktonScope does not exist"; exit 1; }
remote=$(git ls-remote -h origin $BRANCH | awk '{print $1}')
2020-11-30 02:46:40 +01:00
local=$(git rev-parse HEAD)
if [[ "$local" == "$remote" ]]; then
${log} "nothing to do!"
else
${log} "Local and Remote are different, we have to update!"
2020-11-30 02:46:40 +01:00
git fetch
2021-05-06 16:13:17 +02:00
UPDATE=$(git diff --numstat origin/$BRANCH scripts/bash/update.sh | awk '/update.sh/ {print $NF}')
2020-11-30 02:46:40 +01:00
if [[ -n "${UPDATE}" ]]; then
# Update the file and restart the script
2021-05-06 16:13:17 +02:00
git checkout origin/$BRANCH scripts/bash/update.sh
exec scripts/bash/update.sh $BRANCH
2020-11-30 02:46:40 +01:00
fi
2021-05-06 16:13:17 +02:00
special_before
2020-11-30 02:46:40 +01:00
update
2021-05-06 16:13:17 +02:00
special_after
restart
2020-11-30 02:46:40 +01:00
${log} "Done!"
fi