Initial Commit
- initial default booting image
This commit is contained in:
65
support/download/bzr
Executable file
65
support/download/bzr
Executable file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# We want to catch any unexpected failure, and exit immediately
|
||||
set -e
|
||||
|
||||
# Download helper for bzr, to be called from the download wrapper script
|
||||
#
|
||||
# Options:
|
||||
# -q Be quiet
|
||||
# -o FILE Generate archive in FILE.
|
||||
# -u URI Clone from repository at URI.
|
||||
# -c CSET Use changeset (or revision) CSET.
|
||||
# -n NAME Use basename NAME.
|
||||
#
|
||||
# Environment:
|
||||
# BZR : the bzr command to call
|
||||
|
||||
|
||||
quiet=
|
||||
while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
|
||||
case "${OPT}" in
|
||||
q) quiet=-q;;
|
||||
o) output="${OPTARG}";;
|
||||
u) uri="${OPTARG}";;
|
||||
c) cset="${OPTARG}";;
|
||||
n) basename="${OPTARG}";;
|
||||
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
|
||||
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1)) # Get rid of our options
|
||||
|
||||
# Caller needs to single-quote its arguments to prevent them from
|
||||
# being expanded a second time (in case there are spaces in them)
|
||||
_bzr() {
|
||||
if [ -z "${quiet}" ]; then
|
||||
printf '%s ' ${BZR} "${@}"; printf '\n'
|
||||
fi
|
||||
_plain_bzr "$@"
|
||||
}
|
||||
# Note: please keep command below aligned with what is printed above
|
||||
_plain_bzr() {
|
||||
eval ${BZR} "${@}"
|
||||
}
|
||||
|
||||
# --per-file-timestamps comes with bzr-2.2 (released August 2010),
|
||||
# so only pass it if bzr is recent enough. We compute versions as:
|
||||
# major*1000 + minor
|
||||
bzr_min_version=2002
|
||||
bzr_version=$(($(bzr --version |
|
||||
sed -r -n 's/^Bazaar \(bzr\) ([[:digit:]]+)\.([[:digit:]]+)\..*$/\1*1000+\2/p')
|
||||
))
|
||||
|
||||
# If the version is recent enough, we can generate reproducible
|
||||
# archives; otherwise, we just hope for the best (as it would
|
||||
# be downloaded from the BR mirror if what we generate here does
|
||||
# not match the hash we have for it).
|
||||
if [ ${bzr_version} -ge ${bzr_min_version} ]; then
|
||||
timestamp_opt="--per-file-timestamps"
|
||||
fi
|
||||
|
||||
_bzr export ${quiet} --root="'${basename}/'" --format=tgz \
|
||||
${timestamp_opt} - "${@}" "'${uri}'" -r "'${cset}'" \
|
||||
>"${output}"
|
||||
51
support/download/cargo-post-process
Executable file
51
support/download/cargo-post-process
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
# shellcheck source=helpers source-path=SCRIPTDIR
|
||||
. "${0%/*}/helpers"
|
||||
|
||||
if [ "${BR_CARGO_MANIFEST_PATH}" ]; then
|
||||
printf 'Setting BR_CARGO_MANIFEST_PATH is no longer supported; use post-process options.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
manifest=Cargo.toml
|
||||
while getopts "n:o:m:" OPT; do
|
||||
case "${OPT}" in
|
||||
o) output="${OPTARG}";;
|
||||
n) base_name="${OPTARG}";;
|
||||
m) manifest="${OPTARG}";;
|
||||
:) error "option '%s' expects a mandatory argument\n" "${OPTARG}";;
|
||||
\?) error "unknown option '%s'\n" "${OPTARG}";;
|
||||
esac
|
||||
done
|
||||
|
||||
# Already vendored tarball, nothing to do
|
||||
if tar tf "${output}" | grep -q "^[^/]*/VENDOR" ; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
post_process_unpack "${base_name}" "${output}"
|
||||
|
||||
# Do the Cargo vendoring
|
||||
pushd "${base_name}" > /dev/null
|
||||
|
||||
# Create the local .cargo/config.toml with vendor info
|
||||
mkdir -p .cargo/
|
||||
mkdir -p "${CARGO_HOME}"
|
||||
flock "${CARGO_HOME}"/.br-lock \
|
||||
cargo vendor \
|
||||
--manifest-path "${manifest}" \
|
||||
--locked VENDOR \
|
||||
> .cargo/config.toml
|
||||
|
||||
# "cargo vendor' outputs on stderr a message directing to add some data
|
||||
# to the project's .cargo/config.toml, data that it outputs on stdout.
|
||||
# Since we redirect stdout to .cargo/config.toml, the message on stderr
|
||||
# gets confusing, so instruct the user that it's been handled.
|
||||
printf '(note: .cargo/config.toml automatically updated by Buildroot)\n\n'
|
||||
|
||||
popd > /dev/null
|
||||
|
||||
post_process_repack "$(pwd)" "${base_name}" "${output}"
|
||||
116
support/download/check-hash
Executable file
116
support/download/check-hash
Executable file
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# Helper to check a file matches its known hash
|
||||
# Call it with:
|
||||
# $1: the full path to the temporary file that was downloaded, and
|
||||
# that is to be checked
|
||||
# $2: the final basename of the file, to which it will be ultimately
|
||||
# saved as, to be able to match it to the corresponding hashes
|
||||
# in the .hash file
|
||||
# $*: the paths of the files containing all the expected hashes
|
||||
#
|
||||
# Exit codes:
|
||||
# 0: the hash file exists and the file to check matches all its hashes,
|
||||
# or the hash file does not exist
|
||||
# 1: unknown command-line option
|
||||
# 2: the hash file exists and the file to check does not match at least
|
||||
# one of its hashes
|
||||
# 3: the hash file exists and there was no hash to check the file against
|
||||
# 4: the hash file exists and at least one hash type is unknown
|
||||
|
||||
while getopts :q OPT; do
|
||||
case "${OPT}" in
|
||||
q) exec >/dev/null;;
|
||||
\?) exit 1;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
file="${1}"
|
||||
base="${2}"
|
||||
shift 2
|
||||
declare -a h_files=( "${@}" )
|
||||
|
||||
# Check one hash for a file
|
||||
# $1: algo hash
|
||||
# $2: known hash
|
||||
# $3: file (full path)
|
||||
# $4: hash file (full path)
|
||||
check_one_hash() {
|
||||
_h="${1}"
|
||||
_known="${2}"
|
||||
_file="${3}"
|
||||
_h_file="${4}"
|
||||
|
||||
# Note: md5 is supported, but undocumented on purpose.
|
||||
# Note: sha3 is not supported, since there is currently no implementation
|
||||
# (the NIST has yet to publish the parameters).
|
||||
case "${_h}" in
|
||||
md5|sha1) ;;
|
||||
sha224|sha256|sha384|sha512) ;;
|
||||
*) # Unknown hash, exit with error
|
||||
printf "ERROR: unknown hash '%s' for '%s'\n" \
|
||||
"${_h}" "${base}" >&2
|
||||
exit 4
|
||||
;;
|
||||
esac
|
||||
|
||||
# Do the hashes match?
|
||||
_hash="$( "${_h}sum" "${_file}" |cut -d ' ' -f 1 )"
|
||||
if [ "${_hash}" = "${_known}" ]; then
|
||||
printf "%s: OK (%s: %s)\n" "${base}" "${_h}" "${_hash}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
printf "ERROR: while checking hashes from %s\n" "${_h_file}" >&2
|
||||
printf "ERROR: %s has wrong %s hash:\n" "${base}" "${_h}" >&2
|
||||
printf "ERROR: expected: %s\n" "${_known}" >&2
|
||||
printf "ERROR: got : %s\n" "${_hash}" >&2
|
||||
printf "ERROR: Incomplete download, or man-in-the-middle (MITM) attack\n" >&2
|
||||
|
||||
exit 2
|
||||
}
|
||||
|
||||
# Do we know one or more hashes for that file?
|
||||
nb_h_files=0
|
||||
nb_checks=0
|
||||
for h_file in "${h_files[@]}"; do
|
||||
[ -f "${h_file}" ] || continue
|
||||
: $((nb_h_files++))
|
||||
# mapfile reads all lines, even the last one if it is missing a \n
|
||||
mapfile -t hash_lines <"${h_file}"
|
||||
for hash_line in "${hash_lines[@]}"; do
|
||||
read -r t h f <<<"${hash_line}"
|
||||
case "${t}" in
|
||||
''|'#'*)
|
||||
# Skip comments and empty lines
|
||||
continue
|
||||
;;
|
||||
*)
|
||||
if [ "${f}" = "${base}" ]; then
|
||||
check_one_hash "${t}" "${h}" "${file}" "${h_file}"
|
||||
: $((nb_checks++))
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
|
||||
# shellcheck disable=SC2086 # nb_h_files is a non-empty int
|
||||
if [ ${nb_h_files} -eq 0 ]; then
|
||||
printf "WARNING: no hash file for %s\n" "${base}" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086 # nb_checks is a non-empty int
|
||||
if [ ${nb_checks} -eq 0 ]; then
|
||||
case " ${BR_NO_CHECK_HASH_FOR} " in
|
||||
*" ${base} "*)
|
||||
# File explicitly has no hash
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
printf "ERROR: No hash found for %s\n" "${base}" >&2
|
||||
exit 3
|
||||
fi
|
||||
46
support/download/curl
Executable file
46
support/download/curl
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# We want to catch any unexpected failure, and exit immediately
|
||||
set -e
|
||||
|
||||
# Download helper for curl, to be called from the download wrapper script
|
||||
#
|
||||
# Options:
|
||||
# -q Be quiet.
|
||||
# -o FILE Save into file FILE.
|
||||
# -f FILENAME The filename of the tarball to get at URL
|
||||
# -u URL Download file at URL.
|
||||
#
|
||||
# Environment:
|
||||
# CURL : the curl command to call
|
||||
|
||||
quiet=
|
||||
while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
|
||||
case "${OPT}" in
|
||||
q) quiet=-s;;
|
||||
o) output="${OPTARG}";;
|
||||
f) filename="${OPTARG}";;
|
||||
u) url="${OPTARG}";;
|
||||
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
|
||||
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1)) # Get rid of our options
|
||||
|
||||
# Caller needs to single-quote its arguments to prevent them from
|
||||
# being expanded a second time (in case there are spaces in them)
|
||||
_curl() {
|
||||
if [ -z "${quiet}" ]; then
|
||||
printf '%s ' "${CURL}" "${@}"; printf '\n'
|
||||
fi
|
||||
_plain_curl "$@"
|
||||
}
|
||||
# Note: please keep command below aligned with what is printed above
|
||||
_plain_curl() {
|
||||
# shellcheck disable=SC2086 # We want splitting
|
||||
# shellcheck disable=SC2294
|
||||
eval ${CURL} "${@}"
|
||||
}
|
||||
|
||||
_curl ${quiet} "${@}" --output "'${output}'" "'${url}/${filename}'"
|
||||
72
support/download/cvs
Executable file
72
support/download/cvs
Executable file
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# We want to catch any unexpected failure, and exit immediately
|
||||
set -e
|
||||
|
||||
# Download helper for cvs, to be called from the download wrapper script
|
||||
#
|
||||
# Options:
|
||||
# -q Be quiet
|
||||
# -o FILE Generate archive in FILE.
|
||||
# -u URI Checkout from repository at URI.
|
||||
# -c REV Use revision REV.
|
||||
# -N RAWNAME Use rawname (aka module name) RAWNAME.
|
||||
# -n NAME Use basename NAME.
|
||||
#
|
||||
# Environment:
|
||||
# CVS : the cvs command to call
|
||||
|
||||
quiet=
|
||||
while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
|
||||
case "${OPT}" in
|
||||
q) quiet=-Q;;
|
||||
o) output="${OPTARG}";;
|
||||
u) uri="${OPTARG#*://}";;
|
||||
c) rev="${OPTARG}";;
|
||||
N) rawname="${OPTARG}";;
|
||||
n) basename="${OPTARG}";;
|
||||
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
|
||||
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1)) # Get rid of our options
|
||||
|
||||
# Caller needs to single-quote its arguments to prevent them from
|
||||
# being expanded a second time (in case there are spaces in them).
|
||||
# If the CVS server is deadlocked, the client will never return (cfr.
|
||||
# http://autobuild.buildroot.net/results/23d/23d1034b33d0354de15de2ec4a8ccd0603e8db78/build-end.log
|
||||
# ). Since nobody sane will put large code bases in CVS, a timeout of
|
||||
# 10 minutes should do the trick.
|
||||
_cvs() {
|
||||
if [ -z "${quiet}" ]; then
|
||||
printf '%s ' timeout 10m "${CVS}" "${@}"; printf '\n'
|
||||
fi
|
||||
_plain_cvs "$@"
|
||||
}
|
||||
# Note: please keep command below aligned with what is printed above
|
||||
_plain_cvs() {
|
||||
# shellcheck disable=SC2086 # We really want word splitting in CVS
|
||||
# shellcheck disable=SC2294
|
||||
eval timeout 10m ${CVS} "${@}"
|
||||
}
|
||||
|
||||
if [[ ${rev} =~ ^[0-9] ]]; then
|
||||
# Date, because a tag or a branch cannot begin with a number
|
||||
select="-D"
|
||||
else
|
||||
# Tag or branch
|
||||
select="-r"
|
||||
fi
|
||||
|
||||
# The absence of an initial : on ${uri} means access method undefined
|
||||
if [[ ! "${uri}" =~ ^: ]]; then
|
||||
# defaults to anonymous pserver
|
||||
uri=":pserver:anonymous@${uri}"
|
||||
fi
|
||||
|
||||
export TZ=UTC
|
||||
_cvs ${quiet} -z3 -d"'${uri}'" \
|
||||
co "${@}" -d "'${basename}'" ${select} "'${rev}'" -P "'${rawname}'"
|
||||
|
||||
${TAR} czf "${output}" "${basename}"
|
||||
242
support/download/dl-wrapper
Executable file
242
support/download/dl-wrapper
Executable file
@@ -0,0 +1,242 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script is a wrapper to the other download backends.
|
||||
# Its role is to ensure atomicity when saving downloaded files
|
||||
# back to BR2_DL_DIR, and not clutter BR2_DL_DIR with partial,
|
||||
# failed downloads.
|
||||
|
||||
# To avoid cluttering BR2_DL_DIR, we download to a trashable
|
||||
# location, namely in $(BUILD_DIR).
|
||||
# Then, we move the downloaded file to a temporary file in the
|
||||
# same directory as the final output file.
|
||||
# This allows us to finally atomically rename it to its final
|
||||
# name.
|
||||
# If anything goes wrong, we just remove all the temporaries
|
||||
# created so far.
|
||||
|
||||
# We want to catch any unexpected failure, and exit immediately.
|
||||
set -e
|
||||
|
||||
# shellcheck source=helpers source-path=SCRIPTDIR
|
||||
. "${0%/*}/helpers"
|
||||
|
||||
export BR_BACKEND_DL_GETOPTS=":hc:d:o:n:N:H:lru:qf:e"
|
||||
|
||||
main() {
|
||||
local OPT OPTARG
|
||||
local backend output large_file recurse quiet rc
|
||||
local -a uris hfiles backend_opts post_process_opts
|
||||
|
||||
# Parse our options; anything after '--' is for the backend
|
||||
while getopts ":c:d:D:o:n:N:H:lrf:u:qp:P:" OPT; do
|
||||
case "${OPT}" in
|
||||
c) cset="${OPTARG}";;
|
||||
d) dl_dir="${OPTARG}";;
|
||||
D) old_dl_dir="${OPTARG}";;
|
||||
o) output="${OPTARG}";;
|
||||
n) raw_base_name="${OPTARG}";;
|
||||
N) base_name="${OPTARG}";;
|
||||
H) hfiles+=( "${OPTARG}" );;
|
||||
l) large_file="-l";;
|
||||
r) recurse="-r";;
|
||||
f) filename="${OPTARG}";;
|
||||
u) uris+=( "${OPTARG}" );;
|
||||
p) post_process="${OPTARG}";;
|
||||
P) post_process_opts+=( "${OPTARG}" );;
|
||||
q) quiet="-q";;
|
||||
:) error "option '%s' expects a mandatory argument\n" "${OPTARG}";;
|
||||
\?) error "unknown option '%s'\n" "${OPTARG}";;
|
||||
esac
|
||||
done
|
||||
|
||||
# Forget our options, and keep only those for the backend
|
||||
shift $((OPTIND-1))
|
||||
|
||||
if [ -z "${output}" ]; then
|
||||
error "no output specified, use -o\n"
|
||||
fi
|
||||
|
||||
# Legacy handling: check if the file already exists in the global
|
||||
# download directory. If it does, hard-link it. If it turns out it
|
||||
# was an incorrect download, we'd still check it below anyway.
|
||||
# If we can neither link nor copy, fallback to doing a download.
|
||||
# NOTE! This is not atomic, is subject to TOCTTOU, but the whole
|
||||
# dl-wrapper runs under an flock, so we're safe.
|
||||
# shellcheck disable=SC2166 # -a works in this case
|
||||
if [ ! -e "${output}" -a -e "${old_dl_dir}/${filename}" ]; then
|
||||
ln "${old_dl_dir}/${filename}" "${output}" || \
|
||||
cp "${old_dl_dir}/${filename}" "${output}" || \
|
||||
true
|
||||
fi
|
||||
|
||||
# If the output file already exists and:
|
||||
# - there's no .hash file: do not download it again and exit promptly
|
||||
# - matches all its hashes: do not download it again and exit promptly
|
||||
# - fails at least one of its hashes: force a re-download
|
||||
# - there's no hash (but a .hash file): consider it a hard error
|
||||
if [ -e "${output}" ]; then
|
||||
if support/download/check-hash ${quiet} "${output}" "${output##*/}" "${hfiles[@]}"; then
|
||||
exit 0
|
||||
elif [ ${?} -ne 2 ]; then
|
||||
# Do not remove the file, otherwise it might get re-downloaded
|
||||
# from a later location (i.e. primary -> upstream -> mirror).
|
||||
# Do not print a message, check-hash already did.
|
||||
exit 1
|
||||
fi
|
||||
rm -f "${output}"
|
||||
warn "Re-downloading '%s'...\n" "${output##*/}"
|
||||
fi
|
||||
|
||||
# Look through all the uris that we were given to download the package
|
||||
# source
|
||||
download_and_check=0
|
||||
rc=1
|
||||
for uri in "${uris[@]}"; do
|
||||
backend_urlencode="${uri%%+*}"
|
||||
backend="${backend_urlencode%|*}"
|
||||
case "${backend}" in
|
||||
git|svn|cvs|bzr|file|scp|hg|sftp) ;;
|
||||
ftp|ftps|smb) backend="curl" ;;
|
||||
*) backend="wget" ;;
|
||||
esac
|
||||
uri=${uri#*+}
|
||||
|
||||
urlencode=${backend_urlencode#*|}
|
||||
# urlencode must be "urlencode"
|
||||
[ "${urlencode}" != "urlencode" ] && urlencode=""
|
||||
|
||||
# tmpd is a temporary directory in which backends may store
|
||||
# intermediate by-products of the download.
|
||||
# tmpf is the file in which the backends should put the downloaded
|
||||
# content.
|
||||
# tmpd is located in $(BUILD_DIR), so as not to clutter the (precious)
|
||||
# $(BR2_DL_DIR)
|
||||
# We let the backends create tmpf, so they are able to set whatever
|
||||
# permission bits they want (although we're only really interested in
|
||||
# the executable bit.)
|
||||
tmpd="$(mktemp -d "${BUILD_DIR}/.${output##*/}.XXXXXX")"
|
||||
tmpf="${tmpd}/output"
|
||||
|
||||
# shellcheck disable=SC2206 # all three are dash-options
|
||||
backend_opts=( ${quiet} ${large_file} ${recurse} )
|
||||
if [ "${urlencode}" ]; then
|
||||
backend_opts+=( -e )
|
||||
fi
|
||||
|
||||
# Helpers expect to run in a directory that is *really* trashable, so
|
||||
# they are free to create whatever files and/or sub-dirs they might need.
|
||||
# Doing the 'cd' here rather than in all backends is easier.
|
||||
cd "${tmpd}"
|
||||
|
||||
# If the backend fails, we can just remove the content of the temporary
|
||||
# directory to remove all the cruft it may have left behind, and try
|
||||
# the next URI until it succeeds. Once out of URI to try, we need to
|
||||
# cleanup and exit.
|
||||
if ! "${OLDPWD}/support/download/${backend}" \
|
||||
-c "${cset}" \
|
||||
-d "${dl_dir}" \
|
||||
-n "${raw_base_name}" \
|
||||
-N "${base_name}" \
|
||||
-f "${filename}" \
|
||||
-u "${uri}" \
|
||||
-o "${tmpf}" \
|
||||
"${backend_opts[@]}" \
|
||||
-- \
|
||||
"${@}"
|
||||
then
|
||||
# cd back to keep path coherence
|
||||
cd "${OLDPWD}"
|
||||
rm -rf "${tmpd}"
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ -n "${post_process}" ] ; then
|
||||
if ! "${OLDPWD}/support/download/${post_process}-post-process" \
|
||||
-o "${tmpf}" \
|
||||
-n "${raw_base_name}" \
|
||||
"${post_process_opts[@]}"
|
||||
then
|
||||
# cd back to keep path coherence
|
||||
cd "${OLDPWD}"
|
||||
rm -rf "${tmpd}"
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
# cd back to free the temp-dir, so we can remove it later
|
||||
cd "${OLDPWD}"
|
||||
|
||||
# Check if the downloaded file is sane, and matches the stored hashes
|
||||
# for that file
|
||||
if support/download/check-hash ${quiet} "${tmpf}" "${output##*/}" "${hfiles[@]}"; then
|
||||
rc=0
|
||||
else
|
||||
if [ ${?} -ne 3 ]; then
|
||||
rm -rf "${tmpd}"
|
||||
continue
|
||||
fi
|
||||
|
||||
# the hash file exists and there was no hash to check the file
|
||||
# against
|
||||
rc=1
|
||||
fi
|
||||
download_and_check=1
|
||||
break
|
||||
done
|
||||
|
||||
# We tried every URI possible, none seems to work or to check against the
|
||||
# available hash. *ABORT MISSION*
|
||||
if [ "${download_and_check}" -eq 0 ]; then
|
||||
rm -rf "${tmpd}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# tmp_output is in the same directory as the final output, so we can
|
||||
# later move it atomically.
|
||||
tmp_output="$(mktemp "${output}.XXXXXX")"
|
||||
|
||||
# 'mktemp' creates files with 'go=-rwx', so the files are not accessible
|
||||
# to users other than the one doing the download (and root, of course).
|
||||
# This can be problematic when a shared BR2_DL_DIR is used by different
|
||||
# users (e.g. on a build server), where all users may write to the shared
|
||||
# location, since other users would not be allowed to read the files
|
||||
# another user downloaded.
|
||||
# So, we restore the 'go' access rights to a more sensible value, while
|
||||
# still abiding by the current user's umask. We must do that before the
|
||||
# final 'mv', so just do it now.
|
||||
# Some backends (cp and scp) may create executable files, so we need to
|
||||
# carry the executable bit if needed.
|
||||
[ -x "${tmpf}" ] && new_mode=755 || new_mode=644
|
||||
new_mode="$(printf "%04o" $((0${new_mode} & ~0$(umask))))"
|
||||
chmod "${new_mode}" "${tmp_output}"
|
||||
|
||||
# We must *not* unlink tmp_output, otherwise there is a small window
|
||||
# during which another download process may create the same tmp_output
|
||||
# name (very, very unlikely; but not impossible.)
|
||||
# Using 'cp' is not reliable, since 'cp' may unlink the destination file
|
||||
# if it is unable to open it with O_WRONLY|O_TRUNC; see:
|
||||
# http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cp.html
|
||||
# Since the destination filesystem can be anything, it might not support
|
||||
# O_TRUNC, so 'cp' would unlink it first.
|
||||
# Use 'cat' and append-redirection '>>' to save to the final location,
|
||||
# since that is the only way we can be 100% sure of the behaviour.
|
||||
if ! cat "${tmpf}" >>"${tmp_output}"; then
|
||||
rm -rf "${tmpd}" "${tmp_output}"
|
||||
exit 1
|
||||
fi
|
||||
rm -rf "${tmpd}"
|
||||
|
||||
# tmp_output and output are on the same filesystem, so POSIX guarantees
|
||||
# that 'mv' is atomic, because it then uses rename() that POSIX mandates
|
||||
# to be atomic, see:
|
||||
# http://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html
|
||||
if ! mv -f "${tmp_output}" "${output}"; then
|
||||
rm -f "${tmp_output}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
return ${rc}
|
||||
}
|
||||
|
||||
my_name="${0##*/}"
|
||||
main "${@}"
|
||||
49
support/download/file
Executable file
49
support/download/file
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# We want to catch any unexpected failure, and exit immediately
|
||||
set -e
|
||||
|
||||
# Download helper for cp, to be called from the download wrapper script
|
||||
#
|
||||
# Options:
|
||||
# -q Be quiet.
|
||||
# -o FILE Copy to file FILE.
|
||||
# -f FILE Copy from basename file FILE.
|
||||
# -u DIR Copy from FILE in DIR.
|
||||
#
|
||||
# Environment:
|
||||
# LOCALFILES: the cp command to call
|
||||
|
||||
# 'cp' usually does not print anything on its stdout, whereas the
|
||||
# other download backends, even if not verbose, at least print some
|
||||
# progress information.
|
||||
# Make 'cp' verbose by default, so it behaves a bit like the others.
|
||||
verbose=-v
|
||||
|
||||
while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
|
||||
case "${OPT}" in
|
||||
q) verbose=;;
|
||||
o) output="${OPTARG}";;
|
||||
f) file="${OPTARG}";;
|
||||
u) dir="${OPTARG}";;
|
||||
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
|
||||
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1)) # Get rid of our options
|
||||
|
||||
# Caller needs to single-quote its arguments to prevent them from
|
||||
# being expanded a second time (in case there are spaces in them)
|
||||
_localfiles() {
|
||||
if [ -n "${verbose}" ]; then
|
||||
printf '%s ' ${LOCALFILES} "${@}"; printf '\n'
|
||||
fi
|
||||
_plain_localfiles "$@"
|
||||
}
|
||||
# Note: please keep command below aligned with what is printed above
|
||||
_plain_localfiles() {
|
||||
eval ${LOCALFILES} "${@}"
|
||||
}
|
||||
|
||||
_localfiles ${verbose} "'${dir##file://}/${file}'" "'${output}'"
|
||||
299
support/download/git
Executable file
299
support/download/git
Executable file
@@ -0,0 +1,299 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# NOTE: if the output of this backend has to change (e.g. we change what gets
|
||||
# included in the archive (e.g. LFS), or we change the format of the archive
|
||||
# (e.g. tar options, compression ratio or method)), we MUST update the format
|
||||
# version in the variable BR_FMT_VERSION_git, in package/pkg-download.mk.
|
||||
|
||||
# We want to catch any unexpected failure
|
||||
set -e
|
||||
|
||||
# Download helper for git, to be called from the download wrapper script
|
||||
#
|
||||
# Options:
|
||||
# -q Be quiet.
|
||||
# -r Clone and archive sub-modules.
|
||||
# -o FILE Generate archive in FILE.
|
||||
# -u URI Clone from repository at URI.
|
||||
# -c CSET Use changeset CSET.
|
||||
# -n NAME Use basename NAME.
|
||||
#
|
||||
# Environment:
|
||||
# GIT : the git command to call
|
||||
|
||||
# shellcheck disable=SC1090 # Only provides mk_tar_gz()
|
||||
# shellcheck disable=SC1091
|
||||
. "${0%/*}/helpers"
|
||||
|
||||
# Save our path and options in case we need to call ourselves again
|
||||
myname="${0}"
|
||||
declare -a OPTS=("${@}")
|
||||
|
||||
# This function is called when an error occurs. Its job is to attempt a
|
||||
# clone from scratch (only once!) in case the git tree is borked, or in
|
||||
# case an unexpected and unsupported situation arises with submodules
|
||||
# or uncommitted stuff (e.g. if the user manually mucked around in the
|
||||
# git cache).
|
||||
_on_error() {
|
||||
local ret=${?}
|
||||
|
||||
printf "Detected a corrupted git cache.\n" >&2
|
||||
if ${BR_GIT_BACKEND_FIRST_FAULT:-false}; then
|
||||
printf "This is the second time in a row; bailing out\n" >&2
|
||||
exit ${ret}
|
||||
fi
|
||||
export BR_GIT_BACKEND_FIRST_FAULT=true
|
||||
|
||||
printf "Removing it and starting afresh.\n" >&2
|
||||
|
||||
popd >/dev/null
|
||||
rm -rf "${git_cache}"
|
||||
|
||||
exec "${myname}" "${OPTS[@]}" || exit ${ret}
|
||||
}
|
||||
|
||||
quiet=
|
||||
large_file=0
|
||||
recurse=0
|
||||
while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
|
||||
case "${OPT}" in
|
||||
q) quiet=-q; exec >/dev/null;;
|
||||
l) large_file=1;;
|
||||
r) recurse=1;;
|
||||
o) output="${OPTARG}";;
|
||||
u) uri="${OPTARG}";;
|
||||
c) cset="${OPTARG}";;
|
||||
d) dl_dir="${OPTARG}";;
|
||||
n) basename="${OPTARG}";;
|
||||
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
|
||||
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1)) # Get rid of our options
|
||||
|
||||
# Create and cd into the directory that will contain the local git cache
|
||||
git_cache="${dl_dir}/git"
|
||||
mkdir -p "${git_cache}"
|
||||
pushd "${git_cache}" >/dev/null
|
||||
|
||||
# Any error now should try to recover
|
||||
trap _on_error ERR
|
||||
set -E
|
||||
|
||||
# Caller needs to single-quote its arguments to prevent them from
|
||||
# being expanded a second time (in case there are spaces in them)
|
||||
_git() {
|
||||
if [ -z "${quiet}" ]; then
|
||||
printf '%s ' GIT_DIR="${git_cache}/.git" "${GIT}" "${@}"; printf '\n'
|
||||
fi
|
||||
_plain_git "$@"
|
||||
}
|
||||
# Note: please keep command below aligned with what is printed above
|
||||
_plain_git() {
|
||||
# shellcheck disable=SC2086 # We want word-splitting for GIT
|
||||
# shellcheck disable=SC2294
|
||||
eval GIT_DIR="${git_cache}/.git" ${GIT} "${@}"
|
||||
}
|
||||
|
||||
# Create a warning file, that the user should not use the git cache.
|
||||
# It's ours. Our precious.
|
||||
cat <<-_EOF_ >"${dl_dir}/git.readme"
|
||||
IMPORTANT NOTE!
|
||||
|
||||
The git tree located in this directory is for the exclusive use
|
||||
by Buildroot, which uses it as a local cache to reduce bandwidth
|
||||
usage.
|
||||
|
||||
Buildroot *will* trash any changes in that tree whenever it needs
|
||||
to use it. Buildroot may even remove it in case it detects the
|
||||
repository may have been damaged or corrupted.
|
||||
|
||||
Do *not* work in that directory; your changes will eventually get
|
||||
lost. Do *not* even use it as a remote, or as the source for new
|
||||
worktrees; your commits will eventually get lost.
|
||||
_EOF_
|
||||
|
||||
# Initialise a repository in the git cache. If the repository already
|
||||
# existed, this is a noop, unless the repository was broken, in which
|
||||
# case this magically restores it to working conditions. In the latter
|
||||
# case, we might be missing blobs, but that's not a problem: we'll
|
||||
# fetch what we need later anyway.
|
||||
#
|
||||
# We can still go through the wrapper, because 'init' does not use the
|
||||
# path pointed to by GIT_DIR, but really uses the directory passed as
|
||||
# argument.
|
||||
_git init .
|
||||
|
||||
# Ensure the repo has an origin (in case a previous run was killed).
|
||||
if ! _plain_git remote |grep -q -E '^origin$'; then
|
||||
_git remote add origin "'${uri}'"
|
||||
fi
|
||||
|
||||
_git remote set-url origin "'${uri}'"
|
||||
|
||||
printf "Fetching all references\n"
|
||||
_git fetch "${@}" origin
|
||||
_git fetch "${@}" origin -t -f
|
||||
|
||||
# Try to get the special refs exposed by some forges (pull-requests for
|
||||
# github, changes for gerrit...). There is no easy way to know whether
|
||||
# the cset the user passed us is such a special ref or a tag or a sha1
|
||||
# or whatever else. We'll eventually fail at checking out that cset,
|
||||
# below, if there is an issue anyway. Since most of the cset we're gonna
|
||||
# have to clone are not such special refs, consign the output to oblivion
|
||||
# so as not to alarm unsuspecting users, but still trace it as a warning.
|
||||
if ! _git fetch "${@}" origin "'${cset}:${cset}'" >/dev/null 2>&1; then
|
||||
printf "Could not fetch special ref '%s'; assuming it is not special.\n" "${cset}"
|
||||
fi
|
||||
|
||||
# Check that the changeset does exist. If it does not, re-cloning from
|
||||
# scratch won't help, so we don't want to trash the repository for a
|
||||
# missing commit. We just exit without going through the ERR trap.
|
||||
if ! _git rev-parse --quiet --verify "'${cset}^{commit}'" >/dev/null 2>&1; then
|
||||
printf "Commit '%s' does not exist in this repository.\n" "${cset}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# The new cset we want to checkout might have different submodules, or
|
||||
# have sub-dirs converted to/from a submodule. So we would need to
|
||||
# deregister _current_ submodules before we checkout.
|
||||
#
|
||||
# Using "git submodule deinit --all" would remove all the files for
|
||||
# all submodules, including the corresponding .git files or directories.
|
||||
# However, it was only introduced with git-1.8.3, which is too recent
|
||||
# for some enterprise-grade distros.
|
||||
#
|
||||
# So, we fall-back to just removing all submodules directories. We do
|
||||
# not need to be recursive, as removing a submodule will de-facto remove
|
||||
# its own submodules.
|
||||
#
|
||||
# For recent git versions, the repository for submodules is stored
|
||||
# inside the repository of the super repository, so the following will
|
||||
# only remove the working copies of submodules, effectively caching the
|
||||
# submodules.
|
||||
#
|
||||
# For older versions however, the repository is stored in the .git/ of
|
||||
# the submodule directory, so the following will effectively remove the
|
||||
# the working copy as well as the repository, which means submodules
|
||||
# will not be cached for older versions.
|
||||
#
|
||||
# shellcheck disable=SC2016 # Will be expanded by git-foreach
|
||||
cmd='printf "Deregistering submodule \"%s\"\n" "${path}" && cd .. && rm -rf "${path##*/}"'
|
||||
_git submodule --quiet foreach "'${cmd}'"
|
||||
|
||||
# Checkout the required changeset, so that we can update the required
|
||||
# submodules.
|
||||
_git checkout -f -q "'${cset}'"
|
||||
|
||||
# Get rid of now-untracked directories (in case a git operation was
|
||||
# interrupted in a previous run, or to get rid of empty directories
|
||||
# that were parents of submodules removed above).
|
||||
_git clean -ffdx
|
||||
|
||||
# Get date of commit to generate a reproducible archive.
|
||||
# %ci is ISO 8601, so it's fully qualified, with TZ and all.
|
||||
date="$( _plain_git log -1 --pretty=format:%ci )"
|
||||
|
||||
# There might be submodules, so fetch them.
|
||||
if [ ${recurse} -eq 1 ]; then
|
||||
_git submodule update --init --recursive
|
||||
|
||||
# Older versions of git will store the absolute path of the git tree
|
||||
# in the .git of submodules, while newer versions just use relative
|
||||
# paths. Detect and fix the older variants to use relative paths, so
|
||||
# that the archives are reproducible across a wider range of git
|
||||
# versions. However, we can't do that if git is too old and uses
|
||||
# full repositories for submodules.
|
||||
# shellcheck disable=SC2016 # Will be expanded by git-foreach
|
||||
cmd='printf "%s\n" "${path}/"'
|
||||
for module_dir in $( _plain_git submodule --quiet foreach "'${cmd}'" ); do
|
||||
[ -f "${module_dir}/.git" ] || continue
|
||||
relative_dir="$( sed -r -e 's,/+,/,g; s,[^/]+/,../,g' <<<"${module_dir}" )"
|
||||
sed -r -i -e "s:^gitdir\: $(pwd)/:gitdir\: ${relative_dir}:" "${module_dir}/.git"
|
||||
done
|
||||
fi
|
||||
|
||||
# If there are large files then fetch them.
|
||||
if [ ${large_file} -eq 1 ]; then
|
||||
_git lfs install --local
|
||||
_git lfs fetch
|
||||
_git lfs checkout
|
||||
# If there are also submodules, recurse into them,
|
||||
# shellcheck disable=SC2086 # We want word-splitting for GIT
|
||||
if [ ${recurse} -eq 1 ]; then
|
||||
_git submodule foreach --recursive ${GIT} lfs install --local
|
||||
_git submodule foreach --recursive ${GIT} lfs fetch
|
||||
_git submodule foreach --recursive ${GIT} lfs checkout
|
||||
fi
|
||||
fi
|
||||
|
||||
# Find files that are affected by the export-subst git-attribute.
|
||||
# There might be a .gitattribute at the root of the repository, as well
|
||||
# as in any arbitrary sub-directory, whether from the master repository
|
||||
# or a submodule.
|
||||
# "git check-attr -z" outputs results using \0 as separator for everything,
|
||||
# so there is no difference between field or records (but there is a
|
||||
# trailing \0):
|
||||
# path_1\0attr_name\0attr_state\0path_2\0attr_name\0attr_state\0....
|
||||
mapfile -d "" files < <(
|
||||
set -o pipefail # Constrained to this sub-shell
|
||||
find . -print0 \
|
||||
|_plain_git check-attr --stdin -z export-subst \
|
||||
|(i=0
|
||||
while read -r -d "" val; do
|
||||
case "$((i++%3))" in
|
||||
(0) path="${val}";;
|
||||
(1) ;; # Attribute name, always "export-subst", as requested
|
||||
(2)
|
||||
if [ "${val}" = "set" ]; then
|
||||
printf "%s\0" "${path}"
|
||||
fi;;
|
||||
esac
|
||||
done
|
||||
)
|
||||
)
|
||||
# Replace format hints in those files. Always use the master repository
|
||||
# as the source of the git metadata, even for files found in submodules
|
||||
# as this is the most practical: there is no way to chdir() in (g)awk,
|
||||
# and recomputing GIT_DIR for each submodule would really be tedious...
|
||||
# There might be any arbitrary number of hints on each line, so iterate
|
||||
# over those one by one.
|
||||
for f in "${files[@]}"; do
|
||||
TZ=UTC \
|
||||
LC_ALL=C \
|
||||
GIT_DIR="${git_cache}/.git" \
|
||||
awk -v GIT="${GIT}" '
|
||||
{
|
||||
l = $(0);
|
||||
while( (i = match(l, /\$Format:[^\$]+\$/)) > 0 ) {
|
||||
len = RLENGTH;
|
||||
printf("%s", substr(l, 1, i-1) );
|
||||
fmt = substr(l, i, RLENGTH);
|
||||
pretty = substr(fmt, 9, length(fmt)-9);
|
||||
cmd = GIT " -c core.abbrev=40 log -s -n1 --pretty=format:'\''" pretty "'\''";
|
||||
while ( (cmd | getline replace) > 0) {
|
||||
printf("%s", replace);
|
||||
}
|
||||
ret = close(cmd);
|
||||
if (ret != 0) {
|
||||
printf("%s:%d: error while executing command \"%s\"\n", FILENAME, NR, cmd) > "/dev/stderr";
|
||||
exit 1;
|
||||
}
|
||||
l = substr(l, i+len);
|
||||
}
|
||||
printf("%s\n", l);
|
||||
}
|
||||
' "${f}" >"${f}.br-temp"
|
||||
mv -f "${f}.br-temp" "${f}"
|
||||
done
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
# Generate the archive.
|
||||
# We do not want the .git dir; we keep other .git files, in case they are the
|
||||
# only files in their directory.
|
||||
# The .git dir would generate non reproducible tarballs as it depends on
|
||||
# the state of the remote server. It also would generate large tarballs
|
||||
# (gigabytes for some linux trees) when a full clone took place.
|
||||
mk_tar_gz "${git_cache}" "${basename}" "${date}" "${output}" ".git/*"
|
||||
36
support/download/go-post-process
Executable file
36
support/download/go-post-process
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
. "${0%/*}/helpers"
|
||||
|
||||
# Parse our options
|
||||
while getopts "n:o:s:" OPT; do
|
||||
case "${OPT}" in
|
||||
o) output="${OPTARG}";;
|
||||
n) base_name="${OPTARG}";;
|
||||
s) subdir="${OPTARG}";;
|
||||
:) error "option '%s' expects a mandatory argument\n" "${OPTARG}";;
|
||||
\?) error "unknown option '%s'\n" "${OPTARG}";;
|
||||
esac
|
||||
done
|
||||
|
||||
# Already vendored tarball, nothing to do
|
||||
if tar tf "${output}" | grep -q "^[^/]*/vendor" ; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
post_process_unpack "${base_name}" "${output}"
|
||||
|
||||
# Do the Go vendoring
|
||||
pushd "${base_name}/${subdir}" > /dev/null
|
||||
|
||||
if [ ! -f go.mod ]; then
|
||||
echo "ERROR: no vendor/ folder and no go.mod, aborting"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
go mod vendor -v -modcacherw
|
||||
popd > /dev/null
|
||||
|
||||
post_process_repack $(pwd) "${base_name}" "${output}"
|
||||
102
support/download/helpers
Executable file
102
support/download/helpers
Executable file
@@ -0,0 +1,102 @@
|
||||
# Generate a reproducible archive from the content of a directory
|
||||
#
|
||||
# $1 : input directory
|
||||
# $2 : leading component in archive
|
||||
# $3 : ISO8601 date: YYYY-MM-DDThh:mm:ssZZ
|
||||
# $4 : output file
|
||||
# $5... : globs of filenames to exclude from the archive, suitable for
|
||||
# find's -path option, and relative to the input directory $1
|
||||
#
|
||||
# Notes :
|
||||
# - the timestamp is internally rounded to the highest entire second
|
||||
# less than or equal to the timestamp (i.e. any sub-second fractional
|
||||
# part is ignored)
|
||||
# - must not be called with CWD as, or below, the input directory
|
||||
# - some temporary files are created in CWD, and removed at the end
|
||||
#
|
||||
# Example:
|
||||
# $ find /path/to/temp/dir
|
||||
# /path/to/temp/dir/
|
||||
# /path/to/temp/dir/some-file
|
||||
# /path/to/temp/dir/some-dir/
|
||||
# /path/to/temp/dir/some-dir/some-other-file
|
||||
#
|
||||
# $ mk_tar_gz /path/to/some/dir \
|
||||
# foo_bar-1.2.3 \
|
||||
# 1970-01-01T00:00:00Z \
|
||||
# /path/to/foo.tar.gz \
|
||||
# '.git/*' '.svn/*'
|
||||
#
|
||||
# $ tar tzf /path/to/foo.tar.gz
|
||||
# foo_bar-1.2.3/some-file
|
||||
# foo_bar-1.2.3/some-dir/some-other-file
|
||||
#
|
||||
mk_tar_gz() {
|
||||
local in_dir="${1}"
|
||||
local base_dir="${2}"
|
||||
local date="${3}"
|
||||
local out="${4}"
|
||||
shift 4
|
||||
local glob tmp pax_options
|
||||
local -a find_opts
|
||||
|
||||
for glob; do
|
||||
find_opts+=( -or -path "./${glob#./}" )
|
||||
done
|
||||
|
||||
# Drop sub-second precision to play nice with GNU tar's valid_timespec check
|
||||
date="$(date -d "${date}" -u +%Y-%m-%dT%H:%M:%S+00:00)"
|
||||
|
||||
pax_options="delete=atime,delete=ctime,delete=mtime"
|
||||
pax_options+=",exthdr.name=%d/PaxHeaders/%f,exthdr.mtime={${date}}"
|
||||
|
||||
tmp="$(mktemp --tmpdir="$(pwd)")"
|
||||
pushd "${in_dir}" >/dev/null
|
||||
|
||||
# Establish list
|
||||
find . -not -type d -and -not \( -false "${find_opts[@]}" \) >"${tmp}.list"
|
||||
# Sort list for reproducibility
|
||||
LC_ALL=C sort <"${tmp}.list" >"${tmp}.sorted"
|
||||
|
||||
# Create POSIX tarballs, since that's the format the most reproducible
|
||||
${TAR} cf - --transform="s#^\./#${base_dir}/#S" \
|
||||
--numeric-owner --owner=0 --group=0 --mtime="${date}" \
|
||||
--format=posix --pax-option="${pax_options}" --mode='go=u,go-w' \
|
||||
-T "${tmp}.sorted" >"${tmp}.tar"
|
||||
|
||||
# Compress the archive
|
||||
gzip -6 -n <"${tmp}.tar" >"${out}"
|
||||
|
||||
rm -f "${tmp}"{.list,.sorted,.tar}
|
||||
|
||||
popd >/dev/null
|
||||
}
|
||||
|
||||
post_process_unpack() {
|
||||
local dest="${1}"
|
||||
local tarball="${2}"
|
||||
local one_file
|
||||
|
||||
mkdir "${dest}"
|
||||
${TAR} -C "${dest}" --strip-components=1 -xzf "${tarball}"
|
||||
one_file="$(find "${dest}" -type f -print0 |LC_ALL=C sort -z |sed 's/\x0.*//')"
|
||||
touch -r "${one_file}" "${dest}.timestamp"
|
||||
}
|
||||
|
||||
post_process_repack() {
|
||||
local in_dir="${1}"
|
||||
local base_dir="${2}"
|
||||
local out="${3}"
|
||||
local date
|
||||
|
||||
date="@$(stat -c '%Y' "${in_dir}/${base_dir}.timestamp")"
|
||||
|
||||
mk_tar_gz "${in_dir}/${base_dir}" "${base_dir}" "${date}" "${out}"
|
||||
}
|
||||
|
||||
trace() { local msg="${1}"; shift; printf "%s: ${msg}" "${my_name}" "${@}"; }
|
||||
warn() { trace "${@}" >&2; }
|
||||
error() { warn "${@}"; exit 1; }
|
||||
|
||||
# Keep this line and the following as last lines in this file.
|
||||
# vim: ft=bash
|
||||
50
support/download/hg
Executable file
50
support/download/hg
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# We want to catch any unexpected failure, and exit immediately
|
||||
set -e
|
||||
|
||||
# Download helper for hg, to be called from the download wrapper script
|
||||
#
|
||||
# Options:
|
||||
# -q Be quiet.
|
||||
# -o FILE Generate archive in FILE.
|
||||
# -u URI Clone from repository at URI.
|
||||
# -c CSET Use changeset (or revision) CSET.
|
||||
# -n NAME Use basename NAME.
|
||||
#
|
||||
# Environment:
|
||||
# HG : the hg command to call
|
||||
|
||||
quiet=
|
||||
while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
|
||||
case "${OPT}" in
|
||||
q) quiet=-q;;
|
||||
o) output="${OPTARG}";;
|
||||
u) uri="${OPTARG}";;
|
||||
c) cset="${OPTARG}";;
|
||||
n) basename="${OPTARG}";;
|
||||
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
|
||||
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1)) # Get rid of our options
|
||||
|
||||
# Caller needs to single-quote its arguments to prevent them from
|
||||
# being expanded a second time (in case there are spaces in them)
|
||||
_hg() {
|
||||
if [ -z "${quiet}" ]; then
|
||||
printf '%s ' ${HG} "${@}"; printf '\n'
|
||||
fi
|
||||
_plain_hg "$@"
|
||||
}
|
||||
# Note: please keep command below aligned with what is printed above
|
||||
_plain_hg() {
|
||||
eval ${HG} "${@}"
|
||||
}
|
||||
|
||||
_hg clone ${quiet} "${@}" --noupdate "'${uri}'" "'${basename}'"
|
||||
|
||||
_plain_hg archive ${quiet} --repository "'${basename}'" --type tgz \
|
||||
--prefix "'${basename}'" --rev "'${cset}'" \
|
||||
- >"${output}"
|
||||
47
support/download/scp
Executable file
47
support/download/scp
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# We want to catch any unexpected failure, and exit immediately
|
||||
set -e
|
||||
|
||||
# Download helper for scp, to be called from the download wrapper script
|
||||
#
|
||||
# Options:
|
||||
# -q Be quiet.
|
||||
# -o FILE Copy to local file FILE.
|
||||
# -f FILE Copy from remote file FILE.
|
||||
# -u URI Download file at URI.
|
||||
#
|
||||
# Environment:
|
||||
# SCP : the scp command to call
|
||||
|
||||
quiet=
|
||||
while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
|
||||
case "${OPT}" in
|
||||
q) quiet=-q;;
|
||||
o) output="${OPTARG}";;
|
||||
f) filename="${OPTARG}";;
|
||||
u) uri="${OPTARG}";;
|
||||
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
|
||||
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1)) # Get rid of our options
|
||||
|
||||
# Caller needs to single-quote its arguments to prevent them from
|
||||
# being expanded a second time (in case there are spaces in them)
|
||||
_scp() {
|
||||
if [ -z "${quiet}" ]; then
|
||||
printf '%s ' ${SCP} "${@}"; printf '\n'
|
||||
fi
|
||||
_plain_scp "$@"
|
||||
}
|
||||
# Note: please keep command below aligned with what is printed above
|
||||
_plain_scp() {
|
||||
eval ${SCP} "${@}"
|
||||
}
|
||||
|
||||
# Remove any scheme prefix
|
||||
uri="${uri##scp://}"
|
||||
|
||||
_scp ${quiet} "${@}" "'${uri}/${filename}'" "'${output}'"
|
||||
41
support/download/sftp
Executable file
41
support/download/sftp
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# We want to catch any unexpected failure, and exit immediately
|
||||
set -e
|
||||
|
||||
# Download helper for sftp, to be called from the download wrapper script
|
||||
#
|
||||
# Options:
|
||||
# -q Be quiet.
|
||||
# -o FILE Copy to local file FILE.
|
||||
# -f FILE Copy from remote file FILE.
|
||||
# -u URI Download file at URI.
|
||||
#
|
||||
# Environment:
|
||||
# SFTP : the sftp command to call
|
||||
|
||||
quiet=
|
||||
while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
|
||||
case "${OPT}" in
|
||||
q) quiet=-q;;
|
||||
o) output="${OPTARG}";;
|
||||
f) filename="${OPTARG}";;
|
||||
u) uri="${OPTARG}";;
|
||||
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
|
||||
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1)) # Get rid of our options
|
||||
|
||||
# Caller needs to single-quote its arguments to prevent them from
|
||||
# being expanded a second time (in case there are spaces in them)
|
||||
_sftp() {
|
||||
if [ -z "${quiet}" ]; then
|
||||
printf '%s ' ${SFTP} "${@}"; printf '\n'
|
||||
fi
|
||||
# Note: please keep command below aligned with what is printed above
|
||||
eval ${SFTP} "${@}"
|
||||
}
|
||||
|
||||
_sftp ${quiet} "${@}" "'${uri}/${filename}'" "'${output}'"
|
||||
91
support/download/svn
Executable file
91
support/download/svn
Executable file
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# NOTE: if the output of this backend has to change (e.g. we change what gets
|
||||
# included in the archive, or we change the format of the archive (e.g. tar
|
||||
# options, compression ratio or method)), we MUST update the format version
|
||||
# in the variable BR_FTM_VERSION_svn, in package/pkg-download.mk.
|
||||
|
||||
# We want to catch any unexpected failure, and exit immediately
|
||||
set -e
|
||||
|
||||
# Download helper for svn, to be called from the download wrapper script
|
||||
#
|
||||
# Options:
|
||||
# -q Be quiet.
|
||||
# -o FILE Generate archive in FILE.
|
||||
# -u URI Checkout from repository at URI.
|
||||
# -c REV Use revision REV.
|
||||
# -n NAME Use basename NAME.
|
||||
# -r Recursive, i.e. use externals
|
||||
#
|
||||
# Environment:
|
||||
# SVN : the svn command to call
|
||||
|
||||
# shellcheck disable=SC1090 # Only provides mk_tar_gz()
|
||||
# shellcheck disable=SC1091
|
||||
. "${0%/*}/helpers"
|
||||
|
||||
quiet=
|
||||
externals=--ignore-externals
|
||||
while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
|
||||
case "${OPT}" in
|
||||
q) quiet=-q;;
|
||||
o) output="${OPTARG}";;
|
||||
u) uri="${OPTARG}";;
|
||||
c) rev="${OPTARG}";;
|
||||
n) basename="${OPTARG}";;
|
||||
r) externals=;;
|
||||
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
|
||||
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1)) # Get rid of our options
|
||||
|
||||
# Caller needs to single-quote its arguments to prevent them from
|
||||
# being expanded a second time (in case there are spaces in them)
|
||||
_svn() {
|
||||
if [ -z "${quiet}" ]; then
|
||||
printf '%s ' "${SVN}" "${@}"; printf '\n'
|
||||
fi
|
||||
_plain_svn "$@"
|
||||
}
|
||||
# Note: please keep command below aligned with what is printed above
|
||||
_plain_svn() {
|
||||
# shellcheck disable=SC2086 # We want word-splitting for SVN
|
||||
# shellcheck disable=SC2294
|
||||
eval ${SVN} "${@}"
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2086 # externals and quiet may be empty
|
||||
_svn export --ignore-keywords ${quiet} ${externals} "${@}" "'${uri}@${rev}'" "'${basename}'"
|
||||
|
||||
# For 'svn info', we only need the credentials, if any; other options
|
||||
# would be invalid, as they are intended for 'svn export'.
|
||||
# We can also consume the positional parameters, as we'll no longer
|
||||
# be calling any other remote-reaching svn command.
|
||||
creds=
|
||||
while [ ${#} -gt 0 ]; do
|
||||
case "${1}" in
|
||||
--username=*) creds+=" ${1}"; shift;;
|
||||
--password=*) creds+=" ${1}"; shift;;
|
||||
--username) creds+=" ${1} ${2}"; shift 2;;
|
||||
--password) creds+=" ${1} ${2}"; shift 2;;
|
||||
*) shift;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Get the date of the revision, to generate reproducible archives.
|
||||
# The output format is YYYY-MM-DDTHH:MM:SS.mmmuuuZ (i.e. always in the
|
||||
# UTC timezone), which we can feed as-is to the --mtime option for tar.
|
||||
# In case there is a redirection (e.g. http -> https), just keep the
|
||||
# last line (svn outputs everything on stdout)
|
||||
# shellcheck disable=SC2086 # creds may be empty
|
||||
date="$( LC_ALL=C _plain_svn info ${creds} "'${uri}@${rev}'" \
|
||||
|sed -r -e '/^Last Changed Date: /!d; s///'
|
||||
)"
|
||||
|
||||
# Generate the archive.
|
||||
# We did a 'svn export' above, so it's not a working copy (there is no .svn
|
||||
# directory or file to ignore).
|
||||
mk_tar_gz "${basename}" "${basename}" "${date}" "${output}"
|
||||
50
support/download/wget
Executable file
50
support/download/wget
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# We want to catch any unexpected failure, and exit immediately
|
||||
set -e
|
||||
|
||||
# Download helper for wget, to be called from the download wrapper script
|
||||
#
|
||||
# Options:
|
||||
# -q Be quiet.
|
||||
# -o FILE Save into file FILE.
|
||||
# -f FILENAME The filename of the tarball to get at URL
|
||||
# -u URL Download file at URL.
|
||||
# -e ENCODE Tell wget to urlencode the filename passed to it
|
||||
#
|
||||
# Environment:
|
||||
# WGET : the wget command to call
|
||||
|
||||
quiet=
|
||||
while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
|
||||
case "${OPT}" in
|
||||
q) quiet=-q;;
|
||||
o) output="${OPTARG}";;
|
||||
f) filename="${OPTARG}";;
|
||||
u) url="${OPTARG}";;
|
||||
e) encode="-e";;
|
||||
:) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
|
||||
\?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1)) # Get rid of our options
|
||||
|
||||
# Caller needs to single-quote its arguments to prevent them from
|
||||
# being expanded a second time (in case there are spaces in them)
|
||||
_wget() {
|
||||
if [ -z "${quiet}" ]; then
|
||||
printf '%s ' ${WGET} "${@}"; printf '\n'
|
||||
fi
|
||||
_plain_wget "$@"
|
||||
}
|
||||
# Note: please keep command below aligned with what is printed above
|
||||
_plain_wget() {
|
||||
eval ${WGET} "${@}"
|
||||
}
|
||||
|
||||
# Replace every '?' with '%3F' in the filename; only for the PRIMARY and BACKUP
|
||||
# mirror
|
||||
[ -n "${encode}" ] && filename=${filename//\?/%3F}
|
||||
|
||||
_wget ${quiet} "${@}" -O "'${output}'" "'${url}/${filename}'"
|
||||
Reference in New Issue
Block a user