Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions debian/changelog
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 <[email protected]> Wed, 01 Jan 2020 17:57:34 +0100
-- Stéphane Gourichon <[email protected]> Tue, 11 Feb 2020 18:04:27 +0100
3 changes: 2 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Build-Depends: debhelper (>= 9),
python3-dbus,
gir1.2-gtk-3.0,
gir1.2-wnck-3.0,
gir1.2-glib-2.0
gir1.2-glib-2.0,
python3-sphinx
Standards-Version: 4.4.0

Package: quicktile
Expand Down
3 changes: 2 additions & 1 deletion debian/docs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
quicktile
docs/_build/html
README.rst
1 change: 1 addition & 0 deletions debian/manpages
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs/_build/man/quicktile.1
10 changes: 10 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ include /usr/share/dpkg/default.mk
override_dh_auto_install:
dh_auto_install
install -D quicktile.desktop debian/quicktile/etc/xdg/autostart/quicktile.desktop

override_dh_installdocs:
pip3 install --user sphinx_autodoc_typehints sphinxcontrib.autoprogram
( cd docs ; env PATH=$$HOME/.local/bin/:$$PATH make html ; )
dh_installdocs

override_dh_installman:
pip3 install --user sphinx_autodoc_typehints sphinxcontrib.autoprogram
( cd docs ; env PATH=$$HOME/.local/bin/:$$PATH make man ; )
dh_installman
267 changes: 220 additions & 47 deletions recompile_local_debian_package.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand All @@ -23,73 +23,246 @@ Written by Stéphane Gourichon <[email protected]>

========================================================================

Let's go!


EOF

set -euo pipefail

cd "$(dirname "$(readlink -f "$0")" )"
Copy link
Owner

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?

Copy link
Owner

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.

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
Copy link
Owner

@ssokolow ssokolow Nov 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be stephane, but I'm ssokolow and have no such user and group on my system. It looks like you're either missing username and group lookups here or should use names that make it more clear that all that matters is matching the external UID and GID.

Choose a reason for hiding this comment

The 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