planktoscope/scripts/bash/update.sh

39 lines
1.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
2020-11-30 02:46:40 +01:00
function update(){
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
2020-12-05 13:28:33 +01:00
sudo nginx -t && sudo systemctl reload nginx
2020-11-30 02:46:40 +01:00
sudo systemctl restart nodered.service
}
2020-12-01 21:12:29 +01:00
function special(){
2021-01-14 17:04:02 +01:00
${log} "Nothing special to do!"
2020-12-01 21:12:29 +01:00
}
2020-11-27 11:53:21 +01:00
${log} "Updating the main repository"
2020-11-30 02:46:40 +01:00
cd /home/pi/PlanktonScope || { echo "/home/pi/PlanktonScope does not exist"; exit 1; }
2020-11-25 16:58:32 +01:00
2020-11-30 02:46:40 +01:00
remote=$(git ls-remote -h origin master | awk '{print $1}')
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
UPDATE=$(git diff --numstat origin/master scripts/bash/update.sh | awk '/update.sh/ {print $NF}')
if [[ -n "${UPDATE}" ]]; then
# Update the file and restart the script
git checkout origin/master scripts/bash/update.sh
exec scripts/bash/update.sh
fi
2020-12-01 21:12:29 +01:00
special
2020-11-30 02:46:40 +01:00
update
${log} "Done!"
fi