Debian Codegraph @

debian/repack

raw
1 #!/bin/bash
2 # debian/repack - Produce DFSG compliant orig.tar.xz from upstream tarball.
3 # 1) Unpack upstream tarball.
4 # 2) Check for DSFG compliance (no PDFs, SF3s or precompiled binaries).
5 # 3) Set revision number in mscore/revision.h to match Git commit number.
6 # 4) Pack into orig.tar.xz
7
8 set -e # exit on error
9
10 watchfile=$(dirname "$0")/watch
11 if [[ ! -e $watchfile ]]; then
12 printf >&2 '%s: Error! File %s not found.\n' "$0" "$watchfile"
13 exit 1
14 fi
15 apipath=$(grep -o '\<https://api.github.com/[^ \n]*' "$watchfile")
16 if [[ -z $apipath ]]; then
17 printf >&2 '%s: Error! github.com repository not found in %s!\n' "$0" "$watchfile"
18 exit 1
19 fi
20
21 function usage() {
22 cat >&2 <<EOF
23 debian/repack - set MuseScore revision number and check for DFSG compliance.
24
25 Usage: debian/repack --upstream-version VERSION [UPSTREAM-TARBALL]
26 Example: debian/repack --upstream-version "2.0.1+dfsg1"
27 EOF
28 }
29
30 if [[ $1 = --usage || $1 = --help || $1 = -[h?] ]]; then
31 usage
32 exit 0
33 fi
34
35 if [[ $1 != --upstream-version || -z $2 ]]; then
36 printf >&2 '%s: Error! Upstream version was not specified.\n\n' "$0"
37 usage
38 exit 1
39 fi
40
41 baseversion=$2
42 debversion=${baseversion//'%'/'~'}
43 if [[ $baseversion = *'+dfsg'* ]]; then
44 baseversion=${baseversion%+dfsg*}
45 fi
46 gitversion=v${baseversion//'~'/'%'}
47 baseversion=${baseversion//'%'/'~'}
48
49 printf >&2 'D: baseversion<%s> debversion<%s> gitversion<%s>\n' \
50 "$baseversion" "$debversion" "$gitversion"
51
52 tarpath=${3:-../musescore2_$2.orig.tar.gz}
53 printf >&2 '%s\n' "$0: Repacking upstream tarball '$tarpath'."
54
55 if [[ ! -f $tarpath ]]; then
56 printf >&2 '%s: Error! Upstream tarball not found.\n\n' "$0"
57 usage
58 exit 1
59 fi
60
61 tarball="$(basename "$tarpath")"
62 outdir="$(dirname "$tarpath")" # send output files to input directory
63
64 if [[ -n $(which realpath) ]]; then
65 outdir="$(realpath --relative-to="$PWD" "$outdir")"
66 fi
67
68 cd "$outdir"
69
70 symlink=""
71 if [[ -L $tarball ]]; then
72 # If $tarball was actually a symlink then resolve it
73 symlink="$tarball"
74 tarball="$(readlink "$symlink")"
75 fi
76
77 tempdir="tmp-musescore-$debversion"
78
79 # 1) Unpack upstream tarball
80 printf >&2 '%s\n' "Unpacking upstream tarball into '$tempdir'."
81 rm -rf "$tempdir"
82 mkdir "$tempdir"
83 tar -xaf "$tarball" -C "$tempdir"
84 cd "$tempdir"
85 mv *use*ore* "musescore2-$debversion.orig"
86 cd "musescore2-$debversion.orig"
87
88 # 2) Check for DSFG compliance (no precompiled binaries or PDFs, etc).
89 cat >&2 <<EOF
90 Checking for DFSG compliance. If any non compliant files are discovered then
91 they will be printed on the Terminal and then this script will exit. The non-
92 compliant files must be added to the Files-Excluded list within debian/copyright
93 and then you will need to run 'uscan' again. See uscan(1).
94 EOF
95
96 dfsg_compliant="TRUE"
97
98 echo >&2 "Searching for PDF, SF3 and object files..."
99 pdfs=$(find . -iname \*.pdf -o -iname \*.sf3 -o -iname \*.dll -o \
100 -iname \*.o -o -iname \*.a -o -iname \*.so -o -iname \*.so.\*)
101 if [[ -n $pdfs ]]; then
102 printf >&2 '%s\n' \
103 "$pdfs" \
104 "PDF, SF3 or other object files, which are not DFSG-free, were discovered." \
105 "Please add them to Files-Excluded in debian/copyright."
106 dfsg_compliant="FALSE"
107 fi
108
109 echo >&2 "Searching for precompiled binaries..."
110 binaries="$(find . -type f -executable -exec sh -c "file -i '{}' | grep -q 'x-executable; charset=binary'" \; -print)"
111 if [[ -n $binaries ]]; then
112 printf >&2 '%s\n' \
113 "$binaries" \
114 "Binary files were discovered. Binaries are non DFSG-free." \
115 "Please add them to Files-Excluded in debian/copyright."
116 dfsg_compliant="FALSE"
117 fi
118
119 if [[ $dfsg_compliant != TRUE ]]; then
120 echo >&2 "You will need to run 'uscan' again afterwards."
121 exit 1
122 fi
123
124 # 3) Set revision number in mscore/revision.h to match upstream Git commit
125 # Note: upstream has a Makefile target "make revision" to set the revision, but
126 # it only works inside a Git repo so we have to get the revision another way.
127 echo >&2 "Determining upstream revision (first 7 characters of Git commit SHA)."
128
129 if ! apires=$(wget -S --content-on-error -O - "$apipath"); then
130 printf >&2 '%s: Error! Could not read from GitHub API:\n%s\n' "$0" "$apires"
131 exit 1
132 fi
133
134 commit="$( \
135 printf '%s\n' "$apires" \
136 | tr -d '[:space:]' | sed -r 's/("name":)/\n\1/g' \
137 | grep -F "\"name\":\"$gitversion\"" \
138 | sed -nr 's/.*"sha":"([[:alnum:]]{7})[[:alnum:]]{33}".*/\1\n/p' \
139 )"
140
141 if [[ -z $commit ]]; then
142 printf >&2 '%s: Error! Could not get upstream commit. Data:\n%s\n' "$0" "$apires"
143 exit 1
144 fi
145
146 printf >&2 '%s\n' "Upstream revision is '$commit'."
147
148 printf >&2 '%s\n' "Setting revision number in 'mscore/revision.h' to '$commit'."
149 mtime="$(stat -c %y "mscore/revision.h")" # preserve modification time
150 printf '%s\n' "$commit" >"mscore/revision.h"
151 touch -d "$mtime" "mscore/revision.h"
152
153 # 4) Pack into orig.tar.xz
154 cd .. # now inside $tempdir
155 printf >&2 '%s\n' "Creating musescore2_$debversion.orig.tar; this may take a while"
156 tar -cf "../musescore2_$debversion.orig.tar" \
157 -Hustar -b1 \
158 --numeric-owner --owner=0 --group=0 \
159 --mode='u=rwX,go=rX' \
160 "musescore2-$debversion.orig"
161 cd .. # now back to output directory (outside $tempdir)
162
163 # Tidy up (must do this before compressing tar incase tarball has same name)
164 echo >&2 "Removing temporary files."
165 rm -rf "$tempdir" "$tarball" "$symlink"
166
167 # Compress new orig.tar
168 printf >&2 '%s\n' "Compressing musescore2_$debversion.orig.tar; this will take long"
169 xz -7e "musescore2_$debversion.orig.tar"
170
171 cat >&2 <<EOF
172 Finished!
173 The upstream code is in "$outdir/musescore2_$debversion.orig.tar.xz".
174 Check this in with pristine-tar after committing it to the upstream-rochade branch:
175 \$ pristine-tar commit '$outdir/musescore2_$debversion.orig.tar.xz' upstream-rochade
176 Then tag the upstream-rochade branch and merge it into rochade.
177 EOF