From 6c580b0de13803110637052022f8b7615fbf2592 Mon Sep 17 00:00:00 2001 From: Romain Bazile Date: Thu, 6 May 2021 16:13:17 +0200 Subject: [PATCH] update: changes to install new modules --- scripts/bash/update.sh | 45 +++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/scripts/bash/update.sh b/scripts/bash/update.sh index 44ce6f0..183b8fa 100755 --- a/scripts/bash/update.sh +++ b/scripts/bash/update.sh @@ -1,7 +1,21 @@ #!/bin/bash log="logger -t update.sh -s " +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 +} + function update(){ + cd /home/pi/PlanktonScope || { echo "/home/pi/PlanktonScope does not exist"; exit 1; } sudo killall -15 raspimjpeg sudo killall -15 python3 git stash @@ -9,31 +23,40 @@ function update(){ 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 - sudo nginx -t && sudo systemctl reload nginx - sudo systemctl restart nodered.service } -function special(){ - ${log} "Nothing special to do!" +function special_before(){ + cd /home/pi/.node-red || { echo "/home/pi/.node-red does not exist"; exit 1; } + npm install copy-dependencies + ${log} "Nothing else special to do before updating!" } -${log} "Updating the main repository" +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 + ${log} "Nothing else special to do after updating!" +} + + cd /home/pi/PlanktonScope || { echo "/home/pi/PlanktonScope does not exist"; exit 1; } - -remote=$(git ls-remote -h origin master | awk '{print $1}') +remote=$(git ls-remote -h origin $BRANCH | 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!" git fetch - UPDATE=$(git diff --numstat origin/master scripts/bash/update.sh | awk '/update.sh/ {print $NF}') + UPDATE=$(git diff --numstat origin/$BRANCH 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 + git checkout origin/$BRANCH scripts/bash/update.sh + exec scripts/bash/update.sh $BRANCH fi - special + special_before update + special_after + restart ${log} "Done!" fi \ No newline at end of file