Skip git steps in shell scripts if not a valid git repo (#524)

* Skip git steps if no .git dir exists

* Tweak message

* Check for git repo in start.sh

* Fix logic & cleanup

* Make a different check for git repo

* Make a different check for git repo

* Make a different check for git repo
This commit is contained in:
Daniel Markstedt 2021-12-23 09:08:50 -08:00 committed by GitHub
parent 47282c43b9
commit 5817ca6df5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 22 deletions

View File

@ -222,6 +222,15 @@ function stopOldWebInterface() {
# Checks for upstream changes to the git repo and fast-forwards changes if needed
function updateRaScsiGit() {
cd "$BASE" || exit 1
set +e
git rev-parse --is-inside-work-tree &> /dev/null
if [[ $? -ge 1 ]]; then
echo "Warning: This does not seem to be a valid clone of a git repository. I will not be able to pull the latest code."
return 0
fi
set -e
stashed=0
if [[ $(git diff --stat) != '' ]]; then
echo "There are local changes to the RaSCSI code; we will stash and reapply them."

View File

@ -77,28 +77,34 @@ fi
# Create the venv if it doesn't exist
if ! test -e venv; then
echo "Creating python venv for OLED Screen"
python3 -m venv venv
echo "Activating venv"
source venv/bin/activate
echo "Installing requirements.txt"
pip3 install wheel
CFLAGS="$COMPILER_FLAGS" pip3 install -r requirements.txt
git rev-parse HEAD > current
echo "Creating python venv for OLED Screen"
python3 -m venv venv
echo "Activating venv"
source venv/bin/activate
echo "Installing requirements.txt"
pip3 install wheel
CFLAGS="$COMPILER_FLAGS" pip3 install -r requirements.txt
git rev-parse HEAD > current
fi
source venv/bin/activate
# Detect if someone updates - we need to re-run pip3 install.
if ! test -e current; then
git rev-parse > current
# Detect if someone updates the git repo - we need to re-run pip3 install.
set +e
git rev-parse --is-inside-work-tree &> /dev/null
if [[ $? -eq 0 ]]; then
set -e
if ! test -e current; then
git rev-parse > current
elif [ "$(cat current)" != "$(git rev-parse HEAD)" ]; then
echo "New version detected, updating libraries from requirements.txt"
CFLAGS="$COMPILER_FLAGS" pip3 install -r requirements.txt
git rev-parse HEAD > current
fi
else
if [ "$(cat current)" != "$(git rev-parse HEAD)" ]; then
echo "New version detected, updating requirements.txt"
CFLAGS="$COMPILER_FLAGS" pip3 install -r requirements.txt
git rev-parse HEAD > current
fi
echo "Warning: Not running from a valid git repository. Will not be able to update the code."
fi
set -e
# parse arguments
while [ "$1" != "" ]; do

View File

@ -57,16 +57,22 @@ fi
source venv/bin/activate
# Detect if someone updates - we need to re-run pip3 install.
if ! test -e current; then
git rev-parse > current
else
if [ "$(cat current)" != "$(git rev-parse HEAD)" ]; then
echo "New version detected, updating requirements.txt"
# Detect if someone updates the git repo - we need to re-run pip3 install.
set +e
git rev-parse --is-inside-work-tree &> /dev/null
if [[ $? -eq 0 ]]; then
set -e
if ! test -e current; then
git rev-parse > current
elif [ "$(cat current)" != "$(git rev-parse HEAD)" ]; then
echo "New version detected, updating libraries from requirements.txt"
pip3 install -r requirements.txt
git rev-parse HEAD > current
fi
else
echo "Warning: Not running from a valid git repository. Will not be able to update the code."
fi
set -e
# parse arguments
while [ "$1" != "" ]; do