raspiblitz/home.admin/config.scripts/blitz.github.sh

198 lines
7.4 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"
echo "blitz.github.sh info"
2021-12-19 23:04:49 +01:00
echo "blitz.github.sh [-run|-install|-justinstall] branch [repo]"
2020-05-31 18:50:21 +01:00
exit 1
fi
2020-01-21 20:56:18 +01:00
source /mnt/hdd/raspiblitz.conf 2>/dev/null
2018-12-07 23:58:20 +01:00
cd /home/admin/raspiblitz
# 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)
commitHashLong=$(git log -n1 --format=format:"%H")
commitHashShort=${commitHashLong:0:7}
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}'"
echo "commitHashLong='${commitHashLong}'"
echo "commitHashShort='${commitHashShort}'"
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
2021-08-27 03:59:21 -04:00
# "-run" its 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
2021-08-27 03:59:21 -04:00
echo "# forcing github over vagrant sync"
2020-10-14 01:31:27 +02:00
vagrant=0
fi
2020-06-01 22:53:34 +02: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 "# ******************************************"
2021-12-19 16:59:25 +01:00
git config pull.rebase true
2020-10-14 01:31:27 +02:00
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)"
2021-12-19 22:47:42 +01:00
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
echo "# COPYING from GIT-Directory to /home/admin/"
2021-12-19 23:18:00 +01:00
echo "# - basic admin files"
2021-12-19 23:04:49 +01:00
sudo rm -f *.sh
sudo -u admin cp /home/admin/raspiblitz/home.admin/.tmux.conf /home/admin
2021-12-19 23:18:36 +01:00
sudo -u admin cp /home/admin/raspiblitz/home.admin/*.* /home/admin 2>/dev/null
sudo -u admin chmod 755 *.sh
2021-12-19 23:18:00 +01:00
echo "# - asset directory"
2021-12-19 23:04:49 +01:00
sudo rm -rf assets
sudo -u admin cp -R /home/admin/raspiblitz/home.admin/assets /home/admin/assets
2021-12-19 23:18:00 +01:00
echo "# - config.scripts directory"
2021-12-19 23:04:49 +01:00
sudo rm -rf /home/admin/config.scripts
2021-12-19 23:18:36 +01:00
sudo -u admin cp -R /home/admin/raspiblitz/home.admin/config.scripts /home/admin/config.scripts
sudo -u admin chmod 755 /home/admin/config.scripts/*.sh
2021-12-19 23:04:49 +01:00
sudo -u admin chmod 755 /home/admin/config.scripts/*.py
2021-12-19 23:18:00 +01:00
echo "# - setup.scripts directory"
2021-12-19 23:04:49 +01:00
sudo rm -rf /home/admin/setup.scripts
2021-12-19 23:18:36 +01:00
sudo -u admin cp -R /home/admin/raspiblitz/home.admin/setup.scripts /home/admin/setup.scripts
sudo -u admin chmod 755 /home/admin/setup.scripts/*.sh
2021-12-19 23:04:49 +01:00
sudo -u admin chmod 755 /home/admin/config.scripts/*.py
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"