update: fix various bugs

flow: improve update handling
This commit is contained in:
Romain Bazile 2021-06-30 18:41:00 +02:00
parent 3f86fb4ddb
commit 0bdd85366a
2 changed files with 142 additions and 87 deletions

View file

@ -314,7 +314,8 @@
"primary": "indigo", "primary": "indigo",
"accents": "blue", "accents": "blue",
"warn": "red", "warn": "red",
"background": "grey" "background": "grey",
"palette": "light"
} }
}, },
"site": { "site": {
@ -879,7 +880,16 @@
"collapse": false "collapse": false
}, },
{ {
"id": "7551712b.8ef1b8", "id": "f0eab4f4.40bc08",
"type": "ui_spacer",
"name": "spacer",
"group": "4248342d.e55fac",
"order": 2,
"width": 5,
"height": 1
},
{
"id": "13f34bee.279a44",
"type": "ui_spacer", "type": "ui_spacer",
"name": "spacer", "name": "spacer",
"group": "1be83144.4fe4bf", "group": "1be83144.4fe4bf",
@ -888,34 +898,34 @@
"height": 1 "height": 1
}, },
{ {
"id": "74adb5c6.b38aa4", "id": "a862072d.0ec1e8",
"type": "ui_spacer", "type": "ui_spacer",
"name": "spacer", "name": "spacer",
"group": "1be83144.4fe4bf", "group": "1be83144.4fe4bf",
"order": 6, "order": 6,
"width": 12,
"height": 1
},
{
"id": "5296bfb6.a27f6",
"type": "ui_spacer",
"name": "spacer",
"group": "1be83144.4fe4bf",
"order": 7,
"width": 3, "width": 3,
"height": 1 "height": 1
}, },
{ {
"id": "4179b30f.de0144", "id": "ac09f674.27d14",
"type": "ui_spacer",
"name": "spacer",
"group": "1be83144.4fe4bf",
"order": 8,
"width": 3,
"height": 1
},
{
"id": "bbc09199.173ee",
"type": "ui_spacer", "type": "ui_spacer",
"name": "spacer", "name": "spacer",
"group": "1be83144.4fe4bf", "group": "1be83144.4fe4bf",
"order": 9, "order": 9,
"width": 3, "width": 12,
"height": 1 "height": 1
}, },
{ {
"id": "8c8cf500.19fde", "id": "4b444d98.a84854",
"type": "ui_spacer", "type": "ui_spacer",
"name": "spacer", "name": "spacer",
"group": "1be83144.4fe4bf", "group": "1be83144.4fe4bf",
@ -924,59 +934,41 @@
"height": 1 "height": 1
}, },
{ {
"id": "a39d5554.7b4f38", "id": "5b88d5d8.baac64",
"type": "ui_spacer", "type": "ui_spacer",
"name": "spacer", "name": "spacer",
"group": "1be83144.4fe4bf", "group": "1be83144.4fe4bf",
"order": 11, "order": 11,
"width": 12,
"height": 1
},
{
"id": "9694f7f4.22987",
"type": "ui_spacer",
"name": "spacer",
"group": "1be83144.4fe4bf",
"order": 12,
"width": 4, "width": 4,
"height": 1 "height": 1
}, },
{ {
"id": "8bd48fcc.096fc", "id": "df135e23.9d5ba",
"type": "ui_spacer",
"name": "spacer",
"group": "1be83144.4fe4bf",
"order": 13,
"width": 4,
"height": 1
},
{
"id": "6d0cfbad.fb566c",
"type": "ui_spacer", "type": "ui_spacer",
"name": "spacer", "name": "spacer",
"group": "1be83144.4fe4bf", "group": "1be83144.4fe4bf",
"order": 14, "order": 14,
"width": 4,
"height": 1
},
{
"id": "f01875cc.409c4",
"type": "ui_spacer",
"name": "spacer",
"group": "1be83144.4fe4bf",
"order": 15,
"width": 12, "width": 12,
"height": 1 "height": 1
}, },
{ {
"id": "8290ff38.260b6", "id": "7d988743.b75b",
"type": "ui_spacer", "type": "ui_spacer",
"name": "spacer", "name": "spacer",
"group": "1be83144.4fe4bf", "group": "1be83144.4fe4bf",
"order": 17, "order": 16,
"width": 8, "width": 8,
"height": 1 "height": 1
}, },
{
"id": "f0eab4f4.40bc08",
"type": "ui_spacer",
"name": "spacer",
"group": "4248342d.e55fac",
"order": 2,
"width": 5,
"height": 1
},
{ {
"id": "4e78af2d.90be7", "id": "4e78af2d.90be7",
"type": "ui_ui_control", "type": "ui_ui_control",
@ -5982,7 +5974,7 @@
"z": "9daf9e2b.019fc", "z": "9daf9e2b.019fc",
"name": "", "name": "",
"group": "1be83144.4fe4bf", "group": "1be83144.4fe4bf",
"order": 16, "order": 15,
"width": 2, "width": 2,
"height": 1, "height": 1,
"passthru": false, "passthru": false,
@ -6027,7 +6019,7 @@
"z": "9daf9e2b.019fc", "z": "9daf9e2b.019fc",
"name": "", "name": "",
"group": "1be83144.4fe4bf", "group": "1be83144.4fe4bf",
"order": 18, "order": 17,
"width": 2, "width": 2,
"height": 1, "height": 1,
"passthru": false, "passthru": false,
@ -6112,7 +6104,7 @@
"z": "9daf9e2b.019fc", "z": "9daf9e2b.019fc",
"name": "Restart Python", "name": "Restart Python",
"group": "1be83144.4fe4bf", "group": "1be83144.4fe4bf",
"order": 13, "order": 12,
"width": 4, "width": 4,
"height": 1, "height": 1,
"passthru": true, "passthru": true,
@ -6504,7 +6496,7 @@
"z": "9daf9e2b.019fc", "z": "9daf9e2b.019fc",
"name": "Update", "name": "Update",
"group": "1be83144.4fe4bf", "group": "1be83144.4fe4bf",
"order": 8, "order": 7,
"width": 6, "width": 6,
"height": 1, "height": 1,
"passthru": false, "passthru": false,
@ -6513,9 +6505,10 @@
"color": "", "color": "",
"bgcolor": "", "bgcolor": "",
"icon": "mi-system_update", "icon": "mi-system_update",
"payload": "", "payload": " ",
"payloadType": "str", "payloadType": "str",
"topic": "update", "topic": "update",
"topicType": "str",
"x": 260, "x": 260,
"y": 460, "y": 460,
"wires": [ "wires": [
@ -6558,7 +6551,7 @@
"name": "Update message", "name": "Update message",
"order": 1, "order": 1,
"width": 12, "width": 12,
"height": 2, "height": 3,
"format": "<div><center>If you want to update to the latest code version of Node-Red and Python, please click here.\nWe are trying to save your configuration changes with git stash and restore them afterwards, but clearly, things may break!\nAlso, you can choose the branch you want to update to. BE CAREFUL, selecting a branch WILL update the code immediately.\nIf you have made changes to the flow, you will lose them. Please commit those changes from Node-Red interface, from the Project History tab.</center></div>", "format": "<div><center>If you want to update to the latest code version of Node-Red and Python, please click here.\nWe are trying to save your configuration changes with git stash and restore them afterwards, but clearly, things may break!\nAlso, you can choose the branch you want to update to. BE CAREFUL, selecting a branch WILL update the code immediately.\nIf you have made changes to the flow, you will lose them. Please commit those changes from Node-Red interface, from the Project History tab.</center></div>",
"storeOutMessages": true, "storeOutMessages": true,
"fwdInMessages": true, "fwdInMessages": true,
@ -8921,7 +8914,8 @@
"y": 340, "y": 340,
"wires": [ "wires": [
[ [
"af2b8d95.195bb8" "af2b8d95.195bb8",
"6c20d6a7.869b6"
], ],
[], [],
[] []
@ -8931,7 +8925,7 @@
"id": "d334d264.8a7728", "id": "d334d264.8a7728",
"type": "exec", "type": "exec",
"z": "9daf9e2b.019fc", "z": "9daf9e2b.019fc",
"command": "git --git-dir=/home/pi/PlanktonScope/.git branch --list", "command": "git --git-dir=/home/pi/PlanktonScope/.git branch --remotes --list | awk '/HEAD/{next;} split($1, a, \"/\") {print a[2]}'",
"addpay": false, "addpay": false,
"append": "", "append": "",
"useSpawn": "false", "useSpawn": "false",
@ -9009,11 +9003,12 @@
"noerr": 0, "noerr": 0,
"initialize": "", "initialize": "",
"finalize": "", "finalize": "",
"x": 930, "x": 870,
"y": 260, "y": 260,
"wires": [ "wires": [
[ [
"3f13b9f8.bac94e" "3f13b9f8.bac94e",
"ccc7d79b.a419f"
] ]
] ]
}, },
@ -9055,7 +9050,7 @@
"label": "Current code version", "label": "Current code version",
"format": "{{msg.payload}}", "format": "{{msg.payload}}",
"layout": "row-center", "layout": "row-center",
"x": 860, "x": 900,
"y": 320, "y": 320,
"wires": [] "wires": []
}, },
@ -9099,7 +9094,7 @@
"z": "1371dec5.76e671", "z": "1371dec5.76e671",
"name": "git version", "name": "git version",
"links": [ "links": [
"aa2dbb6.4cd9948" "6c20d6a7.869b6"
], ],
"x": 455, "x": 455,
"y": 520, "y": 520,
@ -9623,18 +9618,6 @@
] ]
] ]
}, },
{
"id": "b6bc9b81.ff942",
"type": "function",
"z": "9daf9e2b.019fc",
"name": "get git revision",
"outputs": 1,
"x": 835,
"y": 360,
"wires": [
[]
]
},
{ {
"id": "ba2947.c854deb8", "id": "ba2947.c854deb8",
"type": "function", "type": "function",
@ -10133,5 +10116,69 @@
"8dd6f57f.b77f98" "8dd6f57f.b77f98"
] ]
] ]
},
{
"id": "6c20d6a7.869b6",
"type": "link out",
"z": "9daf9e2b.019fc",
"name": "Git revision",
"links": [
"be6bddd3.2004f"
],
"x": 815,
"y": 360,
"wires": []
},
{
"id": "7de3a9b4.0ab108",
"type": "ui_toast",
"z": "9daf9e2b.019fc",
"position": "top right",
"displayTime": "10",
"highlight": "",
"sendall": true,
"outputs": 0,
"ok": "OK",
"cancel": "",
"raw": false,
"topic": "",
"name": "Git branch update",
"x": 1290,
"y": 260,
"wires": []
},
{
"id": "ccc7d79b.a419f",
"type": "change",
"z": "9daf9e2b.019fc",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "List update successfull",
"tot": "str"
},
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "Branch list update",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1080,
"y": 260,
"wires": [
[
"7de3a9b4.0ab108"
]
]
} }
] ]

