blitz_api/scripts/sync_to_blitz.sh

98 lines
3.6 KiB
Bash
Raw Permalink Normal View History

2022-03-16 23:33:44 +01:00
# 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=""
sshPort="22"
2022-03-16 23:33:44 +01:00
passwordA=""
2021-12-05 21:14:25 +01:00
2022-03-16 23:33:44 +01:00
# 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 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
2022-03-16 23:33:44 +01:00
echo "FAIL: please make sure that sshpass is installed on your system"
echo "macOS: brew install hudochenkov/sshpass/sshpass"
echo "Linux(Debian): apt install sshpass"
exit
fi
# check if ping is installed
pingInstalled=$(ping -c 1 1.1.1.1 | grep -c "PING")
if [ ${pingInstalled} -eq 0 ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "FAIL: please make sure that ping is installed on your system"
echo "Linux(Debian): apt install inetutils-ping OR apt install iputils-ping"
exit
2022-03-16 23:33:44 +01:00
fi
# check if localIP is available&responding
ping -c 1 $localIP
if [ "$?" != "0" ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
2022-03-16 23:33:44 +01:00
echo "FAIL: was not able to ping $localIP"
exit
fi
2021-12-05 21:14:25 +01:00
local=.
remoteRepoPath="/home/blitzapi/blitz_api"
2022-06-04 16:45:32 +02:00
remote="admin@$localIP:${remoteRepoPath}"
2021-12-05 21:14:25 +01:00
# clean pycache just in case the code was compiled locally before
echo "# local cache delete .."
rm -r ./app/__pycache__ 2>/dev/null
rm -r ./app/repositories/ln_impl/protos/__pycache__ 2>/dev/null
rm -r ./app/repositories/ln_impl/__pycache__ 2>/dev/null
rm -r ./app/external/fastapi_versioning/__pycache__ 2>/dev/null
rm -r ./app/external/sse_starlette/__pycache__ 2>/dev/null
rm -r ./app/external/__pycache__ 2>/dev/null
rm -r ./app/models/__pycache__ 2>/dev/null
rm -r ./app/repositories/__pycache__ 2>/dev/null
rm -r ./app/routers/__pycache__ 2>/dev/null
rm -r ./app/auth/__pycache__ 2>/dev/null
2022-06-04 16:45:32 +02:00
# make sure remote repo files can be overwritten bei user admin
echo "# sshpass Test"
2022-06-04 16:45:32 +02:00
sshpass -p "$passwordA" ssh -p $sshPort admin@$localIP "sudo chown -R admin:admin ${remoteRepoPath}"
result=$?
echo "result(${result})"
if [ "$result" != "0" ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "FAIL: was not able to ssh in: ssh -p ${sshPort} admin@$localIP"
echo "Is password correct? --> ${passwordA}"
echo "Too often wrong password? Wait a bit."
2022-06-04 16:45:32 +02:00
echo "SSH in once manually. Then try again."
exit 1
fi
2021-12-05 21:14:25 +01:00
# Needs sshpass installed
2022-03-16 23:33:44 +01:00
echo "# syncing local code to: ${remote}"
2022-05-27 01:03:37 +02:00
sshpass -p "$passwordA" rsync -rvz --exclude .git/ -e "ssh -p ${sshPort}" $local $remote
result=$?
echo "result(${result})"
if [ "$result" != "0" ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
2022-06-04 16:45:32 +02:00
echo "FAIL: was not able to rsync"
exit 1
fi
2022-03-13 18:46:47 +01:00
2022-06-30 12:48:58 +02:00
# make sure uploaded/synced files belog again to the correct raspiblitz user to run
sshpass -p "$passwordA" ssh -p $sshPort admin@$localIP "sudo chown -R blitzapi:blitzapi ${remoteRepoPath}"
2022-03-13 18:46:47 +01:00
# Restart the blitz service to activate changes
2022-03-16 23:33:44 +01:00
echo "# restarting blitzapi.service"
sshpass -p "$passwordA" ssh -p $sshPort admin@$localIP 'sudo systemctl restart blitzapi.service'
2022-03-13 18:46:47 +01:00
# Get latest logs entries
2022-03-16 23:33:44 +01:00
echo "# latest log entries"
sshpass -p "$passwordA" ssh -p $sshPort admin@$localIP 'sudo journalctl -u blitzapi.service -n 10 --no-pager --no-hostname'
2022-03-13 18:46:47 +01:00
# Watch the logs
2022-03-16 23:33:44 +01:00
echo "# watching logs - CTRL+C to exit"
sshpass -p "$passwordA" ssh -p $sshPort admin@$localIP 'sudo journalctl -u blitzapi.service -f --no-hostname'