mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-07-28 05:06:43 +00:00
scripts/get_git: general cleanup
Signed-off-by: Ian Leonard <antonlacon@gmail.com>
This commit is contained in:
parent
843cf6fe13
commit
ff18980dd8
103
scripts/get_git
103
scripts/get_git
@ -12,14 +12,14 @@
|
|||||||
# PKG_GIT_SUBMODULE_DEPTH (optional) history of submodules to clone, must be a number
|
# PKG_GIT_SUBMODULE_DEPTH (optional) history of submodules to clone, must be a number
|
||||||
|
|
||||||
_get_repo_already_downloaded() {
|
_get_repo_already_downloaded() {
|
||||||
if [ -d $PACKAGE ]; then
|
if [ -d "${PACKAGE}" ]; then
|
||||||
(
|
(
|
||||||
cd $PACKAGE
|
cd "${PACKAGE}"
|
||||||
_get_repo_clean
|
_get_repo_clean
|
||||||
[ -n "$(git ls-remote . | grep -m1 HEAD | awk "/^${PKG_VERSION}/ {print \$1;}")" ] || exit 1
|
[ -n "$(git ls-remote . | grep -m1 HEAD | awk "/^${PKG_VERSION}/ {print \$1;}")" ] || die "ERROR: ${PACKAGE}: failed to determine git HEAD"
|
||||||
[ "$PKG_URL" = "$(git remote get-url origin)" ] || exit 1
|
[ "${PKG_URL}" = "$(git remote get-url origin)" ] || die "ERROR: ${PACKAGE}: failed to obtain URL of origin"
|
||||||
[ -z "$PKG_GIT_CLONE_BRANCH" ] && exit 0
|
[ -z "${PKG_GIT_CLONE_BRANCH}" ] && exit 0
|
||||||
[ "$PKG_GIT_CLONE_BRANCH" = "$(git branch | grep ^\* | cut -d ' ' -f2)" ] || exit 1
|
[ "${PKG_GIT_CLONE_BRANCH}" = "$(git branch | grep ^\* | cut -d ' ' -f2)" ] || die "ERROR: ${PACKAGE}: failed to determine current git branch"
|
||||||
exit 0
|
exit 0
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
@ -36,104 +36,101 @@ _get_repo_clean() {
|
|||||||
# Latest file already present, exit now...
|
# Latest file already present, exit now...
|
||||||
_get_repo_already_downloaded && exit 0
|
_get_repo_already_downloaded && exit 0
|
||||||
|
|
||||||
lock_source_dir $1
|
lock_source_dir "${1}"
|
||||||
|
|
||||||
# Check again in case of concurrent access - if nothing needs to be downloaded, exit now...
|
# Check again in case of concurrent access - if nothing needs to be downloaded, exit now...
|
||||||
_get_repo_already_downloaded && exit 0
|
_get_repo_already_downloaded && exit 0
|
||||||
|
|
||||||
# At this point, we need to download something...
|
# At this point, we need to download something...
|
||||||
printf "%${BUILD_INDENT}c $(print_color CLR_GET "GET") $1 (git)\n" ' '>&$SILENT_OUT
|
printf "%${BUILD_INDENT}c $(print_color CLR_GET "GET") ${1} (git)\n" ' '>&$SILENT_OUT
|
||||||
export BUILD_INDENT=$((${BUILD_INDENT:-1}+$BUILD_INDENT_SIZE))
|
export BUILD_INDENT=$((${BUILD_INDENT:-1}+${BUILD_INDENT_SIZE}))
|
||||||
|
|
||||||
rm -f $STAMP_URL $STAMP_SHA
|
rm -f "${STAMP_URL}" "${STAMP_SHA}"
|
||||||
|
|
||||||
GIT_CLONE_PARAMS=""
|
GIT_CLONE_PARAMS=""
|
||||||
GIT_SUBMODULE_PARAMS=""
|
GIT_SUBMODULE_PARAMS=""
|
||||||
|
|
||||||
[ -n "$PKG_GIT_CLONE_BRANCH" ] && GIT_CLONE_PARAMS="$GIT_CLONE_PARAMS --branch $PKG_GIT_CLONE_BRANCH"
|
[ -n "${PKG_GIT_CLONE_BRANCH}" ] && GIT_CLONE_PARAMS="${GIT_CLONE_PARAMS} --branch ${PKG_GIT_CLONE_BRANCH}"
|
||||||
[ "$PKG_GIT_CLONE_SINGLE" = "yes" ] && GIT_CLONE_PARAMS="$GIT_CLONE_PARAMS --single-branch"
|
[ "${PKG_GIT_CLONE_SINGLE}" = "yes" ] && GIT_CLONE_PARAMS="${GIT_CLONE_PARAMS} --single-branch"
|
||||||
|
|
||||||
if [ -n "$PKG_GIT_CLONE_DEPTH" ]; then
|
if [ -n "${PKG_GIT_CLONE_DEPTH}" ]; then
|
||||||
if [[ $PKG_GIT_CLONE_DEPTH =~ ^[0-9]+$ ]]; then
|
if [[ "${PKG_GIT_CLONE_DEPTH}" =~ ^[0-9]+$ ]]; then
|
||||||
GIT_CLONE_PARAMS="$GIT_CLONE_PARAMS --depth $PKG_GIT_CLONE_DEPTH"
|
GIT_CLONE_PARAMS="$GIT_CLONE_PARAMS --depth ${PKG_GIT_CLONE_DEPTH}"
|
||||||
else
|
else
|
||||||
echo "Fatal: PKG_GIT_CLONE_DEPTH is not a number! ($PKG_GIT_CLONE_DEPTH)"
|
die "ERROR: PKG_GIT_CLONE_DEPTH is not a number! (${PKG_GIT_CLONE_DEPTH})"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$PKG_GIT_SUBMODULE_DEPTH" ]; then
|
if [ -n "${PKG_GIT_SUBMODULE_DEPTH}" ]; then
|
||||||
if [[ $PKG_GIT_SUBMODULE_DEPTH =~ ^[0-9]+$ ]]; then
|
if [[ "${PKG_GIT_SUBMODULE_DEPTH}" =~ ^[0-9]+$ ]]; then
|
||||||
GIT_SUBMODULE_PARAMS="$GIT_SUBMODULE_PARAMS --depth $PKG_GIT_SUBMODULE_DEPTH"
|
GIT_SUBMODULE_PARAMS="${GIT_SUBMODULE_PARAMS} --depth ${PKG_GIT_SUBMODULE_DEPTH}"
|
||||||
else
|
else
|
||||||
echo "Fatal: PKG_GIT_SUBMODULE_DEPTH is not a number! ($PKG_GIT_SUBMODULE_DEPTH)"
|
die "ERROR: PKG_GIT_SUBMODULE_DEPTH is not a number! (${PKG_GIT_SUBMODULE_DEPTH})"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
GIT_FOUND="no"
|
GIT_FOUND="no"
|
||||||
opwd=$(pwd)
|
opwd=$(pwd)
|
||||||
for d in $SOURCES/$1/$1-* ; do
|
for d in "${SOURCES}/${1}/${1}-"* ; do
|
||||||
if [ -d "$d/.git" ]; then
|
if [ -d "${d}/.git" ]; then
|
||||||
if [ "${GIT_FOUND}" = "no" ]; then
|
if [ "${GIT_FOUND}" = "no" ]; then
|
||||||
cd $d
|
cd "${d}"
|
||||||
if [ "$PKG_URL" = "$(git remote get-url origin)" ]; then
|
if [ "${PKG_URL}" = "$(git remote get-url origin)" ]; then
|
||||||
if [ -n "$PKG_GIT_CLONE_BRANCH" -a $(git branch | grep "^\* ${PKG_GIT_CLONE_BRANCH}$" | wc -l) -eq 1 -o -z "$PKG_GIT_CLONE_BRANCH" ]; then
|
if [[ -z "${PKG_GIT_CLONE_BRANCH}"]] || [[ $(git branch | grep "^\* ${PKG_GIT_CLONE_BRANCH}$" | wc -l) -eq 1 ]]; then
|
||||||
GIT_FOUND="yes"
|
GIT_FOUND="yes"
|
||||||
GIT_DIR="$d"
|
GIT_DIR="${d}"
|
||||||
_get_repo_clean
|
_get_repo_clean
|
||||||
elif [ -n "$PKG_GIT_CLONE_BRANCH" -a $(git branch | grep "^ ${PKG_GIT_CLONE_BRANCH}$" | wc -l) -eq 1 ]; then
|
elif [ $(git branch | grep "^ ${PKG_GIT_CLONE_BRANCH}$" | wc -l) -eq 1 ]; then
|
||||||
GIT_FOUND="yes"
|
GIT_FOUND="yes"
|
||||||
GIT_DIR="$d"
|
GIT_DIR="${d}"
|
||||||
_get_repo_clean
|
_get_repo_clean
|
||||||
git checkout $PKG_GIT_CLONE_BRANCH
|
git checkout "${PKG_GIT_CLONE_BRANCH}"
|
||||||
elif [ -n "$PKG_GIT_CLONE_BRANCH" -a $(git branch -a | grep "^ remotes/origin/${PKG_GIT_CLONE_BRANCH}$" | wc -l) -eq 1 ]; then
|
elif [ $(git branch -a | grep "^ remotes/origin/${PKG_GIT_CLONE_BRANCH}$" | wc -l) -eq 1 ]; then
|
||||||
GIT_FOUND="yes"
|
GIT_FOUND="yes"
|
||||||
GIT_DIR="$d"
|
GIT_DIR="${d}"
|
||||||
_get_repo_clean
|
_get_repo_clean
|
||||||
git checkout -b $PKG_GIT_CLONE_BRANCH origin/$PKG_GIT_CLONE_BRANCH
|
git checkout -b "${PKG_GIT_CLONE_BRANCH}" "origin/${PKG_GIT_CLONE_BRANCH}"
|
||||||
else
|
else
|
||||||
printf "%${BUILD_INDENT}c $(print_color CLR_CLEAN "DELETE") ($d)\n" ' '>&$SILENT_OUT
|
printf "%${BUILD_INDENT}c $(print_color CLR_CLEAN "DELETE") (${d})\n" ' '>&$SILENT_OUT
|
||||||
cd "${opwd}"
|
cd "${opwd}"
|
||||||
rm -rf "$d"
|
rm -rf "${d}"
|
||||||
fi
|
fi
|
||||||
if [ "$GIT_FOUND" = "yes" ]; then
|
if [ "$GIT_FOUND" = "yes" ]; then
|
||||||
printf "%${BUILD_INDENT}c $(print_color CLR_GET "GIT PULL") $1\n" ' '>&$SILENT_OUT
|
printf "%${BUILD_INDENT}c $(print_color CLR_GET "GIT PULL") ${1}\n" ' '>&$SILENT_OUT
|
||||||
git pull
|
git pull
|
||||||
cd "${opwd}"
|
cd "${opwd}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
printf "%${BUILD_INDENT}c $(print_color CLR_CLEAN "DELETE") ($d)\n" ' '>&$SILENT_OUT
|
printf "%${BUILD_INDENT}c $(print_color CLR_CLEAN "DELETE") (${d})\n" ' '>&$SILENT_OUT
|
||||||
cd "${opwd}"
|
cd "${opwd}"
|
||||||
rm -rf "$d"
|
rm -rf "${d}"
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
printf "%${BUILD_INDENT}c $(print_color CLR_CLEAN "DELETE") ($d)\n" ' '>&$SILENT_OUT
|
|
||||||
rm -rf "$d"
|
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
printf "%${BUILD_INDENT}c $(print_color CLR_CLEAN "DELETE") (${d})\n" ' '>&$SILENT_OUT
|
||||||
|
rm -rf "${d}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
cd "${opwd}"
|
cd "${opwd}"
|
||||||
|
|
||||||
if [ "${GIT_FOUND}" = "no" ]; then
|
if [ "${GIT_FOUND}" = "no" ]; then
|
||||||
printf "%${BUILD_INDENT}c $(print_color CLR_GET "GIT CLONE") $1\n" ' '>&$SILENT_OUT
|
printf "%${BUILD_INDENT}c $(print_color CLR_GET "GIT CLONE") ${1}\n" ' '>&$SILENT_OUT
|
||||||
git clone $GIT_CLONE_PARAMS $PKG_URL $PACKAGE
|
git clone "${GIT_CLONE_PARAMS}" "${PKG_URL}" "${PACKAGE}"
|
||||||
else
|
else
|
||||||
if [ ! "${GIT_DIR}" = "${PACKAGE}" ]; then
|
if [ ! "${GIT_DIR}" = "${PACKAGE}" ]; then
|
||||||
mv "${GIT_DIR}" "${PACKAGE}"
|
mv "${GIT_DIR}" "${PACKAGE}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
(
|
( cd "${PACKAGE}"
|
||||||
cd $PACKAGE
|
[ $(git log --oneline --pretty=tformat:"%H" | grep "^${PKG_VERSION}" | wc -l) -eq 1 ] || die "There is no commit '${PKG_VERSION}' on branch '$(git branch | grep ^\* | cut -d ' ' -f2)' of package '${1}'! Aborting!"
|
||||||
[ $(git log --oneline --pretty=tformat:"%H" | grep "^$PKG_VERSION" | wc -l) -eq 1 ] || { echo "There is no commit '$PKG_VERSION' on branch '$(git branch | grep ^\* | cut -d ' ' -f2)' of package '$1'! Aborting!" ; exit 1 ; }
|
git reset --hard "${PKG_VERSION}"
|
||||||
git reset --hard $PKG_VERSION
|
printf "%${BUILD_INDENT}c $(print_color CLR_GET "GIT SUBMODULE") ${1}\n" ' '>&$SILENT_OUT
|
||||||
printf "%${BUILD_INDENT}c $(print_color CLR_GET "GIT SUBMODULE") $1\n" ' '>&$SILENT_OUT
|
git submodule update --init --recursive "${GIT_SUBMODULE_PARAMS}"
|
||||||
git submodule update --init --recursive $GIT_SUBMODULE_PARAMS
|
|
||||||
)
|
)
|
||||||
|
|
||||||
GIT_SHA=$(git ls-remote $PACKAGE | grep -m1 HEAD | awk '{print $1;}')
|
GIT_SHA=$(git ls-remote "${PACKAGE}" | grep -m1 HEAD | awk '{print $1;}')
|
||||||
|
|
||||||
if [ -n "$PKG_GIT_SHA" ]; then
|
if [ -n "${PKG_GIT_SHA}" ]; then
|
||||||
[ "$PKG_GIT_SHA" = "$GIT_SHA" ] || printf "%${BUILD_INDENT}c $(print_color CLR_WARNING "WARNING") Incorrect git hash in respository: got ${GIT_SHA}, wanted ${PKG_GIT_SHA}\n\n" ' '>&$SILENT_OUT
|
[ "${PKG_GIT_SHA}" = "${GIT_SHA}" ] || printf "%${BUILD_INDENT}c $(print_color CLR_WARNING "WARNING") Incorrect git hash in respository: got ${GIT_SHA}, wanted ${PKG_GIT_SHA}\n\n" ' '>&$SILENT_OUT
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user