Implement snap packaging, snaps are universal linux packages (#170)

This patch implements the necessary details to package gallery-dl as a snap that can be run on a broad range of supporting GNU/Linux distributions[1].

[1] https://snapcraft.io/

Signed-off-by: 林博仁(Buo-ren Lin) <Buo.Ren.Lin@gmail.com>
This commit is contained in:
林博仁(Buo-ren Lin)
2019-03-01 21:12:41 +08:00
committed by Mike Fährmann
parent a138d5873d
commit 77551bf01b
4 changed files with 206 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
#!/usr/bin/env bash
# This is the maintainence launcher for the snap, make necessary runtime environment changes to make the snap work here. You may also insert security confinement/deprecation/obsoletion notice of the snap here.
set \
-o errexit \
-o errtrace \
-o nounset \
-o pipefail
if ! test -v SNAP_ARCH_TRIPLET; then
printf 'Error: SNAP_ARCH_TRIPLET not set, this launcher requires workaround-snap-arch-triplet-launch launcher to work.\n' >&2
exit 1
fi
# Satisfy FFmpeg's usr/lib/ARCH/pulseaudio/libpulsecommon-11.1.so dependency
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}":"$SNAP"/usr/lib/"${SNAP_ARCH_TRIPLET}"/pulseaudio
# Use user's real home directory for canonical configuration path access
# FIXME: Waiting for Snap Store assertion
declare REALHOME="$(
getent passwd "${USER}" \
| cut --delimiter=: --fields=6
)"
if ! test -f "${SNAP_USER_COMMON}"/.config/gallery-dl/config.json \
&& ! test -f "${SNAP_USER_COMMON}"/.gallery-dl.conf; then
declare userwide_config_file
for possible_config_file in \
"${REALHOME}"/.config/gallery-dl/config.json \
"${REALHOME}"/.gallery-dl.conf; do
if test -f "${possible_config_file}"; then
userwide_config_file="${possible_config_file}"
fi
done
if test -v userwide_config_file; then
printf -- \
'gallery-dl-launch: It appears that you have a gallery-dl configuration in your home directory, currently the snap distribution of gallery-dl cannot access it until you create a link via running the following command in the terminal:\n\n'
printf -- \
'gallery-dl-launch: ln %s %s\n\n' \
"${userwide_config_file}" \
"~/snap/$SNAP_NAME/common/.gallery-dl.conf"
fi
fi
#HOME="${REALHOME}"
# Finally run the next part of the command chain
exec "${@}"

View File

@@ -0,0 +1,55 @@
#!/usr/bin/env bash
# This launcher sets the Debian-specific multiarch tuples as the SNAP_ARCH_TRIPLET environmental variable for other launchers' ease
set \
-o errexit \
-o errtrace \
-o nounset \
-o pipefail
if ! test -v SNAP_ARCH; then
printf -- \
'%s: Error: This launcher requires SNAP_ARCH environmental variable to be set and exported.\n' \
"$(basename "${BASH_SOURCE[0]}")"
exit 1
fi
declare \
SNAP_ARCH_TRIPLET
# Refer:
#
# * Environmental variables - doc - snapcraft.io
# https://forum.snapcraft.io/t/environmental-variables/7983
# * Multiarch/Tuples - Debian Wiki
# https://wiki.debian.org/Multiarch/Tuples
# NOTE: Only consider Linux archs with the `released` status in Debian for now
case "${SNAP_ARCH}" in
# These are the special cases
amd64)
SNAP_ARCH_TRIPLET=x86_64-linux-gnu
;;
armel)
SNAP_ARCH_TRIPLET=arm-linux-gnueabi
;;
armhf)
SNAP_ARCH_TRIPLET=arm-linux-gnueabihf
;;
arm64)
SNAP_ARCH_TRIPLET=aarch64-linux-gnu
;;
ppc64el)
SNAP_ARCH_TRIPLET=powerpc64le-linux-gnu
;;
# Consider rest of them not exceptions
s390x \
|*)
SNAP_ARCH_TRIPLET="${SNAP_ARCH}"-linux-gnu
;;
esac
export \
SNAP_ARCH_TRIPLET
# Finally run the launching command
exec "${@}"