From de840cf1e0d07c3dae4f396bf3463f13ae85669f Mon Sep 17 00:00:00 2001 From: rootzoll Date: Wed, 16 Mar 2022 23:33:44 +0100 Subject: [PATCH] improved sync_to_blitz script --- .gitignore | 3 ++- scripts/sync_to_blitz.sh | 44 ++++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index dae70d1..bcacf22 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ __pycache__ .env .coverage -htmlcov \ No newline at end of file +htmlcov +scripts/sync_to_blitz.personal.sh \ No newline at end of file diff --git a/scripts/sync_to_blitz.sh b/scripts/sync_to_blitz.sh index 327e27b..b2d7f86 100644 --- a/scripts/sync_to_blitz.sh +++ b/scripts/sync_to_blitz.sh @@ -1,20 +1,46 @@ -# Set the IP of the Raspiblitz -ip=192.168.1.254 +# TO MAKE THIS SCRIPT WORK: +# create the following file: scripts/sync_to_blitz.personal.sh (it will be ignored by git and not commited) +# add the following two lines to that files and fill with personal data of your development blitz: +localIP="" +passwordA="" -# admin password, WARNING only use with a dev machine -password="your_pw_here" +# get personal blitz info +source scripts/sync_to_blitz.personal.sh +if [ "${localIP}" = "" ] || [ "${passwordA}" == "" ]; then + echo "FAIL: please create scripts/sync_to_blitz.personal.sh file with localIP & passwordA info." + exit +fi + +# check if sshpass is installed +sshpassInstalled=$(sshpass -V | grep -c "sshpass") +if [ ${sshpassInstalled} -eq 0 ]; then + echo "FAIL: please make sure that sshpass is installed on your system" + echo "macOS: brew install hudochenkov/sshpass/sshpass" + exit +fi + +# check if localIP is available&responding +ping -c 1 $localIP +if [ "$?" != "0" ]; then + echo "FAIL: was not able to ping $localIP" + exit +fi local=. -remote=admin@$ip:/home/admin/blitz_api +remote=admin@$localIP:/home/admin/blitz_api # Needs sshpass installed -sshpass -p "$password" rsync -re ssh $local $remote +echo "# syncing local code to: ${remote}" +sshpass -p "$passwordA" rsync -re ssh $local $remote # Restart the blitz service to activate changes -sshpass -p "$password" ssh admin@$ip 'sudo systemctl restart blitzapi.service' +echo "# restarting blitzapi.service" +sshpass -p "$passwordA" ssh admin@$localIP 'sudo systemctl restart blitzapi.service' # Get latest logs entries -sshpass -p "$password" ssh admin@$ip 'sudo journalctl -u blitzapi.service -n 10 --no-pager --no-hostname' +echo "# latest log entries" +sshpass -p "$passwordA" ssh admin@$localIP 'sudo journalctl -u blitzapi.service -n 10 --no-pager --no-hostname' # Watch the logs -sshpass -p "$password" ssh admin@$ip 'sudo journalctl -u blitzapi.service -f --no-hostname' \ No newline at end of file +echo "# watching logs - CTRL+C to exit" +sshpass -p "$passwordA" ssh admin@$localIP 'sudo journalctl -u blitzapi.service -f --no-hostname' \ No newline at end of file