Debian package builder

This commit is contained in:
Mark Cooper 2021-09-24 19:37:35 -05:00
parent 3ef0173226
commit e161f70710
7 changed files with 143 additions and 4 deletions

View File

@ -0,0 +1 @@
/etc/default/audiobookshelf

View File

@ -0,0 +1,8 @@
Package: audiobookshelf
Version: 1.2.1
Section: base
Priority: optional
Architecture: amd64
Depends:
Maintainer: advplyr
Description: Self-hosted audiobook server for managing and playing audiobooks

View File

@ -0,0 +1,84 @@
#!/bin/bash
set -e
set -o pipefail
declare -r init_type='auto'
declare -ri no_rebuild='0'
add_user() {
: "${1:?'User was not defined'}"
declare -r user="$1"
declare -r uid="$2"
if [ -z "$uid" ]; then
declare -r uid_flags=""
else
declare -r uid_flags="--uid $uid"
fi
declare -r group="${3:-$user}"
declare -r descr="${4:-No description}"
declare -r shell="${5:-/bin/false}"
if ! getent passwd | grep -q "^$user:"; then
echo "Creating system user: $user in $group with $descr and shell $shell"
useradd $uid_flags --gid $group --no-create-home --system --shell $shell -c "$descr" $user
fi
}
add_group() {
: "${1:?'Group was not defined'}"
declare -r group="$1"
declare -r gid="$2"
if [ -z "$gid" ]; then
declare -r gid_flags=""
else
declare -r gid_flags="--gid $gid"
fi
if ! getent group | grep -q "^$group:" ; then
echo "Creating system group: $group"
groupadd $gid_flags --system $group
fi
}
start_service () {
: "${1:?'Service name was not defined'}"
declare -r service_name="$1"
if hash systemctl 2> /dev/null; then
if [[ "$init_type" == 'auto' || "$init_type" == 'systemd' ]]; then
{
systemctl enable "$service_name.service" && \
systemctl start "$service_name.service"
} || echo "$service_name could not be registered or started"
fi
elif hash service 2> /dev/null; then
if [[ "$init_type" == 'auto' || "$init_type" == 'upstart' || "$init_type" == 'sysv' ]]; then
service "$service_name" start || echo "$service_name could not be registered or started"
fi
elif hash start 2> /dev/null; then
if [[ "$init_type" == 'auto' || "$init_type" == 'upstart' ]]; then
start "$service_name" || echo "$service_name could not be registered or started"
fi
elif hash update-rc.d 2> /dev/null; then
if [[ "$init_type" == 'auto' || "$init_type" == 'sysv' ]]; then
{
update-rc.d "$service_name" defaults && \
"/etc/init.d/$service_name" start
} || echo "$service_name could not be registered or started"
fi
else
echo 'Your system does not appear to use systemd, Upstart, or System V, so the service could not be started'
fi
}
add_group 'audiobookshelf' ''
add_user 'audiobookshelf' '' 'audiobookshelf' 'audiobookshelf user-daemon' '/bin/false'
mkdir -p '/var/log/audiobookshelf'
chown -R 'audiobookshelf:audiobookshelf' '/var/log/audiobookshelf'
start_service 'audiobookshelf'

26
build/debian/DEBIAN/prerm Normal file
View File

@ -0,0 +1,26 @@
#!/bin/bash
set -e
set -o pipefail
declare -r init_type='auto'
declare -r service_name='audiobookshelf'
if [[ "$init_type" == 'auto' || "$init_type" == 'systemd' || "$init_type" == 'upstart' || "$init_type" == 'sysv' ]]; then
if hash systemctl 2> /dev/null; then
systemctl disable "$service_name.service" && \
systemctl stop "$service_name.service" || \
echo "$service_name wasn't even running!"
elif hash service 2> /dev/null; then
service "$service_name" stop || echo "$service_name wasn't even running!"
elif hash stop 2> /dev/null; then
stop "$service_name" || echo "$service_name wasn't even running!"
elif hash update-rc.d 2> /dev/null; then
{
update-rc.d "$service_name" remove && \
"/etc/init.d/$service_name" stop
} || "$service_name wasn't even running!"
else
echo "Your system does not appear to use upstart, systemd or sysv, so $service_name could not be stopped"
echo 'Unless these systems were removed since install, no processes have been left running'
fi
fi

View File

@ -0,0 +1,4 @@
AUDIOBOOK_PATH=/usr/share/audiobookshelf/audiobooks
METADATA_PATH=/usr/share/audiobookshelf/metadata
CONFIG_PATH=/usr/share/audiobookshelf/config
PORT=1337

View File

@ -0,0 +1,16 @@
[Unit]
Description=Self-hosted audiobook server for managing and playing audiobooks
Requires=network.target
[Service]
Type=simple
EnvironmentFile=/etc/default/audiobookshelf
WorkingDirectory=/usr/share/audiobookshelf
ExecStart=/usr/share/audiobookshelf/audiobookshelf
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
User=audiobookshelf
PermissionsStartOnly=true
[Install]
WantedBy=multi-user.target

View File

@ -1,7 +1,7 @@
{
"name": "audiobookshelf",
"version": "1.2.1",
"description": "Self-hosted audiobook server for managing and playing audiobooks.",
"description": "Self-hosted audiobook server for managing and playing audiobooks",
"main": "index.js",
"scripts": {
"dev": "node index.js",
@ -9,12 +9,12 @@
"client": "cd client && npm install && npm run generate-client",
"generate-client": "cd client && npm run generate",
"prod": "npm run client && npm install && node prod.js",
"build-client": "cd client && rm -rf node_modules && npm i --unsafe-perm=true --allow-root && npm run generate",
"build-server": "rm -rf node_modules && npm i --unsafe-perm=true --allow-root && npm i ffmpeg-static --unsafe-perm=true --allow-root",
"build-client": "cd client && rm -rf node_modules && npm ci --unsafe-perm=true --allow-root && npm run generate",
"build-server": "rm -rf node_modules && npm ci --unsafe-perm=true --allow-root && npm i ffmpeg-static --unsafe-perm=true --allow-root",
"build-prep": "npm run build-client && npm run build-server",
"build-win": "npm run build-prep && pkg -t node12-win-x64 -o ./dist/win/audiobookshelf .",
"build-linuxarm": "npm run build-prep && pkg -t node12-linux-arm64 -o ./dist/linuxarm/audiobookshelf .",
"build-linux": "npm run build-prep && pkg -t node12-linux-x64 -o ./dist/linux/audiobookshelf ."
"build-linux": "npm run build-prep && pkg -t node12-linux-x64 -o dist/linux/audiobookshelf . && cp dist/linux/audiobookshelf build/debian/usr/share/"
},
"bin": "prod.js",
"pkg": {