From b52a1ef08e47377373f688a7f4a0b3fbae6f913c Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Wed, 26 Oct 2022 19:35:23 -0400 Subject: [PATCH] Added script to build deb package --- bin/build_deb.sh | 44 ++++++++++++++++++++++++++++++++++++++ bin/build_rpm.sh | 44 ++++++++++++++++++++++++++++++++++++++ build/etc/adept/adept.toml | 4 ++-- build/scripts/postinst | 36 +++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 2 deletions(-) create mode 100755 bin/build_deb.sh create mode 100755 bin/build_rpm.sh create mode 100755 build/scripts/postinst diff --git a/bin/build_deb.sh b/bin/build_deb.sh new file mode 100755 index 0000000..d4c18c7 --- /dev/null +++ b/bin/build_deb.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Check that we've been supplied a valid version +VERSION="$1" +if [ "$VERSION" == "" ]; then + echo -e "You must supply a version tag like './build_deb.sh 1.2.3'." + exit 1 +fi +# Trim the leading 'v' from version number +if [[ "${VERSION:0:1}" == "v" ]]; then + VERSION="${VERSION:1}" +fi + +# Create workspace for our deb package +WORKDIR="adept_$VERSION" +mkdir "$WORKDIR" + +# Copy build sources into workspace +cp -r build/etc "$WORKDIR/" +mkdir -p "$WORKDIR/usr/bin/" +cp "dist/adept-linux-amd64-v$VERSION" "$WORKDIR/usr/bin/adept" + +# Create debian control file +mkdir "$WORKDIR/DEBIAN" +cat > "$WORKDIR/DEBIAN/control"<< EOF +Package: adept +Version: $VERSION +Section: video +Priority: optional +Architecture: amd64 +Depends: ffmpeg (>= 4), lsof +Maintainer: Gregory Ballantine +Description: Bit Goblin video transcoding service. +EOF +# Copy maintainer scripts +cp build/scripts/* "$WORKDIR/DEBIAN/" +#chmod +rx "$WORKDIR"/DEBIAN/pre* +chmod +rx "$WORKDIR"/DEBIAN/post* + +# Build deb package! +dpkg-deb --build "$WORKDIR" + +# Cleanup +rm -rf "$WORKDIR" diff --git a/bin/build_rpm.sh b/bin/build_rpm.sh new file mode 100755 index 0000000..4607282 --- /dev/null +++ b/bin/build_rpm.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Check that we've been supplied a valid version +VERSION="$1" +if [ "$VERSION" == "" ]; then + echo -e "You must supply a version tag like './build_rpm.sh 1.2.3'." + exit 1 +fi +# Trim the leading 'v' from version number +if [[ "${VERSION:0:1}" == "v" ]]; then + VERSION="${VERSION:1}" +fi + +# Create workspace for our deb package +WORKDIR="adept_$VERSION" +mkdir "$WORKDIR" + +# Copy build sources into workspace +cp -r build/etc "$WORKDIR/" +mkdir -p "$WORKDIR/usr/bin/" +cp "dist/adept-linux-amd64-v$VERSION" "$WORKDIR/usr/bin/adept" + +# Create debian control file +mkdir "$WORKDIR/DEBIAN" +cat > "$WORKDIR/DEBIAN/control"<< EOF +Package: adept +Version: $VERSION +Section: video +Priority: optional +Architecture: amd64 +Depends: ffmpeg (>= 4), lsof +Maintainer: Gregory Ballantine +Description: Bit Goblin video transcoding service. +EOF +# Copy maintainer scripts +cp build/scripts/* "$WORKDIR/DEBIAN/" +#chmod +rx "$WORKDIR"/DEBIAN/pre* +chmod +rx "$WORKDIR"/DEBIAN/post* + +# Build deb package! +dpkg-deb --build "$WORKDIR" + +# Cleanup +rm -rf "$WORKDIR" diff --git a/build/etc/adept/adept.toml b/build/etc/adept/adept.toml index c6ec24d..f42f6b5 100644 --- a/build/etc/adept/adept.toml +++ b/build/etc/adept/adept.toml @@ -1,9 +1,9 @@ log_to_file = true -log_file = '~/adept/adept.log' +log_file = '/var/log/adept/adept.log' log_level = 'info' [transcoder] -repository = '~/adept' +repository = '/srv/adept' interval = 15 video_format = 'mov' video_codec = 'dnxhd' diff --git a/build/scripts/postinst b/build/scripts/postinst new file mode 100755 index 0000000..c6bcedc --- /dev/null +++ b/build/scripts/postinst @@ -0,0 +1,36 @@ +#!/bin/sh + +GETENT_USER=$(getent passwd adept) +# Create the adept user if it doesn't already exist +if [ "$GETENT_USER" = "" ]; then + echo "Creating the 'adept' user." + useradd -r adept +else + echo "The 'adept' user already exists, skipping creation." +fi + +GETENT_GROUP=$(getent group adept) +# Create the adept group if it doesn't already exist +if [ "$GETENT_GROUP" = "" ]; then + echo "Creating the 'adept' group." + groupadd adept + usermod -aG adept adept +else + echo "The 'adept' group already exists, skipping creation." +fi + +# Change the directory ownership of /etc +chown -R adept:adept /etc/adept + +# Create the log directory under /var/log +if [ ! -d /var/log/adept ]; then + echo "Creating /var/log/adept to store log files." + mkdir /var/log/adept + chown adept:adept /var/log/adept +else + echo "/var/log/adept already exists, skipping creation." +fi + +#DEBHELPER# + +exit 0