View file

@ -1,8 +1,13 @@
#!/bin/bash #!/bin/bash
log="logger -t update.sh -s " log="echo -e"
REMOTE_BRANCHES=$(git --git-dir=/home/pi/PlanktonScope/.git branch --remotes --list | awk '/HEAD/{next;} split($1, a, "/") {print a[2]}')
if [[ $# == 1 ]]; then if [[ $# == 1 ]]; then
BRANCH=$1 if [[ $REMOTE_BRANCHES =~ (^| )$1($| ) ]]; then
BRANCH=$1
else
BRANCH="master"
fi
else else
BRANCH="master" BRANCH="master"
fi fi
@ -11,8 +16,9 @@ ${log} "Updating the main repository to branch $BRANCH"
function auto_update(){ function auto_update(){
git fetch git fetch
UPDATE=$(git diff --numstat origin/$BRANCH scripts/bash/update.sh | awk '/update.sh/ {print $NF}') NEWVERSION=$(git diff --numstat origin/$BRANCH scripts/bash/update.sh | awk '/update.sh/ {print $NF}')
if [[ -n "${UPDATE}" ]]; then if [[ -n "${NEWVERSION}" ]]; then
${log} "Updating the update script first"
# Update the file and restart the script # Update the file and restart the script
git checkout origin/$BRANCH scripts/bash/update.sh git checkout origin/$BRANCH scripts/bash/update.sh
exec scripts/bash/update.sh $BRANCH exec scripts/bash/update.sh $BRANCH
@ -31,8 +37,8 @@ function update(){
git stash git stash
# TODO detect branch change and use git pull on same branch and checkout on diff branch # TODO detect branch change and use git pull on same branch and checkout on diff branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" -eq $BRANCH ]; then if [[ "$CURRENT_BRANCH" == "$BRANCH" ]]; then
git merge git pull
else else
git checkout --force $BRANCH git checkout --force $BRANCH
fi fi
@ -44,7 +50,7 @@ function update(){
function special_before(){ function special_before(){
cd /home/pi/.node-red || { echo "/home/pi/.node-red does not exist"; exit 1; } cd /home/pi/.node-red || { echo "/home/pi/.node-red does not exist"; exit 1; }
npm install copy-dependencies npm install copy-dependencies
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 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!" ${log} "Nothing else special to do before updating!"
} }
@ -58,18 +64,20 @@ function special_after(){
${log} "Nothing else special to do after updating!" ${log} "Nothing else special to do after updating!"
} }
echo -e "Update on $(date)\n\n\n\n" >> /home/pi/update.log
cd /home/pi/PlanktonScope || { echo "/home/pi/PlanktonScope does not exist"; exit 1; } cd /home/pi/PlanktonScope || { echo "/home/pi/PlanktonScope 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) local=$(git rev-parse HEAD)
if [[ "$local" == "$remote" ]]; then if [[ "$local" == "$remote" ]]; then
${log} "nothing to do!" ${log} "Nothing to do!"
else else
${log} "Local and Remote are different, we have to update!" ${log} "Local and Remote are different, we have to update, starting now... Please Wait."
auto_update auto_update &>> /home/pi/update.log
special_before special_before &>> /home/pi/update.log
update ${log} "Everything is ready, doing the update now!"
special_after update &>> /home/pi/update.log
restart special_after &>> /home/pi/update.log
${log} "Done!" ${log} "Update is complete, let's restart now."
fi restart &>> /home/pi/update.log
fi
${log} "Update done!"