forked from BtbN/FFmpeg-Builds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload.sh
executable file
·63 lines (48 loc) · 1.53 KB
/
download.sh
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
#!/bin/bash
set -xe
cd "$(dirname "$0")"
source util/vars.sh dl only
if docker info -f "{{println .SecurityOptions}}" | grep rootless >/dev/null 2>&1; then
UIDARGS=()
else
UIDARGS=( -u "$(id -u):$(id -g)" )
fi
[[ -t 1 ]] && TTY_ARG="-t" || TTY_ARG=""
DL_SCRIPT_DIR="$(mktemp -d)"
trap "rm -rf -- '$DL_SCRIPT_DIR'" EXIT
mkdir -p "${PWD}"/.cache/downloads
for STAGE in scripts.d/*.sh scripts.d/*/*.sh; do
STAGENAME="$(basename "$STAGE" | sed 's/.sh$//')"
cat <<-EOF >"${DL_SCRIPT_DIR}/${STAGENAME}.sh"
set -xe -o pipefail
shopt -s dotglob
source /dl_functions.sh
source "/$STAGE"
STG="\$(ffbuild_dockerdl)"
if [[ -z "\$STG" ]]; then
exit 0
fi
DLHASH="\$(sha256sum <<<"\$STG" | cut -d" " -f1)"
DLNAME="$STAGENAME"
if [[ "$1" == "hashonly" ]]; then
echo "\$DLHASH"
exit 0
fi
TGT="/dldir/\${DLNAME}_\${DLHASH}.tar.xz"
if [[ -f "\$TGT" ]]; then
rm -f "/dldir/\${DLNAME}.tar.xz"
ln -s "\${DLNAME}_\${DLHASH}.tar.xz" "/dldir/\${DLNAME}.tar.xz"
exit 0
fi
WORKDIR="\$(mktemp -d)"
trap "rm -rf -- '\$WORKDIR'" EXIT
cd "\$WORKDIR"
eval "\$STG"
tar cpJf "\$TGT.tmp" .
mv "\$TGT.tmp" "\$TGT"
rm -f "/dldir/\${DLNAME}.tar.xz"
ln -s "\${DLNAME}_\${DLHASH}.tar.xz" "/dldir/\${DLNAME}.tar.xz"
EOF
done
docker run -i $TTY_ARG --rm "${UIDARGS[@]}" -v "${DL_SCRIPT_DIR}":/stages -v "${PWD}/.cache/downloads":/dldir -v "${PWD}/scripts.d":/scripts.d -v "${PWD}/util/dl_functions.sh":/dl_functions.sh "${REGISTRY}/${REPO}/base:latest" \
bash -c 'set -xe && for STAGE in /stages/*.sh; do bash $STAGE; done'