From 550ad72f93232e40c1f35b6445b5a5cba9057e18 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Thu, 13 Dec 2018 23:28:04 -0500 Subject: [PATCH 1/5] Add Debian package build script for docker --- build-deb.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 build-deb.sh diff --git a/build-deb.sh b/build-deb.sh new file mode 100755 index 000000000..43c5d2027 --- /dev/null +++ b/build-deb.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Build a Jellyfin .deb file with Docker on Linux +# Places the output .deb file in the parent directory + +set -o xtrace +set -o errexit +set -o pipefail +set -o nounset + +date="$( date +%s )" +curdir="$( pwd )" +tmpdir="$( mktemp -d )" +curuser="$( whoami )" + +docker build ${curdir} --tag jellyfin-debuild-${date} --file ${curdir}/Dockerfile.debian_package +docker run --volume ${tmpdir}:/temp --interactive --tty jellyfin-debuild-${date} cp --recursive /dist /temp/ +docker image rm jellyfin-debuild-${date} --force +sudo chown --recursive ${curuser} ${tmpdir} +mv ${tmpdir}/dist/*.deb ${curdir}/../ +rm --recursive --force ${tmpdir} From f3ba806e4a391036bb8e321ba859b573afb6d3e1 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Fri, 14 Dec 2018 00:57:50 -0500 Subject: [PATCH 2/5] Major script cleanups based on feedback --- build-deb.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/build-deb.sh b/build-deb.sh index 43c5d2027..a85725708 100755 --- a/build-deb.sh +++ b/build-deb.sh @@ -1,21 +1,23 @@ -#!/bin/bash +#!/usr/bin/env sh # Build a Jellyfin .deb file with Docker on Linux # Places the output .deb file in the parent directory set -o xtrace set -o errexit -set -o pipefail set -o nounset -date="$( date +%s )" -curdir="$( pwd )" -tmpdir="$( mktemp -d )" -curuser="$( whoami )" +package_temporary_dir="`mktemp -d`" +current_user="`whoami`" +image_name="jellyfin-debuild" -docker build ${curdir} --tag jellyfin-debuild-${date} --file ${curdir}/Dockerfile.debian_package -docker run --volume ${tmpdir}:/temp --interactive --tty jellyfin-debuild-${date} cp --recursive /dist /temp/ -docker image rm jellyfin-debuild-${date} --force -sudo chown --recursive ${curuser} ${tmpdir} -mv ${tmpdir}/dist/*.deb ${curdir}/../ -rm --recursive --force ${tmpdir} +cleanup() { + docker image rm $image_name --force + test -d ${package_temporary_dir} && rm -r ${package_temporary_dir} +} +trap cleanup EXIT + +docker build . -t $image_name -f ./Dockerfile.debian_package +docker run --rm -v $package_temporary_dir:/temp $image_name cp -r /dist /temp/ +sudo chown -R $current_user $package_temporary_dir +mv $package_temporary_dir/dist/*.deb ../ From 26e44854f6914474153dfb3e1f43cec4e06195c3 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Fri, 14 Dec 2018 13:47:04 -0500 Subject: [PATCH 3/5] Add quoting and consistent variable calls --- build-deb.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build-deb.sh b/build-deb.sh index a85725708..ec7c7d128 100755 --- a/build-deb.sh +++ b/build-deb.sh @@ -13,11 +13,11 @@ image_name="jellyfin-debuild" cleanup() { docker image rm $image_name --force - test -d ${package_temporary_dir} && rm -r ${package_temporary_dir} + test -d "$package_temporary_dir" && rm -r "$package_temporary_dir" } trap cleanup EXIT -docker build . -t $image_name -f ./Dockerfile.debian_package -docker run --rm -v $package_temporary_dir:/temp $image_name cp -r /dist /temp/ -sudo chown -R $current_user $package_temporary_dir -mv $package_temporary_dir/dist/*.deb ../ +docker build . -t "$image_name" -f ./Dockerfile.debian_package +docker run --rm -v "$package_temporary_dir:/temp" "$image_name" cp -r /dist /temp/ +sudo chown -R "$current_user" "$package_temporary_dir" +mv "$package_temporary_dir"/dist/*.deb ../ From a7cdab9ae352ac8afae6b4b153f3c99a07075646 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Fri, 14 Dec 2018 18:43:50 -0500 Subject: [PATCH 4/5] Remove errexit and cleanup on INT too --- build-deb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-deb.sh b/build-deb.sh index ec7c7d128..c61d1e7ad 100755 --- a/build-deb.sh +++ b/build-deb.sh @@ -4,7 +4,6 @@ # Places the output .deb file in the parent directory set -o xtrace -set -o errexit set -o nounset package_temporary_dir="`mktemp -d`" @@ -16,6 +15,7 @@ cleanup() { test -d "$package_temporary_dir" && rm -r "$package_temporary_dir" } trap cleanup EXIT +trap cleanup INT docker build . -t "$image_name" -f ./Dockerfile.debian_package docker run --rm -v "$package_temporary_dir:/temp" "$image_name" cp -r /dist /temp/ From 0fec8f64931b62789be7e266ade52a8e200ea9dd Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Fri, 14 Dec 2018 18:57:12 -0500 Subject: [PATCH 5/5] Don't use errexit, explicitly exit on failures --- build-deb.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/build-deb.sh b/build-deb.sh index c61d1e7ad..8d701910d 100755 --- a/build-deb.sh +++ b/build-deb.sh @@ -14,10 +14,9 @@ cleanup() { docker image rm $image_name --force test -d "$package_temporary_dir" && rm -r "$package_temporary_dir" } -trap cleanup EXIT -trap cleanup INT +trap cleanup EXIT INT -docker build . -t "$image_name" -f ./Dockerfile.debian_package -docker run --rm -v "$package_temporary_dir:/temp" "$image_name" cp -r /dist /temp/ -sudo chown -R "$current_user" "$package_temporary_dir" -mv "$package_temporary_dir"/dist/*.deb ../ +docker build . -t "$image_name" -f ./Dockerfile.debian_package || exit 1 +docker run --rm -v "$package_temporary_dir:/temp" "$image_name" cp -r /dist /temp/ || exit 1 +sudo chown -R "$current_user" "$package_temporary_dir" || exit 1 +mv "$package_temporary_dir"/dist/*.deb ../ || exit 1