raspiblitz/home.admin/XXsyncScripts.sh

194 lines
6.9 KiB
Bash
Raw Normal View History

2018-08-08 19:58:15 +02:00
#!/bin/bash
2018-12-07 23:51:30 +01:00
2019-01-14 16:13:37 +01:00
# This is for developing on your RaspiBlitz.
# THIS IS NOT THE REGULAR UPDATE MECHANISM
# and can lead to dirty state of your scripts.
# IF YOU WANT TO UPDATE YOUR RASPIBLITZ:
# https://github.com/rootzoll/raspiblitz/blob/dev/FAQ.md#how-to-update-my-raspiblitz-after-version-098
2019-01-14 16:13:37 +01:00
2020-05-31 18:50:21 +01:00
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "-help" ]; then
echo "FOR DEVELOPMENT USE ONLY!"
echo "RaspiBlitz Sync Scripts"
2020-05-31 22:23:16 +02:00
echo "XXsyncScripts.sh info"
2020-06-03 00:23:54 +02:00
echo "XXsyncScripts.sh [-run|-clean|-install|-justinstall] branch [repo]"
2020-05-31 18:50:21 +01:00
exit 1
fi
2018-12-07 23:58:20 +01:00
cd /home/admin/raspiblitz
2020-01-21 20:56:18 +01:00
source /mnt/hdd/raspiblitz.conf 2>/dev/null
2018-12-07 23:58:20 +01:00
# gather info
activeGitHubUser=$(sudo -u admin cat /home/admin/raspiblitz/.git/config 2>/dev/null | grep "url = " | cut -d "=" -f2 | cut -d "/" -f4)
activeBranch=$(git branch 2>/dev/null | grep \* | cut -d ' ' -f2)
2020-05-31 18:50:21 +01:00
# if parameter is "info" just give back basic info about sync
2020-04-26 15:23:58 +02:00
if [ "$1" == "info" ]; then
echo "activeGitHubUser='${activeGitHubUser}'"
echo "activeBranch='${activeBranch}'"
exit 1
fi
2018-12-07 23:51:30 +01:00
# change branch if set as parameter
2020-10-14 01:31:27 +02:00
vagrant=0
2019-01-14 23:55:25 +01:00
clean=0
2020-06-03 00:25:15 +02:00
install=0
2018-12-08 00:09:26 +01:00
wantedBranch="$1"
2020-04-26 20:54:44 +02:00
wantedGitHubUser="$2"
2020-06-01 22:53:34 +02:00
if [ "${wantedBranch}" = "-run" ]; then
2020-09-14 12:49:10 +02:00
# "-run" ist just used by "patch" command and will ignore all further parameter
2020-06-01 22:55:09 +02:00
wantedBranch="${activeBranch}"
wantedGitHubUser="${activeGitHubUser}"
2020-10-14 01:31:27 +02:00
# detect if running in vagrant VM
vagrant=$(df | grep -c "/vagrant")
if [ "$2" = "git" ]; then
echo "# forcing guthub over vagrant sync"
vagrant=0
fi
2020-06-01 22:53:34 +02:00
fi
2019-01-14 23:55:25 +01:00
if [ "${wantedBranch}" = "-clean" ]; then
clean=1
wantedBranch="$2"
2020-04-26 23:22:33 +02:00
wantedGitHubUser="$3"
2019-01-14 23:55:25 +01:00
fi
2020-05-24 17:23:54 +02:00
if [ "${wantedBranch}" = "-install" ]; then
2020-06-03 00:23:54 +02:00
install=1
2020-05-24 17:23:54 +02:00
wantedBranch="$2"
wantedGitHubUser="$3"
fi
2020-06-03 00:23:54 +02:00
if [ "${wantedBranch}" = "-justinstall" ]; then
clean=1
install=1
wantedBranch=""
wantedGitHubUser=""
fi
2020-04-26 20:54:44 +02:00
# set to another GutHub repo as origin
2020-10-14 01:31:27 +02:00
if [ ${#wantedGitHubUser} -gt 0 ] && [ ${vagrant} -eq 0 ]; then
2020-04-26 20:54:44 +02:00
echo "# your active GitHubUser is: ${activeGitHubUser}"
echo "# your wanted GitHubUser is: ${wantedGitHubUser}"
if [ "${activeGitHubUser}" = "${wantedGitHubUser}" ]; then
echo "# OK"
else
2020-04-26 21:21:23 +02:00
echo "# checking repo exists .."
repoExists=$(curl -s https://api.github.com/repos/${wantedGitHubUser}/raspiblitz | jq -r '.name' | grep -c 'raspiblitz')
if [ ${repoExists} -eq 0 ]; then
echo "error='repo not found'"
exit 1
fi
2020-04-26 20:54:44 +02:00
echo "# try changing github origin .."
git remote set-url origin https://github.com/${wantedGitHubUser}/raspiblitz.git
activeGitHubUser=$(sudo -u admin cat /home/admin/raspiblitz/.git/config | grep "url = " | cut -d "=" -f2 | cut -d "/" -f4)
fi
2019-01-14 23:55:25 +01:00
fi
2020-10-14 01:31:27 +02:00
if [ ${#wantedBranch} -gt 0 ] && [ ${vagrant} -eq 0 ]; then
echo "# your active branch is: ${activeBranch}"
2020-04-26 20:54:44 +02:00
echo "# your wanted branch is: ${wantedBranch}"
2018-12-07 23:51:30 +01:00
if [ "${wantedBranch}" = "${activeBranch}" ]; then
echo "# OK"
2018-12-07 23:51:30 +01:00
else
2020-04-26 21:21:23 +02:00
2020-10-06 21:13:05 +02:00
# always clean & install fresh on branch change
clean=1
install=1
2020-04-26 22:49:59 +02:00
echo "# checking if branch is locally available"
localBranch=$(git branch | grep -c "${wantedBranch}")
if [ ${localBranch} -eq 0 ]; then
echo "# checking branch exists .."
branchExists=$(curl -s https://api.github.com/repos/${activeGitHubUser}/raspiblitz/branches/${wantedBranch} | jq -r '.name' | grep -c ${wantedBranch})
if [ ${branchExists} -eq 0 ]; then
echo "error='branch not found'"
exit 1
fi
2020-04-26 22:49:59 +02:00
echo "# checkout/changing branch .."
git fetch
2020-04-26 22:49:59 +02:00
git checkout -b ${wantedBranch} origin/${wantedBranch}
else
echo "# changing branch .."
2020-04-26 22:51:18 +02:00
git checkout ${wantedBranch}
2020-04-26 22:49:59 +02:00
fi
2018-12-07 23:51:30 +01:00
activeBranch=$(git branch | grep \* | cut -d ' ' -f2)
fi
fi
2020-05-23 15:59:58 +01:00
checkSumBlitzPyBefore=$(find /home/admin/raspiblitz/home.admin/BlitzPy -type f -exec md5sum {} \; | md5sum)
checkSumBlitzTUIBefore=$(find /home/admin/raspiblitz/home.admin/BlitzTUI -type f -exec md5sum {} \; | md5sum)
2020-10-14 01:31:27 +02:00
if [ ${vagrant} -eq 0 ]; then
origin=$(git remote -v | grep 'origin' | tail -n1)
echo "# *** SYNCING RASPIBLITZ CODE WITH GITHUB ***"
echo "# This is for developing on your RaspiBlitz."
echo "# THIS IS NOT THE REGULAR UPDATE MECHANISM"
echo "# and can lead to dirty state of your scripts."
echo "# REPO ----> ${origin}"
echo "# BRANCH --> ${activeBranch}"
echo "# ******************************************"
git pull 1>&2
cd ..
else
cd ..
echo "# --> VAGRANT IS ACTIVE"
echo "# *** SYNCING RASPIBLITZ CODE WITH VAGRANT LINKED DIRECTORY ***"
echo "# This is for developing on your RaspiBlitz with a VM."
echo "# - delete /home/admin/raspiblitz"
2020-10-14 01:31:27 +02:00
sudo rm -r /home/admin/raspiblitz
sudo mkdir /home/admin/raspiblitz
echo "# - copy from vagrant new raspiblitz files (ignore hidden dirs)"
sudo cp -r /vagrant/* /home/admin/raspiblitz
echo "# - set admin as owner of files"
2020-10-14 01:31:27 +02:00
sudo chown admin:admin -R /home/admin/raspiblitz
fi
2019-01-14 23:55:25 +01:00
if [ ${clean} -eq 1 ]; then
2020-10-14 01:31:27 +02:00
echo "# Cleaning assets .. "
2020-06-03 00:30:47 +02:00
sudo rm -f *.sh
sudo rm -rf assets
2020-10-14 01:31:27 +02:00
sudo -u admin mkdir assets
2019-01-14 23:55:25 +01:00
else
echo "# ******************************************"
echo "# NOT cleaning/deleting old files"
echo "# use parameter '-clean' if you want that next time"
echo "# ******************************************"
2019-01-14 23:55:25 +01:00
fi
2020-01-21 20:56:18 +01:00
echo "# COPYING from GIT-Directory to /home/admin/"
2020-10-14 01:31:27 +02:00
sudo rm -r /home/admin/config.scripts
2021-05-03 14:00:01 +02:00
sudo -u admin cp -r -f /home/admin/raspiblitz/home.admin/* /home/admin
sudo -u admin chmod -R +x /home/admin/config.scripts
sudo -u admin chmod -R +x /home/admin/setup.scripts
echo "# ******************************************"
2020-05-23 15:59:58 +01:00
2020-05-23 16:16:54 +01:00
echo "# Checking if the content of BlitzPy changed .."
2020-05-23 15:59:58 +01:00
checkSumBlitzPyAfter=$(find /home/admin/raspiblitz/home.admin/BlitzPy -type f -exec md5sum {} \; | md5sum)
echo "# checkSumBlitzPyBefore = ${checkSumBlitzPyBefore}"
echo "# checkSumBlitzPyAfter = ${checkSumBlitzPyAfter}"
2020-06-03 00:23:54 +02:00
if [ "${checkSumBlitzPyBefore}" = "${checkSumBlitzPyAfter}" ] && [ ${install} -eq 0 ]; then
2020-05-23 15:59:58 +01:00
echo "# BlitzPy did not changed."
else
blitzpy_wheel=$(ls -trR /home/admin/raspiblitz/home.admin/BlitzPy/dist | grep -E "*any.whl" | tail -n 1)
blitzpy_version=$(echo ${blitzpy_wheel} | grep -oE "([0-9]\.[0-9]\.[0-9])")
echo "# BlitzPy changed --> UPDATING to Version ${blitzpy_version}"
2020-05-31 18:50:21 +01:00
sudo -H /usr/bin/python -m pip install "/home/admin/raspiblitz/home.admin/BlitzPy/dist/${blitzpy_wheel}" >/dev/null 2>&1
2020-05-23 15:59:58 +01:00
fi
2020-01-21 20:56:18 +01:00
if [ "${touchscreen}" = "1" ]; then
echo "# Checking if the content of BlitzTUI changed .."
checkSumBlitzTUIAfter=$(find /home/admin/raspiblitz/home.admin/BlitzTUI -type f -exec md5sum {} \; | md5sum)
echo "# checkSumBlitzTUIBefore = ${checkSumBlitzTUIBefore}"
echo "# checkSumBlitzTUIAfter = ${checkSumBlitzTUIAfter}"
2020-10-06 21:13:05 +02:00
if [ "${checkSumBlitzTUIBefore}" = "${checkSumBlitzTUIAfter}" ] && [ ${install} -eq 0 ] && [ ${clean} -eq 0 ]; then
echo "# BlitzTUI did not changed."
2020-01-22 12:02:10 +01:00
else
echo "# BlitzTUI changed --> UPDATING TOUCHSCREEN INSTALL ..."
2020-06-03 14:18:50 +02:00
sudo /home/admin/config.scripts/blitz.touchscreen.sh update
2020-01-22 12:02:10 +01:00
fi
2020-01-21 20:56:18 +01:00
fi
echo "# ******************************************"
2020-06-04 20:31:34 +02:00
echo "# OK - shell scripts and assets are synced"
2020-05-23 15:59:58 +01:00
echo "# Reboot recommended"