summaryrefslogtreecommitdiff
path: root/include/git.sh
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2025-05-13 22:00:28 +0100
committerLeah Rowe <leah@libreboot.org>2025-05-13 22:00:28 +0100
commitb04c86e5740f92cbea708f52a444df3aa1a2061f (patch)
treea0bac325f3df1373c4754826fb03bdcd0ee137bd /include/git.sh
parent3c23ff4fa1873e9170326141e31eb588d71a7d3a (diff)
git.sh: rename to get.sh
it now handles more than just git, and i forsee it handling even more in the future, e.g. rsync, ftp, bittorrent. Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'include/git.sh')
-rw-r--r--include/git.sh176
1 files changed, 0 insertions, 176 deletions
diff --git a/include/git.sh b/include/git.sh
deleted file mode 100644
index 9405828e..00000000
--- a/include/git.sh
+++ /dev/null
@@ -1,176 +0,0 @@
-# SPDX-License-Identifier: GPL-3.0-or-later
-# Copyright (c) 2020-2021,2023-2025 Leah Rowe <leah@libreboot.org>
-# Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
-
-eval "`setvars "" loc url bkup_url subfile subhash subrepo subrepo_bkup \
- depend subfile_bkup repofail`"
-
-tmpgit="$xbmklocal/gitclone"
-tmpgitcache="$XBMK_CACHE/tmpgit"
-
-fetch_targets()
-{
- e "src/$project/$tree" d && return 0
-
- printf "Creating %s tree %s\n" "$project" "$tree"
- git_prep "$url" "$bkup_url" "$xbmkpwd/$configdir/$tree/patches" \
- "src/$project/$tree" with_submodules
- nuke "$project/$tree" "$project/$tree"
-}
-
-fetch_project()
-{
- eval "`setvars "" xtree`"
- eval "`setcfg "config/git/$project/pkg.cfg"`"
-
- chkvars url
-
- [ -n "$xtree" ] && x_ ./mk -f coreboot "$xtree"
- [ -z "$depend" ] || for d in $depend ; do
- printf "'%s' needs '%s'; grabbing '%s'\n" "$project" "$d" "$d"
- x_ ./mk -f $d
- done
- clone_project
-
- for x in config/git/*; do
- [ -d "$x" ] && nuke "${x##*/}" "src/${x##*/}" 2>/dev/null; :
- done; :
-}
-
-clone_project()
-{
- loc="$XBMK_CACHE/clone/$project" && singletree "$project" && \
- loc="src/$project"
- printf "Downloading project '%s' to '%s'\n" "$project" "$loc"
-
- e "$loc" d missing && remkdir "${tmpgit%/*}" && git_prep \
- "$url" "$bkup_url" "$xbmkpwd/config/$project/patches" "$loc"; :
-}
-
-git_prep()
-{
- _patchdir="$3"
- _loc="$4" # $1 and $2 are gitrepo and gitrepo_backup
-
- chkvars rev
- xbmkget "$1" "$2" "$tmpgit" "$rev" git "$_patchdir"
- if singletree "$project" || [ $# -gt 4 ]; then
- dx_ fetch_submodule "$mdir/module.list"
- fi
-
- [ "$_loc" = "${_loc%/*}" ] || x_ mkdir -p "${_loc%/*}"
- x_ mv "$tmpgit" "$_loc"
-}
-
-fetch_submodule()
-{
- mcfgdir="$mdir/${1##*/}"; eval \
- "`setvars "" subhash subrepo subrepo_bkup subfile subfile_bkup st`"
- [ ! -f "$mcfgdir/module.cfg" ] || . "$mcfgdir/module.cfg" || \
- err "! . $mcfgdir/module.cfg"
-
- for xt in repo file; do
- _seval="if [ -n \"\$sub$xt\" ] || [ -n \"\$sub${xt}_bkup\" ]"
- eval "$_seval; then st=\"\$st \$xt\"; fi"
- done
- st="${st# }" && [ "$st" = "repo file" ] && err "$mdir: repo+file"
-
- [ -z "$st" ] && return 0 # subrepo/subfile not defined
- chkvars "sub${st}" "sub${st}_bkup" "subhash"
-
- [ "$st" = "file" ] && xbmkget "$subfile" "$subfile_bkup" \
- "$tmpgit/$1" "$subhash" && return 0
- x_ rm -Rf "$tmpgit/$1"
- xbmkget "$subrepo" "$subrepo_bkup" "$tmpgit/$1" "$subhash" git \
- "$mdir/${1##*/}/patches"
-}
-
-# can grab from the internet, or copy locally.
-# if copying locally, it can only copy a file.
-xbmkget()
-{
- _dlop="curl" && [ $# -gt 4 ] && _dlop="$5"
- [ "$_dlop" = "curl" ] || [ "$_dlop" = "copy" ] || \
- [ "$_dlop" = "git" ] || err "$1 $2 $3 $4: Bad dlop type: '$_dlop'"
-
- for url in "$1" "$2"; do
- [ -n "$url" ] && try_file "$url" "$_dlop" "$@" && return 0
- done && err "$1 $2 $3 $4: not downloaded"; :
-}
-
-try_file()
-{
- cached="file/$6" && [ "$2" = "git" ] && cached="clone/${3##*/}" && \
- cached="${cached%.git}"
- cached="$XBMK_CACHE/$cached"
- x_ mkdir -p "${5%/*}" "${cached%/*}"
-
- echk="d" && dl_fail="n" && [ "$2" != "git" ] && echk="f" && \
- bad_checksum "$6" "$cached" 2>/dev/null && dl_fail="y"
- [ "$dl_fail" = "n" ] && e "$5" $echk && return 0
-
- [ "$2" != "git" ] && x_ rm -f "$cached"
-
- try_$2 "$cached" "$@" || return 1
-
- if [ "$2" = "git" ]; then
- tmpclone "$cached" "$5" "$6" "$8" || return 1
- else
- bad_checksum "$6" "$cached" && return 1
- [ "$cached" != "$5" ] && x_ cp "$cached" "$5"
- fi
-}
-
-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; :
-}
-
-try_git()
-{
- gitdest="`findpath "$1"`" || err "Can't get readpath for '$1'"
- x_ rm -Rf "$tmpgitcache"
-
- [ -d "$gitdest" ] || git clone "$2" "$tmpgitcache" || return 1
- [ -d "$gitdest" ] || x_ mkdir -p "${gitdest##*/}"
- [ -d "$gitdest" ] || x_ mv "$tmpgitcache" "$gitdest"
-
- git -C "$gitdest" remote add main "$4" 2>/dev/null || :
- git -C "$gitdest" remote add backup "$5" 2>/dev/null || :
- git -C "$gitdest" fetch --all || :
- git -C "$gitdest" pull --all || :
-}
-
-bad_checksum()
-{
- [ "$(sha512sum "$2" | awk '{print $1}')" != "$1" ] || return 1
- printf "Bad checksum for file: %s\n" "$2" 1>&2; rm -f "$2" || :; :
-}
-
-tmpclone()
-{
- [ -d "$2" ] && return 0
- printf "Creating git clone '%s' from '%s'\n" "$2" "$1"
- ( x_ git clone "$1" "$2" ) || return 1
- ( x_ git -C "$2" reset --hard "$3" ) || return 1
- ( fx_ "eval x_ git -C \"$2\" am" find "$4" -type f ) || return 1; :
-}
-
-nuke()
-{
- e "config/${1%/}/nuke.list" f missing || while read -r nukefile; do
- rmf="src/${2%/}/$nukefile" && [ -L "$rmf" ] && continue
- e "$rmf" e missing || x_ rm -Rf "$rmf"
- done < "config/${1%/}/nuke.list"; :
-}