2015-10-24 12:55:13 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2021-01-02 21:34:16 +01:00
|
|
|
# Copyright (C) 2015-2021 Sébastien Helleu <flashcode@flashtux.org>
|
2015-10-24 12:55:13 +02:00
|
|
|
#
|
|
|
|
# This file is part of WeeChat, the extensible chat client.
|
|
|
|
#
|
|
|
|
# WeeChat is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# WeeChat is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2018-11-29 23:16:07 +01:00
|
|
|
# along with WeeChat. If not, see <https://www.gnu.org/licenses/>.
|
2015-10-24 12:55:13 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# Build WeeChat Debian packages for a stable or development version.
|
|
|
|
#
|
|
|
|
# According to the version (stable/devel), a symbolic "debian" is made:
|
|
|
|
# debian/ --> debian-stable/
|
|
|
|
# or: debian/ --> debian-devel/
|
|
|
|
#
|
|
|
|
# According to the distro version, a patch can be applied on debian files
|
|
|
|
# (patches are in directory tools/debian/patches).
|
|
|
|
#
|
|
|
|
# Script arguments: Examples:
|
|
|
|
#
|
2017-09-28 01:54:53 +02:00
|
|
|
# 1. version devel, devel-2, stable, stable-2, 1.9, 1.9-2
|
|
|
|
# 2. distro type/name debian/sid, ubuntu/artful, raspbian/stretch
|
2015-10-24 12:55:13 +02:00
|
|
|
#
|
2018-03-20 22:09:20 +01:00
|
|
|
# The script can also just check that all Debian/Ubuntu patches apply fine
|
|
|
|
# with a single argument: "test-patches".
|
|
|
|
#
|
2015-10-24 12:55:13 +02:00
|
|
|
# Examples:
|
|
|
|
#
|
|
|
|
# …/build-debian.sh devel debian/sid
|
2017-09-28 01:54:53 +02:00
|
|
|
# …/build-debian.sh stable debian/stretch
|
|
|
|
# …/build-debian.sh 1.9 ubuntu/artful
|
|
|
|
# …/build-debian.sh 1.9-2 ubuntu/zesty
|
2015-10-24 12:55:13 +02:00
|
|
|
#
|
2018-03-20 22:09:20 +01:00
|
|
|
# …/build-debian.sh test-patches
|
|
|
|
#
|
2015-10-24 12:55:13 +02:00
|
|
|
# Environment variables that can be used:
|
|
|
|
#
|
|
|
|
# PACKAGER_NAME Name of packager (for debian/changelog)
|
|
|
|
# PACKAGER_EMAIL E-mail of packager (for debian/changelog)
|
|
|
|
# JOBS Number of simultaneous jobs (for dpkg-buildpackage)
|
|
|
|
# (numeric or "auto" for dpkg >= 1.17.10)
|
|
|
|
#
|
|
|
|
|
|
|
|
# exit on any error
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# default values for options from environment variables
|
|
|
|
DEFAULT_PACKAGER_NAME="Sébastien Helleu"
|
|
|
|
DEFAULT_PACKAGER_EMAIL="flashcode@flashtux.org"
|
|
|
|
DEFAULT_JOBS=""
|
|
|
|
|
2016-04-01 07:44:35 +02:00
|
|
|
usage ()
|
2015-10-24 12:55:13 +02:00
|
|
|
{
|
2016-04-01 07:44:35 +02:00
|
|
|
RC=$1
|
2015-10-24 12:55:13 +02:00
|
|
|
cat <<-EOF
|
|
|
|
|
|
|
|
Syntax: $0 devel|stable|<version> distro
|
2018-03-20 22:09:20 +01:00
|
|
|
$0 test-patches
|
2015-10-24 12:55:13 +02:00
|
|
|
|
2018-03-20 22:09:20 +01:00
|
|
|
version version to build: stable, devel or specific version
|
|
|
|
(debian package revision is allowed after name (default is 1),
|
|
|
|
for example: devel-2, stable-2, 1.9-2)
|
|
|
|
distro the distro type/name (debian/sid, ubuntu/artful, raspbian/stretch, ...)
|
|
|
|
|
|
|
|
test-patches test that all Debian/Ubuntu patches apply fine (with git apply --check)
|
2015-10-24 12:55:13 +02:00
|
|
|
|
|
|
|
IMPORTANT: the current OS must match the distro, and the WeeChat sources
|
|
|
|
must be checkouted in the appropriate version (this script
|
|
|
|
does not checkout sources on a specific tag).
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
$0 devel debian/sid
|
2017-09-28 01:54:53 +02:00
|
|
|
$0 stable debian/stretch
|
|
|
|
$0 1.9 ubuntu/artful
|
|
|
|
$0 1.9-2 ubuntu/zesty
|
2018-03-20 22:09:20 +01:00
|
|
|
$0 test-patches
|
2015-10-24 12:55:13 +02:00
|
|
|
|
|
|
|
EOF
|
2019-11-28 21:23:59 +01:00
|
|
|
exit "${RC}"
|
2015-10-24 12:55:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
error ()
|
|
|
|
{
|
|
|
|
echo >&2 "ERROR: $*"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
error_usage ()
|
|
|
|
{
|
|
|
|
echo >&2 "ERROR: $*"
|
2016-04-01 07:44:35 +02:00
|
|
|
usage 1
|
2015-10-24 12:55:13 +02:00
|
|
|
}
|
|
|
|
|
2018-03-20 22:09:20 +01:00
|
|
|
test_patches ()
|
|
|
|
{
|
|
|
|
set +e
|
2018-03-22 21:13:23 +01:00
|
|
|
PATCHES_OK=0
|
|
|
|
PATCHES_ERROR=0
|
2019-11-28 21:23:59 +01:00
|
|
|
for file in "${ROOT_DIR}"/tools/debian/patches/*.patch; do
|
2018-03-20 22:09:20 +01:00
|
|
|
echo "=== Testing patch ${file} ==="
|
2019-11-28 21:25:47 +01:00
|
|
|
if git apply --check "${file}"; then
|
2018-03-22 21:13:23 +01:00
|
|
|
PATCHES_OK=$((PATCHES_OK+1))
|
|
|
|
else
|
|
|
|
PATCHES_ERROR=$((PATCHES_ERROR+1))
|
2018-03-20 22:09:20 +01:00
|
|
|
fi
|
|
|
|
done
|
2018-03-22 21:13:23 +01:00
|
|
|
echo "Patches: ${PATCHES_OK} OK, ${PATCHES_ERROR} in error."
|
|
|
|
exit ${PATCHES_ERROR}
|
2018-03-20 22:09:20 +01:00
|
|
|
}
|
|
|
|
|
2015-10-24 12:55:13 +02:00
|
|
|
# ================================== START ==================================
|
|
|
|
|
|
|
|
# package name/email
|
|
|
|
[ -z "${PACKAGER_NAME}" ] && PACKAGER_NAME="${DEFAULT_PACKAGER_NAME}" && PACKAGER_EMAIL="${DEFAULT_PACKAGER_EMAIL}"
|
|
|
|
if [ -z "${PACKAGER_EMAIL}" ]; then
|
|
|
|
echo >&2 "ERROR: PACKAGER_EMAIL must be set if PACKAGER_NAME is set."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# simultaneous jobs for compilation (dpkg-buildpackage -jN)
|
|
|
|
[ -z "${JOBS}" ] && JOBS="${DEFAULT_JOBS}"
|
|
|
|
|
|
|
|
# check git repository
|
|
|
|
ROOT_DIR=$(git rev-parse --show-toplevel)
|
2019-11-28 21:23:59 +01:00
|
|
|
if [ -z "${ROOT_DIR}" ] || [ ! -d "${ROOT_DIR}/.git" ] || [ ! -d "${ROOT_DIR}/debian-stable" ]; then
|
2015-10-24 12:55:13 +02:00
|
|
|
error "this script must be run from WeeChat git repository."
|
|
|
|
fi
|
|
|
|
cd "${ROOT_DIR}"
|
|
|
|
|
|
|
|
# check command line arguments
|
2016-04-01 07:44:35 +02:00
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
usage 0
|
|
|
|
fi
|
2018-03-20 22:09:20 +01:00
|
|
|
if [ "$1" = "test-patches" ]; then
|
|
|
|
test_patches
|
|
|
|
exit 0
|
|
|
|
fi
|
2015-10-24 12:55:13 +02:00
|
|
|
if [ $# -lt 2 ]; then
|
|
|
|
error_usage "missing arguments"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# command line arguments
|
|
|
|
VERSION="$1"
|
|
|
|
DISTRO="$2"
|
|
|
|
|
|
|
|
# separate version and revision
|
2017-09-28 01:54:53 +02:00
|
|
|
# example: devel => devel / 1, stable-2 => stable / 2, 1.9-2 => 1.9 / 2
|
2015-10-24 12:55:13 +02:00
|
|
|
TMP_VERSION=$(expr "${VERSION}" : '\([^/]*\)-') || true
|
|
|
|
DEB_REVISION=""
|
2019-11-28 21:27:43 +01:00
|
|
|
if [ -n "${TMP_VERSION}" ]; then
|
2015-10-24 12:55:13 +02:00
|
|
|
DEB_REVISION=$(expr "${VERSION}" : '[^-]*-\([^-]*\)') || true
|
|
|
|
VERSION="${TMP_VERSION}"
|
|
|
|
fi
|
|
|
|
if [ -z "${DEB_REVISION}" ]; then
|
|
|
|
DEB_REVISION="1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# convert version "stable" to its number
|
|
|
|
if [ "${VERSION}" = "stable" ]; then
|
2019-11-28 21:23:59 +01:00
|
|
|
VERSION="$("${ROOT_DIR}/version.sh" stable)"
|
2015-10-24 12:55:13 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${VERSION}" ]; then
|
|
|
|
error_usage "unknown version"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# extract distro type (debian, ubuntu, ...)
|
|
|
|
DISTRO_TYPE=$(expr "${DISTRO}" : '\([^/]*\)/') || true
|
|
|
|
|
|
|
|
# extract distro name (sid, jessie, wily, ...)
|
|
|
|
DISTRO_NAME=$(expr "${DISTRO}" : '[^/]*/\([a-z]*\)') || true
|
|
|
|
|
2019-11-28 21:26:45 +01:00
|
|
|
if [ -z "${DISTRO_TYPE}" ] || [ -z "${DISTRO_NAME}" ]; then
|
2015-10-24 12:55:13 +02:00
|
|
|
error_usage "missing distro type/name"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# set distro for dch
|
2016-05-16 14:23:32 +02:00
|
|
|
if [ "${DISTRO_TYPE}" = "ubuntu" ]; then
|
|
|
|
# ubuntu
|
2015-10-24 12:55:13 +02:00
|
|
|
if [ "${VERSION}" = "devel" ]; then
|
|
|
|
DCH_DISTRO="UNRELEASED"
|
|
|
|
else
|
|
|
|
DCH_DISTRO="${DISTRO_NAME}"
|
|
|
|
fi
|
2016-05-16 14:23:32 +02:00
|
|
|
else
|
|
|
|
# debian/raspbian
|
|
|
|
DCH_DISTRO="unstable"
|
2015-10-24 12:55:13 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${VERSION}" = "devel" ]; then
|
2016-10-23 08:37:31 +02:00
|
|
|
# devel packages: weechat-devel(-xxx)_X.Y-1~dev20150511_arch.deb
|
2015-10-24 12:55:13 +02:00
|
|
|
DEB_DIR="debian-devel"
|
|
|
|
DEB_NAME="weechat-devel"
|
2019-11-28 21:23:59 +01:00
|
|
|
DEB_VERSION="$("${ROOT_DIR}/version.sh" devel)-1~dev$(date '+%Y%m%d')"
|
2015-10-24 12:55:13 +02:00
|
|
|
if [ "${DEB_REVISION}" != "1" ]; then
|
|
|
|
DEB_VERSION="${DEB_VERSION}-${DEB_REVISION}"
|
|
|
|
fi
|
|
|
|
DCH_CREATE="--create"
|
|
|
|
DCH_URGENCY="low"
|
|
|
|
DCH_CHANGELOG="Repository snapshot"
|
|
|
|
else
|
2016-10-23 08:37:31 +02:00
|
|
|
# stable packages: weechat-(-xxx)_X.Y-1_arch.deb
|
2015-10-24 12:55:13 +02:00
|
|
|
DEB_DIR="debian-stable"
|
|
|
|
DEB_NAME="weechat"
|
|
|
|
DEB_VERSION="${VERSION}-${DEB_REVISION}"
|
|
|
|
DCH_CREATE=""
|
|
|
|
DCH_URGENCY="medium"
|
|
|
|
DCH_CHANGELOG="New upstream release"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# display build info
|
|
|
|
echo "=== Building ${DEB_NAME}-${DEB_VERSION} on ${DISTRO_TYPE}/${DISTRO_NAME} (${DCH_DISTRO}) ==="
|
|
|
|
|
|
|
|
# ================================== BUILD ==================================
|
|
|
|
|
|
|
|
# apply patch (if needed, for old distros)
|
|
|
|
PATCH_FILE="${ROOT_DIR}/tools/debian/patches/weechat_${DISTRO_TYPE}_${DISTRO_NAME}.patch"
|
|
|
|
if [ -f "${PATCH_FILE}" ]; then
|
|
|
|
echo " - Applying patch ${PATCH_FILE}"
|
|
|
|
git apply "${PATCH_FILE}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# create a symlink "debian" -> "debian-{stable|devel}"
|
|
|
|
rm -f debian
|
|
|
|
ln -s -f "${DEB_DIR}" debian
|
|
|
|
|
|
|
|
# update debian changelog
|
|
|
|
if [ "${VERSION}" = "devel" ]; then
|
|
|
|
rm -f "${DEB_DIR}/changelog"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# create/update changelog
|
|
|
|
echo " - Updating changelog: ${DEB_NAME} ${DEB_VERSION} (${DCH_DISTRO}, ${DCH_URGENCY}), ${PACKAGER_NAME} <${PACKAGER_EMAIL}>: ${DCH_CHANGELOG}"
|
|
|
|
DEBFULLNAME="${PACKAGER_NAME}" DEBEMAIL="${PACKAGER_EMAIL}" dch "${DCH_CREATE}" --package "${DEB_NAME}" --newversion "${DEB_VERSION}" --distribution "${DCH_DISTRO}" --urgency "${DCH_URGENCY}" "${DCH_CHANGELOG}"
|
|
|
|
|
2018-03-21 22:25:17 +01:00
|
|
|
# build packages (without debug symbols)
|
|
|
|
DEB_BUILD_OPTIONS="noddebs" dpkg-buildpackage -us -uc -j${JOBS} --source-option="--tar-ignore=.git" --source-option="--tar-ignore=build*"
|
2015-10-24 12:55:13 +02:00
|
|
|
|
|
|
|
# all OK!
|
|
|
|
echo " - Build OK [${DEB_NAME}-${DEB_VERSION}]"
|
|
|
|
exit 0
|