James Kuszmaul | 4cb043c | 2021-01-17 11:25:51 -0800 | [diff] [blame] | 1 | #!/bin/bash -e |
| 2 | # $Id: make-deb 2770 2013-05-30 08:46:46Z dreibh $ |
| 3 | # |
| 4 | # Debian Packaging Scripts |
| 5 | # Copyright (C) 2002-2017 by Thomas Dreibholz |
| 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation, either version 3 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # |
| 20 | # Contact: dreibh@iem.uni-due.de |
| 21 | |
| 22 | |
| 23 | # --------------------------------------------------------------------------- |
| 24 | # USAGE: |
| 25 | # ./make-deb default => for Ubuntu REVU |
| 26 | # Note: Replaces "Maintainer" by Ubuntu Developers and |
| 27 | # writes original maintainer entry to "XSBC-Original-Maintainer" |
| 28 | # ./make-deb unstable => for Debian Mentors |
| 29 | # ./make-deb natty|maverick|... => for Launchpad PPA |
| 30 | # --------------------------------------------------------------------------- |
| 31 | |
| 32 | |
| 33 | DISTRIBUTIONS=`\ |
| 34 | ( \ |
| 35 | while [ x$1 != "x" ] ; do \ |
| 36 | echo $1 |
| 37 | shift |
| 38 | done \ |
| 39 | ) | sort -u` |
| 40 | if [ "$DISTRIBUTIONS" == "" ] ; then |
| 41 | DISTRIBUTIONS="default" |
| 42 | fi |
| 43 | |
| 44 | |
| 45 | CHANGELOG_HEADER="`head -n1 debian/changelog`" |
| 46 | |
| 47 | # The package name, e.g. MyApplication |
| 48 | PACKAGE=`echo $CHANGELOG_HEADER | sed -e "s/(.*//" -e "s/ //g"` |
| 49 | |
| 50 | # The package distribution, e.g. precise, raring, ... |
| 51 | PACKAGE_DISTRIBUTION=`echo $CHANGELOG_HEADER | sed -e "s/[^)]*)//" -e "s/;.*//g" -e "s/ //g"` |
| 52 | # The package's version, e.g. 1.2.3-1ubuntu1 |
| 53 | PACKAGE_VERSION=`echo $CHANGELOG_HEADER | sed -e "s/.*(//" -e "s/).*//" -e "s/ //g" -e "s/ //g" -e "s/^[0-9]://g"` |
| 54 | # The package's output version, e.g. 1.2.3-1ubuntu |
| 55 | OUTPUT_VERSION=`echo $PACKAGE_VERSION | sed -e "s/\(ubuntu\|ppa\)[0-9]*$/\1/"` |
| 56 | # The package's Debian version, e.g. 1.2.3-1 |
| 57 | DEBIAN_VERSION=`echo $OUTPUT_VERSION | sed -e "s/\(ubuntu\|ppa\)$//1"` |
| 58 | # The package's upstream version, e.g. 1.2.3 |
| 59 | UPSTREAM_VERSION=`echo $DEBIAN_VERSION | sed -e "s/-[0-9]*$//"` |
| 60 | # The package's plain upstream version, e.g. 1.2.3 (without e.g. ~svn<xxxx>) |
| 61 | PLAIN_VERSION=`echo $UPSTREAM_VERSION | sed -e "s/\([0-9\.]*\)[-+~].*$/\1/"` |
| 62 | |
| 63 | |
| 64 | echo -e "\x1b[34m######################################################################\x1b[0m" |
| 65 | echo -e "\x1b[34mCHANGELOG_HEADER: $CHANGELOG_HEADER\x1b[0m" |
| 66 | echo -e "\x1b[34mPACKAGE: $PACKAGE\x1b[0m" |
| 67 | echo -e "\x1b[34mPACKAGE_DISTRIBUTION: $PACKAGE_DISTRIBUTION\x1b[0m" |
| 68 | echo -e "\x1b[34mPACKAGE_VERSION $PACKAGE_VERSION\x1b[0m" |
| 69 | echo -e "\x1b[34mOUTPUT_VERSION: $OUTPUT_VERSION\x1b[0m" |
| 70 | echo -e "\x1b[34mDEBIAN_VERSION: $DEBIAN_VERSION\x1b[0m" |
| 71 | echo -e "\x1b[34mUPSTREAM_VERSION: $UPSTREAM_VERSION\x1b[0m" |
| 72 | echo -e "\x1b[34mPLAIN_VERSION: $PLAIN_VERSION\x1b[0m" |
| 73 | echo -e "\x1b[34m######################################################################\x1b[0m" |
| 74 | |
| 75 | if [ ! -e ./debian.conf ] ; then |
| 76 | echo >&2 "ERROR: debian.conf does not exist -> no configuration for the new package!" |
| 77 | exit 1 |
| 78 | fi |
| 79 | . ./debian.conf |
| 80 | |
| 81 | |
| 82 | echo -e "" |
| 83 | echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Calling wrap-and-sort ==========================================\x1b[0m" |
| 84 | echo -e "" |
| 85 | wrap-and-sort -a -v || exit 1 |
| 86 | |
| 87 | |
| 88 | echo -e "" |
| 89 | echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Creating upstream package ======================================\x1b[0m" |
| 90 | echo -e "" |
| 91 | UPSTREAM_PACKAGE="`find . -maxdepth 1 -name "$PACKAGE-*.gz" -printf '%f'`" |
| 92 | UPSTREAM_PACKAGE_TYPE="gz" |
| 93 | if [ ! -e "$UPSTREAM_PACKAGE" ] ; then |
| 94 | UPSTREAM_PACKAGE="`find . -maxdepth 1 -name "$PACKAGE-*.bz2" -printf '%f'`" |
| 95 | UPSTREAM_PACKAGE_TYPE="bz2" |
| 96 | fi |
| 97 | if [ ! -e "$UPSTREAM_PACKAGE" ]; then |
| 98 | rm -f $PACKAGE-*.gz $PACKAGE"_"*.gz $PACKAGE-*.bz2 $PACKAGE"_"*.bz2 |
| 99 | echo -e "\x1b[34m------ Running MAKE_DIST ... ------\x1b[0m" |
| 100 | echo "\$ $MAKE_DIST" |
| 101 | eval "$MAKE_DIST" |
| 102 | |
| 103 | echo -e "\x1b[34m------ Looking for upstream package ... ------\x1b[0m" |
| 104 | UPSTREAM_PACKAGE="`find . -maxdepth 1 -name $PACKAGE-*.gz -printf '%f'`" |
| 105 | UPSTREAM_PACKAGE_TYPE="gz" |
| 106 | if [ ! -e "$UPSTREAM_PACKAGE" ] ; then |
| 107 | UPSTREAM_PACKAGE="`find . -maxdepth 1 -name $PACKAGE-*.bz2 -printf '%f'`" |
| 108 | UPSTREAM_PACKAGE_TYPE="bz2" |
| 109 | fi |
| 110 | if [ ! -e "$UPSTREAM_PACKAGE" ] ; then |
| 111 | echo -e "\x1b[34mERROR: No upstrem package found!\x1b[0m" |
| 112 | exit 1 |
| 113 | fi |
| 114 | fi |
| 115 | echo -e "" |
| 116 | echo -e "\x1b[34m==> Upstream package is $UPSTREAM_PACKAGE (type is $UPSTREAM_PACKAGE_TYPE)\x1b[0m" |
| 117 | echo -e "" |
| 118 | |
| 119 | |
| 120 | echo -e "" |
| 121 | echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Creating packages ==============================================\x1b[0m" |
| 122 | for DISTRIBUTION in $DISTRIBUTIONS ; do |
| 123 | |
| 124 | echo -e "" |
| 125 | echo -e "\x1b[34m------ Creating package for $DISTRIBUTION ------\x1b[0m" |
| 126 | |
| 127 | success=1 |
| 128 | cp ${UPSTREAM_PACKAGE} ${PACKAGE}_${UPSTREAM_VERSION}.orig.tar.$UPSTREAM_PACKAGE_TYPE |
| 129 | cp ${UPSTREAM_PACKAGE} ${PACKAGE}_$OUTPUT_VERSION.orig.tar.$UPSTREAM_PACKAGE_TYPE |
| 130 | cp ${UPSTREAM_PACKAGE} ${PACKAGE}_$DEBIAN_VERSION.orig.tar.$UPSTREAM_PACKAGE_TYPE |
| 131 | rm -rf ${PACKAGE}-${UPSTREAM_VERSION} |
| 132 | rm -rf ${PACKAGE}-${UPSTREAM_VERSION}.orig |
| 133 | if [ "$UPSTREAM_PACKAGE_TYPE" = "gz" ] ; then |
| 134 | tar xzf ${UPSTREAM_PACKAGE} |
| 135 | elif [ "$UPSTREAM_PACKAGE_TYPE" = "bz2" ] ; then |
| 136 | tar xjf ${UPSTREAM_PACKAGE} |
| 137 | else |
| 138 | echo 2>&1 "ERROR: Bad archive format: $UPSTREAM_PACKAGE" |
| 139 | exit 1 |
| 140 | fi |
| 141 | cp -r ${PACKAGE}-${UPSTREAM_VERSION} ${PACKAGE}-${UPSTREAM_VERSION}.orig |
| 142 | cp -r debian ${PACKAGE}-${UPSTREAM_VERSION} |
| 143 | find ${PACKAGE}-${UPSTREAM_VERSION} -name .svn | xargs --no-run-if-empty rm -rf |
| 144 | cd ${PACKAGE}-${UPSTREAM_VERSION} |
| 145 | success=0 |
| 146 | |
| 147 | if [ $success -ne 0 ] ; then |
| 148 | exit 1 |
| 149 | fi |
| 150 | |
| 151 | if [ "$DISTRIBUTION" != "default" ] ; then |
| 152 | if [ "$DISTRIBUTION" = "unstable" -o "$DISTRIBUTION" = "testing" -o "$DISTRIBUTION" = "stable" ] ; then |
| 153 | # Debian: Also remove Launchpad Bug IDs. |
| 154 | sed -e "s/$PACKAGE_DISTRIBUTION;/$DISTRIBUTION;/1" \ |
| 155 | -e "s/\(ubuntu\|ppa\)[0-9]//1" \ |
| 156 | -e "/(LP: #/D" \ |
| 157 | <debian/changelog | ../filter-empty-entries "$DEBIAN_LAST_ENTRY" >debian/changelog.new |
| 158 | else |
| 159 | # Ubuntu PPA |
| 160 | # Naming example: 2.7.7-0ubuntu1~natty1~ppa0 |
| 161 | # Ubuntu: Also remove Debian Bug IDs. |
| 162 | sed -e "s/$PACKAGE_DISTRIBUTION;/$DISTRIBUTION;/1" \ |
| 163 | -e "s/$PACKAGE_VERSION/$PACKAGE_VERSION~${DISTRIBUTION}1~ppa0/1" \ |
| 164 | -e "/(Closes: #/D" \ |
| 165 | <debian/changelog | ../filter-empty-entries "$UBUNTU_LAST_ENTRY" >debian/changelog.new |
| 166 | |
| 167 | # ------ Old distributions not supporting c++/regex style symbols -- |
| 168 | if [ "$DISTRIBUTION" = "dapper" -o \ |
| 169 | "$DISTRIBUTION" = "edgy" -o \ |
| 170 | "$DISTRIBUTION" = "feisty" -o \ |
| 171 | "$DISTRIBUTION" = "hardy" -o \ |
| 172 | "$DISTRIBUTION" = "intrepid" -o \ |
| 173 | "$DISTRIBUTION" = "jaunty" -o \ |
| 174 | "$DISTRIBUTION" = "karmic" -o \ |
| 175 | "$DISTRIBUTION" = "lucid" ] ; then |
| 176 | # Just skip the symbols ... |
| 177 | find debian/ -maxdepth 1 -name "*.symbols" | xargs --no-run-if-empty rm -f |
| 178 | fi |
| 179 | fi |
| 180 | mv debian/changelog.new debian/changelog |
| 181 | |
| 182 | # ------ Old distributions not supporting new Debian format ----------- |
| 183 | if [ "$DISTRIBUTION" = "dapper" -o \ |
| 184 | "$DISTRIBUTION" = "edgy" -o \ |
| 185 | "$DISTRIBUTION" = "feisty" -o \ |
| 186 | "$DISTRIBUTION" = "hardy" -o \ |
| 187 | "$DISTRIBUTION" = "intrepid" -o \ |
| 188 | "$DISTRIBUTION" = "jaunty" ] ; then |
| 189 | rm -rf debian/source |
| 190 | fi |
| 191 | # --------------------------------------------------------------------- |
| 192 | else |
| 193 | # Ubuntu: Remove Debian Bug IDs. |
| 194 | sed -e "/(Closes: #/D" \ |
| 195 | <debian/changelog >debian/changelog.new |
| 196 | mv debian/changelog.new debian/changelog |
| 197 | sed -e "s/^Maintainer:/Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>\nXSBC-Original-Maintainer:/g" <debian/control >debian/control.new |
| 198 | mv debian/control.new debian/control |
| 199 | fi |
| 200 | |
| 201 | echo -e "" |
| 202 | echo -e "\x1b[34m------ Creating diff file $PACKAGE-$PACKAGE_VERSION.diff.gz ------\x1b[0m" |
| 203 | ( |
| 204 | cd .. |
| 205 | diff -urN "--exclude=*~" "--exclude=.svn" "--exclude=.git" \ |
| 206 | $PACKAGE-$UPSTREAM_VERSION.orig $PACKAGE-$UPSTREAM_VERSION \ |
| 207 | | gzip -c >$PACKAGE-$PACKAGE_VERSION.diff.gz |
| 208 | ) |
| 209 | |
| 210 | |
| 211 | echo -e "" |
| 212 | echo -e "\x1b[34m------ Building source package ------\x1b[0m" |
| 213 | |
| 214 | # Without signature: |
| 215 | # debuild -us -uc |
| 216 | # For sources: |
| 217 | # debuild -S |
| 218 | # For binaries: |
| 219 | # debuild -b |
| 220 | # Use -i to ignore .svn files! |
| 221 | |
| 222 | |
| 223 | if [ "$SKIP_PACKAGE_SIGNING" = "" ] ; then |
| 224 | SKIP_PACKAGE_SIGNING=0 |
| 225 | fi |
| 226 | if [ $SKIP_PACKAGE_SIGNING -eq 1 ] ; then |
| 227 | # Build source package without signature: |
| 228 | debuild -us -uc -S "-k$MAINTAINER" -i || exit 1 |
| 229 | else |
| 230 | # Build source package including signature: |
| 231 | debuild -sa -S "-k$MAINTAINER" -i || exit 1 |
| 232 | fi |
| 233 | |
| 234 | # Important: In /etc/pbuilderrc, set COMPONENTS="main universe"! |
| 235 | # Important: After that, update with option "--override-config"! |
| 236 | # sudo pbuilder update --override-config |
| 237 | |
| 238 | cd .. |
| 239 | |
| 240 | if [ "$DISTRIBUTION" = "unstable" -o \ |
| 241 | "$DISTRIBUTION" = "testing" -o \ |
| 242 | "$DISTRIBUTION" = "stable" -o \ |
| 243 | "$DISTRIBUTION" = "default" ] ; then |
| 244 | if [ "$DISTRIBUTION" = "default" ] ; then |
| 245 | version=${PACKAGE_VERSION} |
| 246 | else |
| 247 | version=${DEBIAN_VERSION} |
| 248 | fi |
| 249 | dscFile=`ls ${PACKAGE}_${version}.dsc | tail -n1` |
| 250 | else |
| 251 | dscFile=`ls ${PACKAGE}_${PACKAGE_VERSION}~${DISTRIBUTION}[0-9]~ppa[0-9].dsc | tail -n1` |
| 252 | fi |
| 253 | if [ ! -e $dscFile ] ; then |
| 254 | echo -e "\x1b[34mERROR: $dscFile has not been generated successfully -> Aborting!\x1b[0m" |
| 255 | exit 1 |
| 256 | fi |
| 257 | |
| 258 | done |
| 259 | |
| 260 | |
| 261 | |
| 262 | if [ -e "$UPSTREAM_PACKAGE.asc" ] ; then |
| 263 | rm -f "$UPSTREAM_PACKAGE.asc" |
| 264 | fi |
| 265 | if [ "$SKIP_PACKAGE_SIGNING" != "" -a ! $SKIP_PACKAGE_SIGNING -eq 1 ] ; then |
| 266 | echo -e "" |
| 267 | echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Sign upstream package ==========================================\x1b[0m" |
| 268 | echo -e "" |
| 269 | echo -e "\x1b[34mSigning upstream package $UPSTREAM_PACKAGE ...\x1b[0m" |
| 270 | gpg -sab "$UPSTREAM_PACKAGE" |
| 271 | fi |
| 272 | |
| 273 | |
| 274 | |
| 275 | echo -e "" |
| 276 | echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Command overview ===============================================\x1b[0m" |
| 277 | echo -e "" |
| 278 | |
| 279 | echo -e "\x1b[34mUpload to PPA:\x1b[0m" |
| 280 | for DISTRIBUTION in $DISTRIBUTIONS ; do |
| 281 | if [ "$DISTRIBUTION" = "unstable" -o \ |
| 282 | "$DISTRIBUTION" = "testing" -o \ |
| 283 | "$DISTRIBUTION" = "stable" -o \ |
| 284 | "$DISTRIBUTION" = "default" ] ; then |
| 285 | if [ "$DISTRIBUTION" = "default" ] ; then |
| 286 | ppa="revu" |
| 287 | version=${PACKAGE_VERSION} |
| 288 | else |
| 289 | ppa="mentors" |
| 290 | version=${DEBIAN_VERSION} |
| 291 | fi |
| 292 | changesFile=`ls ${PACKAGE}_${version}_source.changes | tail -n1` |
| 293 | else |
| 294 | ppa="ppa" |
| 295 | changesFile=`ls ${PACKAGE}_${PACKAGE_VERSION}~${DISTRIBUTION}[0-9]~ppa[0-9]_source.changes | tail -n1` |
| 296 | fi |
| 297 | echo -e "\x1b[34m dput $ppa $changesFile\x1b[0m" |
| 298 | done |
| 299 | echo -e "" |
| 300 | |
| 301 | |
| 302 | |
| 303 | if [ -e make-symbols ] ; then |
| 304 | echo -e "\x1b[34m################################################################\x1b[0m" |
| 305 | echo -e "\x1b[34mDo not forget to run make-symbols after library version changes!\x1b[0m" |
| 306 | echo -e "\x1b[34m################################################################\x1b[0m" |
| 307 | echo -e "" |
| 308 | fi |
| 309 | |
| 310 | echo -e "\x1b[34mBuild Test Commands:\x1b[0m" |
| 311 | for DISTRIBUTION in $DISTRIBUTIONS ; do |
| 312 | if [ "$DISTRIBUTION" = "unstable" -o \ |
| 313 | "$DISTRIBUTION" = "testing" -o \ |
| 314 | "$DISTRIBUTION" = "stable" -o \ |
| 315 | "$DISTRIBUTION" = "default" ] ; then |
| 316 | if [ "$DISTRIBUTION" = "default" ] ; then |
| 317 | version=${PACKAGE_VERSION} |
| 318 | else |
| 319 | version=${DEBIAN_VERSION} |
| 320 | fi |
| 321 | changesFilesPattern="${PACKAGE}_${version}_*.changes" |
| 322 | dscFile=`ls ${PACKAGE}_${version}.dsc | tail -n1` |
| 323 | else |
| 324 | changesFilesPattern="${PACKAGE}_${PACKAGE_VERSION}~${DISTRIBUTION}[0-9]~ppa[0-9]_*.changes" |
| 325 | dscFile=`ls ${PACKAGE}_${PACKAGE_VERSION}~${DISTRIBUTION}[0-9]~ppa[0-9].dsc | tail -n1` |
| 326 | fi |
| 327 | echo -e "\x1b[34m sudo pbuilder build $dscFile && lintian -iIEv --pedantic /var/cache/pbuilder/result/$changesFilesPattern\x1b[0m" |
| 328 | done |
| 329 | echo -e "" |