summaryrefslogtreecommitdiff
path: root/include/git.sh
diff options
context:
space:
mode:
Diffstat (limited to 'include/git.sh')
-rw-r--r--include/git.sh83
1 files changed, 56 insertions, 27 deletions
diff --git a/include/git.sh b/include/git.sh
index 81c75806..0091c832 100644
--- a/include/git.sh
+++ b/include/git.sh
@@ -57,11 +57,8 @@ git_prep()
dx_ fetch_submodule "$mdir/module.list"
fi
- [ "$_loc" != "$XBMK_CACHE/repo/$project" ] && \
- [ "$XBMK_RELEASE" = "y" ] && rmgit "$tmpgit"
-
[ "$_loc" = "${_loc%/*}" ] || x_ mkdir -p "${_loc%/*}"
- mv "$tmpgit" "$_loc" || err "git_prep: !mv $tmpgit $_loc"
+ x_ mv "$tmpgit" "$_loc"
}
fetch_submodule()
@@ -82,43 +79,75 @@ fetch_submodule()
[ "$st" = "file" ] && xbmkget "$subfile" "$subfile_bkup" \
"$tmpgit/$1" "$subhash" && return 0
- rm -Rf "$tmpgit/$1" || err "!rm '$mdir' '$1'"
+ x_ rm -Rf "$tmpgit/$1"
tmpclone "$subrepo" "$subrepo_bkup" "$tmpgit/$1" "$subhash" \
"$mdir/${1##*/}/patches"
}
-tmpclone()
+# can grab from the internet, or copy locally.
+# if copying locally, it can only copy a file.
+xbmkget()
{
- livepull="n" && [ "$repofail" = "y" ] && \
- printf "Cached clone failed; trying online.\n" 1>&2 && livepull="y"
+ _dlop="curl" && [ $# -gt 4 ] && _dlop="$5"
+ x_ mkdir -p "${3%/*}" "$XBMK_CACHE/file"
+ for url in "$1" "$2"; do
+ [ -n "$url" ] && try_file "$url" "$_dlop" "$@" && return 0
+ done && err "$1 $2 $3 $4: not downloaded"; :
+}
- repofail="n"
+try_file()
+{
+ cached="$XBMK_CACHE/file/$6"
+ dl_fail="n" # 1 url, 2 url backup, 3 destination, 4 checksum
+ bad_checksum "$6" "$cached" 2>/dev/null && dl_fail="y"
+ [ "$dl_fail" = "n" ] && e "$5" f && return 0
- [ $# -lt 6 ] || rm -Rf "$3" || err "git retry: !rm $3 ($1)"
- repodir="$XBMK_CACHE/repo/${1##*/}" && [ $# -gt 5 ] && repodir="$3"
- mkdir -p "$XBMK_CACHE/repo" || err "!rmdir $XBMK_CACHE/repo"
+ x_ rm -f "$cached"
+ [ "$2" = "curl" ] || [ "$2" = "copy" ] || \
+ err "$3 $4 $5 $6: Unsupported dlop type: '$2'"
- if [ "$livepull" = "y" ] && [ ! -d "$repodir" ]; then
- git clone "$1" "$repodir" || git clone $2 "$repodir" || \
- err "!clone $1 $2 $repodir $4 $5" #
- elif [ -d "$repodir" ] && [ $# -lt 6 ]; then
- git -C "$repodir" pull || sleep 3 || git -C "$repodir" pull \
- || sleep 3 || git -C "$repodir" pull || :
- fi
- (
- [ $# -gt 5 ] || git clone "$repodir" "$3" || err "!clone $repodir $3"
- git -C "$3" reset --hard "$4" || err "!reset $1 $2 $3 $4 $5"
- fx_ "eval x_ git -C \"$3\" am" find "$5" -type f
- ) || repofail="y"
+ try_$2 "$cached" "$@" || return 1
+
+ bad_checksum "$6" "$cached" && return 1
+ [ "$cached" = "$5" ] || x_ cp "$cached" "$5"; :
+}
+
+try_curl()
+{
+ _ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
+ curl --location --retry 3 -A "$_ua" "$2" -o "$1" || \
+ wget --tries 3 -U "$_ua" "$2" -O "$1" || return 1; :
+}
+
+try_copy()
+{
+ [ -L "$2" ] && printf "dl %s %s %s %s: '%s' is a symlink\n" \
+ "$4" "$5" "$6" "$7" "$2" 1>&2 && return 1
+ [ ! -f "$2" ] && printf "dl %s %s %s %s: '%s' not a file\n" \
+ "$4" "$5" "$6" "$7" "$2" 1>&2 && return 1
+ cp "$2" "$1" || return 1; :
+}
+
+bad_checksum()
+{
+ [ "$(sha512sum "$2" | awk '{print $1}')" != "$1" ] || return 1
+ printf "Bad checksum for file: %s\n" "$2" 1>&2; rm -f "$2" || :; :
+}
- [ "$repofail" = "y" ] && [ $# -lt 6 ] && tmpclone "$@" retry
- [ "$repofail" = "y" ] && err "!clone $1 $2 $3 $4 $5"; :
+tmpclone()
+{
+ [ -d "$3" ] && return 0
+ printf "Creating git clone '%s' from '%s', '%s'\n" "$3" "$1" "$2"
+ git clone "$1" "$3" || x_ rm -Rf "$3"
+ [ -d "$3" ] || x_ git clone "$2" "$3"
+ x_ git -C "$3" reset --hard "$4"
+ fx_ "eval x_ git -C \"$3\" am" find "$5" -type f
}
nuke()
{
e "config/${1%/}/nuke.list" f missing || while read -r nukefile; do
rmf="src/${2%/}/$nukefile" && [ -L "$rmf" ] && continue
- e "$rmf" e missing || rm -Rf "$rmf" || err "!rm $rmf, ${2%/}"
+ e "$rmf" e missing || x_ rm -Rf "$rmf"
done < "config/${1%/}/nuke.list"; :
}