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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#!/bin/bash
# debian/repack - Produce DFSG compliant orig.tar.gz from upstream tarball.
# 1) Unpack upstream tarball.
# 2) Check for DSFG compliance (no PDFs or precompiled binaries).
# 3) Set revision number in mscore/revision.h to match Git commit number.
# 4) Pack into orig.tar.gz
set -e # exit on error
function usage() {
cat <<EOF
debian/repack - set MuseScore revision number and check for DFSG compliance.
Usage: debian/repack --upstream-version VERSION [UPSTREAM-TARBALL]
Example: debian/repack --upstream-version "2.0.1+dfsg1"
EOF
}
[[ "$1" == "--usage" || "$1" == "--help" || "$1" == -[h?] ]] && usage && exit
if [ "$1" != "--upstream-version" ] || [ ! "$2" ]; then
printf "$0: Error! Upstream version was not specified.\n\n$(usage)\n" >&2
exit 1
fi
version="$2"
if [[ $version == *"+dfsg"* ]]; then
dfsg="+dfsg${version#*+dfsg}"
version="${version%+dfsg*}"
fi
[ "$3" ] && tarpath="$3" || tarpath="../musescore_$version$dfsg.orig.tar.gz"
echo "$0: Repacking upstream tarball '$tarpath'." >&2
if [ ! -f "$tarpath" ]; then
printf "$0: Error! Upstream tarball not found.\n\n$(usage)\n" >&2
exit 1
fi
tarball="$(basename "$tarpath")"
outdir="$(dirname "$tarpath")" # send output files to input directory
if [ "$(which realpath)" ]; then
outdir="$(realpath --relative-to="$PWD" "$outdir")"
fi
cd "$outdir"
symlink=""
if [ -L "$tarball" ]; then
# If $tarball was actually a symlink then resolve it
symlink="$tarball"
tarball="$(readlink "$symlink")"
fi
tempdir="tmp-musescore-$version$dfsg"
# 1) Unpack upstream tarball
echo "Unpacking upstream tarball into '$tempdir'." >&2
mkdir "$tempdir"
tar -zxf "$tarball" -C "$tempdir"
cd "$tempdir/MuseScore-$version"
# 2) Check for DSFG compliance (no precompiled binaries or PDFs, etc).
cat >&2 <<EOF
Checking for DFSG compliance. If any non compliant files are discovered then
they will be printed on the Terminal and then this script will exit. The non-
compliant files must be added to the Files-Excluded list within debian/copyright
and then you will need to run 'uscan' or 'gbp import-orig' again. See USCAN(1).
EOF
dfsg_compliant="TRUE"
echo "Searching for PDF files..." >&2
pdfs="$(find . -iname "*.pdf" -print)"
if [ "$pdfs" ]; then
echo "$pdfs"
echo "PDF files were discovered. PDFs are non DFSG-free." >&2
echo "Please add them to Files-Excluded in debian/copyright." >&2
dfsg_compliant="FALSE"
fi
echo "Searching for precompiled binaries..." >&2
binaries="$(find . -type f -executable -exec sh -c "file -i '{}' | grep -q 'x-executable; charset=binary'" \; -print)"
if [ "$binaries" ]; then
echo "$binaries"
echo "Binary files were discovered. Binaries are non DFSG-free." >&2
echo "Please add them to Files-Excluded in debian/copyright." >&2
dfsg_compliant="FALSE"
fi
if [ "$dfsg_compliant" == "FALSE" ]; then
echo "You will need to run 'uscan' or 'gbp import-orig' again afterwards." >&2
exit 1
fi
# 3) Set revision number in mscore/revision.h to match upstream Git commit
# Note: upstream has a Makefile target "make revision" to set the revision, but
# it only works inside a Git repo so we have to get the revision another way.
echo "Determining upstream revision (first 7 characters of Git commit SHA)." >&2
commit="$( \
wget -qO - https://api.github.com/repos/musescore/MuseScore/tags \
| tr -d '[:space:]' | sed -r 's/("name":)/\n\1/g' \
| grep -F "\"name\":\"v$version\"" \
| sed -nr 's/.*"sha":"([[:alnum:]]{7})[[:alnum:]]{33}".*/\1\n/p' \
)"
if [ ! "$commit" ]; then
echo "$0: Error! Couldn't get upstream commit." >&2
exit 1
fi
echo "Upstream revision is '$commit'." >&2
echo "Setting revision number in 'mscore/revision.h' to '$commit'." >&2
mtime="$(stat -c %y "mscore/revision.h")" # preserve modification time
echo "$commit" > "mscore/revision.h"
touch -d "$mtime" "mscore/revision.h"
# 4) Pack into orig.tar.gz
cd .. # now inside $tempdir
mv "MuseScore-$version" "musescore-$version$dfsg"
tar -cf "../musescore_$version$dfsg.orig.tar" "musescore-$version$dfsg"
cd .. # now back to output directory (outside $tempdir)
# Tidy up (must do this before compressing tar incase tarball has same name)
echo "Removing temporary files." >&2
rm -rf "$tempdir" "$tarball" "$symlink"
# Compress new orig.tar
gzip -9 "musescore_$version$dfsg.orig.tar"
cat >&2 <<EOF
Finished!
The upstream code is in "$outdir/musescore_$version$dfsg.orig.tar.gz".
Use 'uupdate' to upgrade the source package based on the upstream release:
\$ uupdate --upstream-version $version $outdir/musescore_$version$dfsg.orig.tar.gz
Or, if working in a Git repository, use git-buildpackage to update the source:
\$ gbp import-orig --merge-mode=replace $outdir/musescore_$version$dfsg.orig.tar.gz
EOF
|