2020-11-25 16:58:32 +01:00
|
|
|
#!/bin/bash
|
2022-11-11 17:31:21 +01:00
|
|
|
|
2021-06-30 18:41:00 +02:00
|
|
|
log="echo -e"
|
2020-11-25 16:58:32 +01:00
|
|
|
|
2021-07-07 16:15:55 +02:00
|
|
|
CURRENT_BRANCH=$(git --git-dir=/home/pi/PlanktoScope/.git rev-parse --abbrev-ref HEAD)
|
2021-07-01 15:56:15 +02:00
|
|
|
REMOTE_BRANCHES=$(git --git-dir=/home/pi/PlanktoScope/.git branch --remotes --list | awk '/HEAD/{next;} split($1, a, "/") {print a[2]}')
|
2021-05-06 16:13:17 +02:00
|
|
|
if [[ $# == 1 ]]; then
|
2021-07-07 16:15:55 +02:00
|
|
|
if [[ $REMOTE_BRANCHES =~ (^|[[:space:]])$1($|[[:space:]]) ]]; then
|
|
|
|
BRANCH="$1"
|
2021-06-30 18:41:00 +02:00
|
|
|
else
|
2021-07-07 16:15:55 +02:00
|
|
|
BRANCH="$CURRENT_BRANCH"
|
2021-06-30 18:41:00 +02:00
|
|
|
fi
|
2021-05-06 16:13:17 +02:00
|
|
|
else
|
2021-07-07 16:15:55 +02:00
|
|
|
BRANCH="$CURRENT_BRANCH"
|
2021-05-06 16:13:17 +02:00
|
|
|
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-07-01 15:56:15 +02:00
|
|
|
cd /home/pi/PlanktoScope || { echo "/home/pi/PlanktoScope does not exist"; exit 1; }
|
2020-11-30 02:46:40 +01:00
|
|
|
sudo killall -15 raspimjpeg
|
|
|
|
sudo killall -15 python3
|
|
|
|
git stash
|
2021-06-08 18:02:19 +02:00
|
|
|
# TODO detect branch change and use git pull on same branch and checkout on diff branch
|
2021-06-30 18:41:00 +02:00
|
|
|
if [[ "$CURRENT_BRANCH" == "$BRANCH" ]]; then
|
|
|
|
git pull
|
2021-06-08 18:02:19 +02:00
|
|
|
else
|
2021-07-07 16:15:55 +02:00
|
|
|
git checkout --force "$BRANCH"
|
2021-06-08 18:02:19 +02:00
|
|
|
fi
|
2020-11-30 02:46:40 +01:00
|
|
|
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; }
|
2021-07-01 18:19:32 +02:00
|
|
|
sudo rpi-eeprom-update -a
|
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; }
|
2021-07-07 16:15:55 +02:00
|
|
|
#node_modules/copy-dependencies/index.js projects/PlanktoScope ./
|
2021-05-06 16:13:17 +02:00
|
|
|
# updating and installing now whatever module has been added to package.json
|
2021-07-07 16:15:55 +02:00
|
|
|
#npm update
|
|
|
|
#pip3 install -U -r /home/pi/PlanktoScope/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
|
|
|
}
|
|
|
|
|
2021-07-07 16:15:55 +02:00
|
|
|
echo -e "\n\n\nUpdate on $(date)\n\n" >> /home/pi/update.log
|
2021-07-01 15:56:15 +02:00
|
|
|
cd /home/pi/PlanktoScope || { echo "/home/pi/PlanktoScope does not exist"; exit 1; }
|
2021-07-07 16:15:55 +02:00
|
|
|
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
|
2021-06-30 18:41:00 +02:00
|
|
|
${log} "Nothing to do!"
|
2020-11-30 02:46:40 +01:00
|
|
|
else
|
2021-06-30 18:41:00 +02:00
|
|
|
${log} "Local and Remote are different, we have to update, starting now... Please Wait."
|
|
|
|
special_before &>> /home/pi/update.log
|
2021-07-07 16:15:55 +02:00
|
|
|
${log} "Everything is ready, doing the actual update now!"
|
2021-06-30 18:41:00 +02:00
|
|
|
update &>> /home/pi/update.log
|
2021-07-07 16:15:55 +02:00
|
|
|
#special_after &>> /home/pi/update.log
|
2021-06-30 18:41:00 +02:00
|
|
|
${log} "Update is complete, let's restart now."
|
|
|
|
restart &>> /home/pi/update.log
|
|
|
|
fi
|
2023-01-19 22:23:42 +01:00
|
|
|
${log} "Update done!"
|