summaryrefslogtreecommitdiff
path: root/src/sogrep.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/sogrep.in')
-rw-r--r--src/sogrep.in33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/sogrep.in b/src/sogrep.in
index d1ca1a1..0ee05cc 100644
--- a/src/sogrep.in
+++ b/src/sogrep.in
@@ -6,13 +6,17 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
-m4_include(lib/common.sh)
+_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@}
+# shellcheck source=src/lib/common.sh
+source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh
+# shellcheck source=src/lib/valid-repos.sh
+source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-repos.sh
+
# globals
-: ${SOLINKS_MIRROR:="https://mirror.pkgbuild.com"}
+fallback_mirror='https://geo.mirror.pkgbuild.com'
: ${SOCACHE_DIR:="${XDG_CACHE_HOME:-${HOME}/.cache}/sogrep"}
-m4_include(lib/valid-repos.sh)
arches=('x86_64')
# options
@@ -23,11 +27,16 @@ source /usr/share/makepkg/util/parseopts.sh
source /usr/share/makepkg/util/util.sh
recache() {
- local repo arch verbosity=-s
+ local repo arch fallback_linksdburl linksdburl mirror verbosity=-s
(( VERBOSE )) && verbosity=--progress-bar
for repo in "${_repos[@]}"; do
+ if [[ -n "$SOLINKS_MIRROR" ]]; then
+ mirror="$SOLINKS_MIRROR"
+ elif ! mirror="$(set -o pipefail; pacman-conf --repo "$repo" Server 2>/dev/null | head -n1)"; then
+ mirror="$fallback_mirror"
+ fi
for arch in "${arches[@]}"; do
# delete extracted tarballs from previous sogrep versions
rm -rf "${SOCACHE_DIR}/${arch}/${repo}"
@@ -36,8 +45,20 @@ recache() {
local dbpath=${SOCACHE_DIR}/${arch}/${repo}.links.tar.gz
mkdir -p "${dbpath%/*}"
(( VERBOSE )) && echo "Fetching ${repo}.links.tar.gz..."
- if ! curl -fLR "${verbosity}" -o "${dbpath}" -z "${dbpath}" \
- "${SOLINKS_MIRROR}/${repo}/os/${arch}/${repo}.links.tar.gz"; then
+
+ if [[ "$mirror" == *"/${repo}/os/${arch}" ]]; then
+ linksdburl="${mirror}/${repo}.links.tar.gz"
+ else
+ linksdburl="${mirror}/${repo}/os/${arch}/${repo}.links.tar.gz"
+ fi
+ fallback_linksdburl="${fallback_mirror}/${repo}/os/${arch}/${repo}.links.tar.gz"
+
+ if curl -fLR "${verbosity}" -o "${dbpath}" -z "${dbpath}" "$linksdburl"; then
+ :
+ elif [[ "$linksdburl" != "$fallback_linksdburl" ]] \
+ && curl -fLR "${verbosity}" -o "${dbpath}" -z "${dbpath}" "$fallback_linksdburl"; then
+ :
+ else
echo "error: failed to download links database for repo ${repo}"
exit 1
fi