1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#!/bin/bash
# Copyright (c) Contributors to the Apptainer project, established as
# Apptainer a Series of LF Projects LLC.
# For website terms of use, trademark policy, privacy policy and other
# project policies see https://lfprojects.org/policies
#
# Download additional source urls listed in rpm into directory in $1.
# Assumes being run from the top of the apptainer source directory.
if [ -n "$2" ] || [[ "$1" = -* ]]; then
echo "Usage: $0 [downloaddir]" >&2
echo "The default downloaddir is '.'" >&2
exit 2
fi
DIR=.
if [ -n "$1" ]; then
DIR="$1"
fi
set -ex
${0%/*}/clean-dependencies $1
SPEC=dist/rpm/apptainer.spec.in
SUBS="$(sed -n "s/.*%global //p" $SPEC)"
# Expected format for sources that have a different base path than the URL
# is a line beginning "# URL:" followed by the URL, then the source with just
# the base path.
sed -n -e '/^# URL:/{s/^# //;s/%%/%/g;p}' -e 's/^Source[1-9][0-9]*: //p' -e 's/^Patch[1-9][0-9]*: //p' $SPEC | while read -r LINE; do
# first apply substitutions
LINE=$(echo "$SUBS" | (while read -r FROM TO; do
LINE="${LINE//%\{$FROM\}/$TO}"
done
echo "$LINE"))
if [[ "$LINE" = *http* ]]; then
URL="${LINE/*http/http}"
if [[ "$LINE" = "URL:"*http* ]]; then
# the file name is on the next line
continue
fi
# take the file name from the base of the URL
LINE="${LINE/*\//}"
fi
if [ -n "$GITHUB_TOKEN" ] && [[ "$URL" = *github.com/*.patch ]]; then
# use github API instead because the public URL downloads
# sometimes hit server busy (429) when run in github actions
URL="$(echo "$URL"|sed -e 's,github.com/,api.github.com/repos/,' \
-e 's,/pull/,/pulls/,' -e 's,\.patch,,')"
curl -f -L -sS -o $DIR/$LINE \
-H "Accept: application/vnd.github.diff" \
-H "Authorization: Bearer $GITHUB_TOKEN" $URL
else
curl -f -L -sS -o $DIR/$LINE $URL
fi
if [[ "$LINE" = gocryptfs*.tar.gz ]]; then
# Also download go dependencies
echo "Adding vendor to $LINE" >&2
pushd "$DIR"
SUBDIR="${LINE%.tar.gz}"
trap "rm -rf $SUBDIR" 0
tar -xf $LINE
cd $SUBDIR
go mod vendor
cd ..
tar -czf $LINE "$SUBDIR"
rm -rf "$SUBDIR"
trap "" 0
popd
fi
done
|