-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include doc and manpage in Debian package. #112
base: master
Are you sure you want to change the base?
Changes from all commits
00af923
b507d53
cf38f65
f1e6fd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
quicktile (0.4.0gtk3-1) UNRELEASED; urgency=medium | ||
quicktile (0.4-1) UNRELEASED; urgency=medium | ||
|
||
* First Debian package. | ||
|
||
-- Stéphane Gourichon <stephane.gourichon@fidergo.fr> Wed, 01 Jan 2020 17:57:34 +0100 | ||
-- Stéphane Gourichon <stephane.gourichon@fidergo.fr> Tue, 11 Feb 2020 18:04:27 +0100 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
quicktile | ||
docs/_build/html | ||
README.rst |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docs/_build/man/quicktile.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ cat <<EOF | |
One-step Debian package generation script. | ||
======================================================================== | ||
|
||
This script takes a git-version-controlled tree hierarchy containing | ||
a proper debian/ directory for package generation, does a temporary | ||
This script takes a git-version-controlled tree hierarchy containing a | ||
proper 'debian/' directory for package generation, does a temporary | ||
clone and builds debian packages from it. | ||
|
||
Added value : | ||
|
@@ -23,73 +23,246 @@ Written by Stéphane Gourichon <stephane_dpkg@gourichon.org> | |
|
||
======================================================================== | ||
|
||
Let's go! | ||
|
||
|
||
EOF | ||
|
||
set -euo pipefail | ||
|
||
cd "$(dirname "$(readlink -f "$0")" )" | ||
cd "$(dirname "$0" )" | ||
PKGDIR="$PWD" | ||
|
||
dpkg-checkbuilddeps | ||
echo -e "* dpkg-checkbuilddeps\tPASSED" | ||
# necessary for install_package_if_missing and build_locally | ||
BECOMEROOT="" | ||
if [[ "$(id -u)" != "0" ]] ; then BECOMEROOT="sudo" ; fi | ||
|
||
PKGDIR="$PWD" | ||
APT_COMMAND_LINE="apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y" | ||
|
||
TMPDIR=$( mktemp -d ) && echo "* Will work in temp dir $TMPDIR" | ||
function install_package_if_missing() | ||
{ | ||
local PKGTOINSTALL | ||
PKGTOINSTALL=() | ||
for PKGNAME | ||
do | ||
if ! dpkg-query -W -f'${Status}' "$PKGNAME" 2>/dev/null | grep -q "ok installed" | ||
then | ||
PKGTOINSTALL+=( "$PKGNAME" ) | ||
echo "Scheduling to install $PKGNAME" | ||
fi | ||
done | ||
|
||
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) && echo "* Current git branch $CURRENT_BRANCH" | ||
if [[ "${#PKGTOINSTALL[@]}" = "0" ]] | ||
then | ||
return 0 | ||
fi | ||
|
||
NAMEFORTAR="$( head -n 1 debian/changelog | sed -n 's/^\([^ ]*\)* (\([^-]*\)-[0-9]*).*$/\1_\2/p' )" | ||
DIRNAMEFORDEB=${NAMEFORTAR//_/-} | ||
echo will install "${#PKGTOINSTALL[@]}" | ||
printf "* %s\n" "${PKGTOINSTALL[@]}" | ||
|
||
if [[ -z "$NAMEFORTAR" ]] | ||
then | ||
echo >&2 "Cannot figure out tar archive name from first line of debian/changelog. Aborting" | ||
head -n 1 debian/changelog | ||
exit 1 | ||
fi | ||
if [[ -z "${DID_APT_GET_UPDATE:-}" ]] | ||
then | ||
${BECOMEROOT:-} apt-get update | ||
fi | ||
|
||
if output=$(git status --porcelain) && [ -z "$output" ]; then | ||
echo "Working directory clean" | ||
else | ||
echo >&2 "WARNING: uncommitted changes. Consider aborting." | ||
git status | ||
echo >&2 "WARNING: uncommitted changes. Consider aborting." | ||
echo >&2 "Waiting for 10 second." | ||
sleep 10 | ||
fi | ||
# shellcheck disable=SC2086 | ||
# APT_COMMAND_LINE intentionally contains space-separated arguments | ||
${BECOMEROOT:-} $APT_COMMAND_LINE install "${PKGTOINSTALL[@]}" | ||
} | ||
|
||
function build_locally() | ||
{ | ||
TMPDIR=$( mktemp -d ) && echo "* Will work in temp dir $TMPDIR" | ||
|
||
if | ||
[[ "${no_cleanup:-}" == "rue" ]] | ||
then | ||
# shellcheck disable=SC2064 | ||
# TMPDIR is indeed intended to be expanded at the time this line is executed, not at trap time. | ||
trap "echo rm -rf ${TMPDIR:?}" EXIT | ||
fi | ||
|
||
install_package_if_missing dpkg-dev git | ||
|
||
pwd | ||
|
||
if dpkg-checkbuilddeps 2>/dev/null | ||
then | ||
echo -e "* dpkg-checkbuilddeps\tPASSED" | ||
else | ||
echo -e "* dpkg-checkbuilddeps asks for more packages" | ||
install_package_if_missing equivs devscripts | ||
( cd "$TMPDIR" ; \ | ||
mk-build-deps -i -t "$APT_COMMAND_LINE" \ | ||
"$PKGDIR/debian/control" \ | ||
-s "${BECOMEROOT:-}" ; | ||
) | ||
echo -e "* dpkg-checkbuilddeps\tPASSED" | ||
fi | ||
|
||
if [[ "${1:-}" == "deps_only" ]] | ||
# if [[ "${local_install_deps_only:-}" == "true" ]] | ||
then | ||
echo "Install-only pass, returning now." | ||
return 0 | ||
fi | ||
|
||
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) && echo "* Current git branch $CURRENT_BRANCH" | ||
|
||
NAMEFORTAR="$( head -n 1 debian/changelog | sed -n 's/^\([^ ]*\)* (\([^)]*\)).*$/\1_\2/p' )" | ||
DIRNAMEFORDEB=${NAMEFORTAR//_/-} | ||
|
||
if [[ -z "$NAMEFORTAR" ]] | ||
then | ||
echo >&2 "Cannot figure out tar archive name from first line of debian/changelog. Aborting" | ||
head -n 1 debian/changelog | ||
exit 1 | ||
fi | ||
|
||
if output=$(git status --porcelain) && [ -z "$output" ]; then | ||
echo "Working directory clean" | ||
else | ||
echo >&2 "WARNING: uncommitted changes. Consider aborting." | ||
git status | ||
echo >&2 "WARNING: uncommitted changes. Consider aborting." | ||
echo >&2 "Waiting for 10 second." | ||
#sleep 10 | ||
fi | ||
|
||
GITREV=$( git describe ) | ||
|
||
cd "$TMPDIR" | ||
git clone "$PKGDIR" "${DIRNAMEFORDEB}" | ||
|
||
tar zcf "${NAMEFORTAR}.orig.tar.gz" "${DIRNAMEFORDEB}" | ||
cd "${DIRNAMEFORDEB}" | ||
|
||
GITREV=$( git describe ) | ||
dpkg-checkbuilddeps | ||
debuild -us -uc | ||
|
||
cd "$TMPDIR" | ||
git clone "$PKGDIR" "${DIRNAMEFORDEB}" | ||
. /etc/os-release ; DISTRO_ID="${ID}-${VERSION_ID}" | ||
|
||
tar zcvf ${NAMEFORTAR}.orig.tar.gz "${DIRNAMEFORDEB}" | ||
cd "${DIRNAMEFORDEB}" | ||
OUTDIR="$PKGDIR/../compiled_packages/${DISTRO_ID}/${NAMEFORTAR}" #_$( date +%Yy%mm%dd_%Hh%Mm%Ss )" | ||
|
||
dpkg-checkbuilddeps | ||
debuild -us -uc | ||
mkdir -p "$OUTDIR" | ||
|
||
. /etc/os-release ; DISTRO_ID="${ID}-${VERSION_ID}" | ||
echo "generated from git commit $GITREV" >"${OUTDIR}/${NAMEFORTAR}.gitversion" | ||
|
||
OUTDIR="$PKGDIR/../compiled_packages/${DISTRO_ID}/${NAMEFORTAR}" #_$( date +%Yy%mm%dd_%Hh%Mm%Ss )" | ||
cd .. | ||
|
||
mkdir -p "$OUTDIR" | ||
cp -v "${NAMEFORTAR}"?* "$OUTDIR" | ||
|
||
echo "generated from git commit $GITREV" >"${OUTDIR}/${NAMEFORTAR}.gitversion" | ||
echo | ||
echo ================================================================ | ||
echo "Artifacts available in $OUTDIR:" | ||
echo "OUTDIR=$OUTDIR" | ||
echo ================================================================ | ||
|
||
cd .. | ||
cd "$OUTDIR" | ||
|
||
ls -al | ||
} | ||
|
||
function build_in_docker() | ||
{ | ||
OSIMAGE="$1" | ||
|
||
# By default, files generated in Docker have same owner as user inside docker. | ||
# So, let's make sure there is a matching user inside the docker container. | ||
|
||
docker run -it -v "$PKGDIR/..":/up "$OSIMAGE" \ | ||
bash -c " | ||
cd /up/*/debian/source ; cd ../.. | ||
bash recompile_local_debian_package.sh --install-deps-only | ||
USER=$(id -un) ; userdel \"\$USER\" | ||
GID=$(id -g) ; groupadd -f -g \$GID $(id -gn) | ||
useradd -u $(id -u) --gid stephane -l -m \"\$USER\" -s /bin/bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops! Of course this is unacceptable for published software. Probably a local expedient that I forgot to refine. |
||
grep -H stephane /etc/*passwd | ||
grep -H stephane /etc/*group | ||
set -xv ; su - \$USER -- \$PWD/recompile_local_debian_package.sh --local | ||
" | ||
} | ||
|
||
function usage() | ||
{ | ||
cat <<EOF | ||
------------------------------------------------------------------------ | ||
Usage: | ||
|
||
To compile a package for your local distribution (will prompt for root if needed): | ||
|
||
recompile_local_debian_package.sh --local | ||
|
||
This separates the step needing root and the step not needing root: | ||
|
||
recompile_local_debian_package.sh --install-deps-only | ||
recompile_local_debian_package.sh --local | ||
|
||
|
||
To compile a package for any Debian-based distribution available through Docker: | ||
|
||
recompile_local_debian_package.sh --docker <image_id> | ||
|
||
In practice, Debian hosts can create Debian packages, Ubuntu hosts can create Ubuntu and Debian package. | ||
|
||
------------------------------------------------------------------------ | ||
EOF | ||
} | ||
|
||
if [[ "$#" == 0 ]] | ||
then | ||
echo -e >&2 "No argument provided. Exiting.\n" | ||
usage | ||
exit 1 | ||
fi | ||
|
||
cp -v "${NAMEFORTAR}"?* "$OUTDIR" | ||
while [[ "$#" -gt 0 ]] | ||
do | ||
ARG="$1" | ||
shift | ||
|
||
echo | ||
echo ================================================================ | ||
echo "Artifacts available in $OUTDIR:" | ||
echo "OUTDIR=$OUTDIR" | ||
echo ================================================================ | ||
case "$ARG" in | ||
--no-cleanup) | ||
# Generic code for option handling | ||
ARGSHORT="${ARG#--}" | ||
ARGSHORT="${ARGSHORT//-/_}" | ||
declare -n ARGVAR="${ARGSHORT}" | ||
VALUE=true | ||
echo "Seeing option: $ARG to $VALUE" | ||
|
||
cd "$OUTDIR" | ||
# The line below actually sets a variable named from the | ||
# option, e.g. "ARGVAR=$VALUE" does "no_cleanup=true" due | ||
# to the feature "nameref attribute" of bash, enabled by | ||
# "declare -n" above. | ||
# | ||
# Therefore: | ||
# | ||
# shellcheck disable=SC2034 | ||
ARGVAR=$VALUE | ||
unset ARGVAR | ||
;; | ||
--install-deps-only) | ||
build_locally deps_only | ||
;; | ||
--local) | ||
build_locally | ||
;; | ||
--docker) | ||
OSIMAGE="${1:-}" | ||
if [[ -z "$OSIMAGE" ]] | ||
then | ||
. /etc/os-release ; DISTRO_ID="${ID}:${VERSION_ID}" | ||
echo -e >&2 "--docker argument needs a parameter.\n" \ | ||
"Please provide a docker base image name for the target OS of your \n" \ | ||
"build package.\nExample: --docker ${ID}:${VERSION_ID}" | ||
exit 1 | ||
fi | ||
shift | ||
build_in_docker "$OSIMAGE" | ||
;; | ||
*) | ||
echo >&2 "Error: unknown option $ARG" | ||
usage | ||
exit 1 | ||
esac | ||
done | ||
|
||
ls -al | ||
exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a specific example of why this change is necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh. I'm not used to GitHub's reviews. I'll have to remember to mark the last line rather than the first next time.