Files
UltraGrid/data/scripts/fetch_submodule.sh
Martin Pulec 32089545ca fetch_submodule.sh: remove directory if needed
+ fixed lowercased $module
2021-03-03 12:07:10 +01:00

45 lines
1.7 KiB
Bash

## fetches a submodule
##
## @param $1 name
## @param $2 fallback Gzip URL
## @param $3 fallback Git URL
## @param $4 if set to 1, report submodule update
## @retval 1 submodule was updated (and $4 was set to 1)
## @retval 0 otherwise
fetch_submodule() {
MODULE=$1
FALLBACK_URL=$2
FALLBACK_GIT_URL=$3
SUBMODULE_UPDATED= # assume that submodule have not been updated
printf "Downloading ${MODULE}... "
if ! command -v git >/dev/null; then
if [ ! -d ext-deps/$MODULE ]; then
echo "git not found - trying to download a release"
mkdir -p ext-deps/tmp
curl -L $FALLBACK_URL | tar -C ext-deps/tmp -xz
[ -d ext-deps/$MODULE ] && rmdir ext-deps/$MODULE
mv ext-deps/tmp/* ext-deps/$MODULE
rmdir ext-deps/tmp
else
echo "skipped (ext-deps/$MODULE is already present)"
fi
elif ! git branch >/dev/null 2>&1; then
# we are not in UltraGrid git repository but can use git to download
if [ ! -d ext-deps/$MODULE ]; then
echo "git submodule found - trying to clone"
git clone $FALLBACK_GIT_URL ext-deps/$MODULE
else
echo "skipped (ext-deps/$MODULE is already present)"
fi
else
SUBMODULE_UPDATED=`git submodule update --init ext-deps/$MODULE`
if [ -z "$SUBMODULE_UPDATED" ]; then
echo "not needed"
return 0
fi
return ${4:-0}
fi
return 0
}