1*4882a593Smuzhiyun#!/usr/bin/env bash 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun# NOTE: if the output of this backend has to change (e.g. we change what gets 4*4882a593Smuzhiyun# included in the archive, or we change the format of the archive (e.g. tar 5*4882a593Smuzhiyun# options, compression ratio or method)), we MUST update the format version 6*4882a593Smuzhiyun# in the variable BR_FTM_VERSION_svn, in package/pkg-download.mk. 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun# We want to catch any unexpected failure, and exit immediately 9*4882a593Smuzhiyunset -e 10*4882a593Smuzhiyun 11*4882a593Smuzhiyun# Download helper for svn, to be called from the download wrapper script 12*4882a593Smuzhiyun# 13*4882a593Smuzhiyun# Options: 14*4882a593Smuzhiyun# -q Be quiet. 15*4882a593Smuzhiyun# -o FILE Generate archive in FILE. 16*4882a593Smuzhiyun# -u URI Checkout from repository at URI. 17*4882a593Smuzhiyun# -c REV Use revision REV. 18*4882a593Smuzhiyun# -n NAME Use basename NAME. 19*4882a593Smuzhiyun# 20*4882a593Smuzhiyun# Environment: 21*4882a593Smuzhiyun# SVN : the svn command to call 22*4882a593Smuzhiyun 23*4882a593Smuzhiyun. "${0%/*}/helpers" 24*4882a593Smuzhiyun 25*4882a593Smuzhiyunquiet= 26*4882a593Smuzhiyunwhile getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do 27*4882a593Smuzhiyun case "${OPT}" in 28*4882a593Smuzhiyun q) quiet=-q;; 29*4882a593Smuzhiyun o) output="${OPTARG}";; 30*4882a593Smuzhiyun u) uri="${OPTARG}";; 31*4882a593Smuzhiyun c) rev="${OPTARG}";; 32*4882a593Smuzhiyun n) basename="${OPTARG}";; 33*4882a593Smuzhiyun :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;; 34*4882a593Smuzhiyun \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;; 35*4882a593Smuzhiyun esac 36*4882a593Smuzhiyundone 37*4882a593Smuzhiyun 38*4882a593Smuzhiyunshift $((OPTIND-1)) # Get rid of our options 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun# Caller needs to single-quote its arguments to prevent them from 41*4882a593Smuzhiyun# being expanded a second time (in case there are spaces in them) 42*4882a593Smuzhiyun_svn() { 43*4882a593Smuzhiyun if [ -z "${quiet}" ]; then 44*4882a593Smuzhiyun printf '%s ' ${SVN} "${@}"; printf '\n' 45*4882a593Smuzhiyun fi 46*4882a593Smuzhiyun _plain_svn "$@" 47*4882a593Smuzhiyun} 48*4882a593Smuzhiyun# Note: please keep command below aligned with what is printed above 49*4882a593Smuzhiyun_plain_svn() { 50*4882a593Smuzhiyun eval ${SVN} "${@}" 51*4882a593Smuzhiyun} 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun_svn export --ignore-keywords ${quiet} "${@}" "'${uri}@${rev}'" "'${basename}'" 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun# Get the date of the revision, to generate reproducible archives. 56*4882a593Smuzhiyun# The output format is YYYY-MM-DDTHH:MM:SS.mmmuuuZ (i.e. always in the 57*4882a593Smuzhiyun# UTC timezone), which we can feed as-is to the --mtime option for tar. 58*4882a593Smuzhiyun# In case there is a redirection (e.g. http -> https), just keep the 59*4882a593Smuzhiyun# last line (svn outputs everything on stdout) 60*4882a593Smuzhiyundate="$( _plain_svn info "'${uri}@${rev}'" \ 61*4882a593Smuzhiyun |sed -r -e '/^Last Changed Date: /!d; s///' 62*4882a593Smuzhiyun )" 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun# Generate the archive. 65*4882a593Smuzhiyun# We did a 'svn export' above, so it's not a working copy (there is no .svn 66*4882a593Smuzhiyun# directory or file to ignore). 67*4882a593Smuzhiyunmk_tar_gz "${basename}" "${basename}" "${date}" "${output}" 68