improved sync_to_blitz script

This commit is contained in:
rootzoll 2022-03-16 23:33:44 +01:00
parent d466d3ab47
commit de840cf1e0
2 changed files with 37 additions and 10 deletions

3
.gitignore vendored
View file

@ -2,4 +2,5 @@
__pycache__
.env
.coverage
htmlcov
htmlcov
scripts/sync_to_blitz.personal.sh

View file

@ -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'
echo "# watching logs - CTRL+C to exit"
sshpass -p "$passwordA" ssh admin@$localIP 'sudo journalctl -u blitzapi.service -f --no-hostname'