From 83fa9900f9848660628dee0fba015c8414e26e23 Mon Sep 17 00:00:00 2001 From: Michael Biermann Date: Mon, 2 Sep 2019 17:44:58 +0200 Subject: [PATCH] =?UTF-8?q?self-update=20skript=20hinzugef=C3=BCgt.=20ToDo?= =?UTF-8?q?:=20Test,=20ob=20Internet=20verf=C3=BCgbar!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- startup.sh | 64 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/startup.sh b/startup.sh index 68b530a..e0cd1e8 100755 --- a/startup.sh +++ b/startup.sh @@ -1,13 +1,61 @@ #!/bin/bash -x -# wait for sonic-pi to start -sleep 90 -# set the default audio output to be the headphone jack -amixer cset numid=3 1 +SCRIPT=$(readlink -f "$0") +SCRIPTPATH=$(dirname "$SCRIPT") +SCRIPTNAME="$0" +ARGS="$@" + +UPSTREAM=${1:-'@{u}'} +LOCAL=$(git rev-parse @) #Hash of the current local commit (@ is a git shorthand) +REMOTE=$(git rev-parse "$UPSTREAM") #Hash of the current upstream commit +BASE=$(git merge-base @ "$UPSTREAM") #Hash of the commit at which the current branch and its upstream diverge + + +self_update() { + # Wait for Network + sleep 10 + + cd $SCRIPTPATH + git fetch + + if [ $LOCAL = $REMOTE ]; then + echo "Repo is Up-to-date" + + elif [ $LOCAL = $BASE ]; then + echo "Repo is not Up-to-date. Pulling!" + git pull --force + + echo "Executeing the new version..." + exec "$SCRIPTNAME" "$@" + + # Now exit this old instance + exit 0 + + else + echo "Diverged" + fi + + echo "Already the latest version. Now running the script. " + + +} + +main() { + # wait for sonic-pi to start + sleep 70 + + # set the default audio output to be the headphone jack + amixer cset numid=3 1 + + # set audio volume to full + amixer sset PCM 100% + + # play our tune + cat /home/pi/world-o-techno/world-o-techno.rb|sonic_pi +} + +self_update +main -# set audio volume to full -amixer sset PCM 100% -# play our tune -cat /home/pi/world-o-techno/world-o-techno.rb|sonic_pi