#!/bin/sh
set -o nounset
set -o errexit
if [ "$#" != '0' ]
then
if [ "${1-}" != '-h' ] && [ "${1-}" != '--help' ]
then
code='0'
exec 1>&2
fi
cat <<EOF
USAGE: $0
Reads giada.spec from the same directory as the script. Uses the value of
%upstream_source to download the upstream release archive; filters out
non-redistributable files; and writes a distributable tarball to the current
working directory.
EOF
exit "${code-1}"
fi
OUTDIR="${PWD}"
cd "$(dirname "$0")"
SPEC="${PWD}/giada.spec"
URL="$(
rpm -E "$(
awk -F: '
tolower($0) ~ /^(name|version|summary|url):/ {
colon = index($0, ":")
printf("%%global %s %s\n", tolower($1), substr($0, colon + 1))
}
' "${SPEC}"
)
$(grep -E '^%global ' "${SPEC}")
%upstream_source
" | sed -r -e 's/^[[:blank:]]+//' -e 's/[[:blank:]]$//'
)"
ARCHIVE="$(echo "${URL}" | awk -F / '{ print $NF }')"
cat 1>&2 <<EOF
Downloading:
URL: ${URL}
Archive: ${ARCHIVE}
EOF
# Download the archive
tmpdir="$(mktemp --directory)"
trap "rm -rf '${tmpdir}'" INT TERM EXIT
curl \
--location \
--proto-redir -all,https \
--output "${tmpdir}/${ARCHIVE}" \
"${URL}"
phase() {
cat <<EOF
==============================================================================
$1
==============================================================================
EOF
}
phase 'Extracting upstream archive'
# Extract the archive
xdir="${tmpdir}/x"
mkdir "${xdir}"
tar -C "${xdir}" -xzf "${tmpdir}/${ARCHIVE}"
echo "Extracted ${ARCHIVE} ($(
stat --format=%s "${tmpdir}/${ARCHIVE}"
) bytes)"
phase 'Filtering upstream archive'
(
set -o nounset
set -o errexit
cd "${xdir}"
echo '--> Removing VST 3 SDK'
rm -rf */src/deps/vst3sdk
echo '--> Removing JUCE'
rm -rf */src/deps/juce
)
phase 'Writing filtered archive'
FILTERED_ARCHIVE="$(basename "${ARCHIVE}" .tar.gz)-distributable.tar"
tar -C "${xdir}" -c . -f "./${FILTERED_ARCHIVE}"
echo "Wrote ${FILTERED_ARCHIVE} ($(
stat --format=%s "${FILTERED_ARCHIVE}"
) bytes)"
phase 'Re-compressing filtered archive'
rm -vf "${FILTERED_ARCHIVE}.xz"
# We could re-compress as gzip with pigz almost instantly; xz takes quite a
# while, but saves many megabytes in the source RPM, which is probably worth
# it as long as we are re-compressing anyway.
xz -9ev "${FILTERED_ARCHIVE}"
phase 'Done'
echo "Wrote ${FILTERED_ARCHIVE}.xz ($(
stat --format=%s "${FILTERED_ARCHIVE}.xz"
) bytes)"