update: temporary fix to cleanup things a bit

This commit is contained in:
Romain Bazile 2021-07-07 16:15:55 +02:00
parent f79cc62a60
commit ef09302e0d
2 changed files with 21 additions and 25 deletions

View file

@ -1,19 +1,18 @@
#!/bin/bash
log="echo -e"
${log} "Updating the installer script from $BRANCH"
CURRENT_BRANCH=$(git --git-dir=/home/pi/PlanktoScope/.git rev-parse --abbrev-ref HEAD)
REMOTE_BRANCHES=$(git --git-dir=/home/pi/PlanktoScope/.git branch --remotes --list | awk '/HEAD/{next;} split($1, a, "/") {print a[2]}')
if [[ $# == 1 ]]; then
if [[ $REMOTE_BRANCHES =~ (^| )$1($| ) ]]; then
BRANCH=$1
if [[ $REMOTE_BRANCHES =~ (^|[[:space:]])$1($|[[:space:]]) ]]; then
BRANCH="$1"
else
BRANCH="master"
BRANCH="$CURRENT_BRANCH"
fi
else
BRANCH="master"
BRANCH="$CURRENT_BRANCH"
fi
${log} "Updating the installer script from $BRANCH"
curl "https://raw.githubusercontent.com/PlanktonPlanet/PlanktoScope/$BRANCH/scripts/bash/update.sh" > /tmp/update.sh
exec /tmp/update.sh "$BRANCH"
chmod +x /tmp/update.sh
exec /tmp/update.sh "$BRANCH"

View file

@ -1,15 +1,16 @@
#!/bin/bash
log="echo -e"
CURRENT_BRANCH=$(git --git-dir=/home/pi/PlanktoScope/.git rev-parse --abbrev-ref HEAD)
REMOTE_BRANCHES=$(git --git-dir=/home/pi/PlanktoScope/.git branch --remotes --list | awk '/HEAD/{next;} split($1, a, "/") {print a[2]}')
if [[ $# == 1 ]]; then
if [[ $REMOTE_BRANCHES =~ (^| )$1($| ) ]]; then
BRANCH=$1
if [[ $REMOTE_BRANCHES =~ (^|[[:space:]])$1($|[[:space:]]) ]]; then
BRANCH="$1"
else
BRANCH="master"
BRANCH="$CURRENT_BRANCH"
fi
else
BRANCH="master"
BRANCH="$CURRENT_BRANCH"
fi
${log} "Updating the main repository to branch $BRANCH"
@ -25,11 +26,10 @@ function update(){
sudo killall -15 python3
git stash
# TODO detect branch change and use git pull on same branch and checkout on diff branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$CURRENT_BRANCH" == "$BRANCH" ]]; then
git pull
else
git checkout --force $BRANCH
git checkout --force "$BRANCH"
fi
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
@ -39,33 +39,30 @@ function update(){
function special_before(){
cd /home/pi/.node-red || { echo "/home/pi/.node-red does not exist"; exit 1; }
sudo rpi-eeprom-update -a
npm install copy-dependencies
pip3 install --upgrade adafruit-blinka adafruit-platformdetect loguru Pillow pyserial smbus2 matplotlib morphocut adafruit-circuitpython-motor adafruit-circuitpython-motorkit adafruit-circuitpython-pca9685 numpy paho-mqtt
${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/PlanktoScope ./
#node_modules/copy-dependencies/index.js projects/PlanktoScope ./
# updating and installing now whatever module has been added to package.json
npm update
pip3 install -U -r /home/pi/PlanktoScope/requirements.txt
python3 -m pip install -U scikit-image
#npm update
#pip3 install -U -r /home/pi/PlanktoScope/requirements.txt
${log} "Nothing else special to do after updating!"
}
echo -e "Update on $(date)\n\n\n\n" >> /home/pi/update.log
echo -e "\n\n\nUpdate on $(date)\n\n" >> /home/pi/update.log
cd /home/pi/PlanktoScope || { echo "/home/pi/PlanktoScope does not exist"; exit 1; }
remote=$(git ls-remote -h origin $BRANCH | 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, starting now... Please Wait."
special_before &>> /home/pi/update.log
${log} "Everything is ready, doing the update now!"
${log} "Everything is ready, doing the actual update now!"
update &>> /home/pi/update.log
special_after &>> /home/pi/update.log
#special_after &>> /home/pi/update.log
${log} "Update is complete, let's restart now."
restart &>> /home/pi/update.log
fi