summaryrefslogtreecommitdiff
path: root/src/sogrep.in
diff options
context:
space:
mode:
authornl6720 <nl6720@gmail.com>2022-09-10 12:44:49 +0300
committernl6720 <nl6720@gmail.com>2023-03-16 19:03:56 +0200
commitb34814419dff4c266201c7ee2402bdf9648c6078 (patch)
treeb3383bc04054b04382a256ae9847db0b877c4515 /src/sogrep.in
parent6dd7be3fd4d3104101f5a8bbf0f12fcfe8124fd7 (diff)
downloaddevtools-b34814419dff4c266201c7ee2402bdf9648c6078.tar.xz
sogrep: do not hardcode the mirror
Use the first mirror that is configured for each repo in pacman.conf. With the default configuration, this means to use the first mirror from /etc/pacman.d/mirrorlist. If a repo is not configured in pacman.conf, fall back to https://geo.mirror.pkgbuild.com.
Diffstat (limited to 'src/sogrep.in')
-rw-r--r--src/sogrep.in25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/sogrep.in b/src/sogrep.in
index d1ca1a1..031d28e 100644
--- a/src/sogrep.in
+++ b/src/sogrep.in
@@ -9,7 +9,7 @@
m4_include(lib/common.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)
@@ -23,11 +23,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 +41,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