From d95689a0780efa87bea46a401c160828bd56a7ac Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 25 Sep 2021 13:01:53 -0500 Subject: [PATCH] Debian preinstall script for config and ffmpeg --- build/debian/DEBIAN/preinst | 95 +++++++++++++++++++ build/debian/etc/default/audiobookshelf | 1 + .../usr/lib/audiobookshelf-ffmpeg/.gitkeep | 0 package.json | 2 +- server/DownloadManager.js | 1 - 5 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 build/debian/DEBIAN/preinst create mode 100644 build/debian/usr/lib/audiobookshelf-ffmpeg/.gitkeep diff --git a/build/debian/DEBIAN/preinst b/build/debian/DEBIAN/preinst new file mode 100644 index 00000000..8919fd4b --- /dev/null +++ b/build/debian/DEBIAN/preinst @@ -0,0 +1,95 @@ +#!/bin/bash +set -e +set -o pipefail + +DEFAULT_AUDIOBOOK_PATH="/usr/share/audiobookshelf/audiobooks" +DEFAULT_DATA_PATH="/usr/share/audiobookshelf" +DEFAULT_PORT=7331 + +CONFIG_PATH="/etc/default/audiobookshelf" + +install_ffmpeg() { + echo "Starting FFMPEG Install" + + WGET="wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz" + TARGET_DIR="/usr/lib/audiobookshelf-ffmpeg/" + + if ! cd "$TARGET_DIR"; then + echo "WARNING: can't access working directory ($TARGET_DIR) creating it" >&2 + mkdir "$TARGET_DIR" + cd "$TARGET_DIR" + fi + + $WGET + tar xvf ffmpeg-git-amd64-static.tar.xz --strip-components=1 + rm ffmpeg-git-amd64-static.tar.xz + + chown -R 'audiobookshelf:audiobookshelf' "$TARGET_DIR" + + echo "Good to go on Ffmpeg... hopefully" +} + +should_build_config() { + if [ -f "$CONFIG_PATH" ]; then + echo "You already have a config file. Do you want to use it?" + + options=("Yes" "No") + select yn in "${options[@]}" + do + case $yn in + "Yes") + false; return + ;; + "No") + true; return + ;; + esac + done + else + echo "No existing config found in $CONFIG_PATH" + true; return + fi +} + +setup_config() { + if should_build_config; then + echo "Alright then, let's setup a new config." + + AUDIOBOOK_PATH="" + read -p "Enter path for your audiobooks [Default: $DEFAULT_AUDIOBOOK_PATH]: " AUDIOBOOK_PATH + + if [[ -z "$AUDIOBOOK_PATH" ]]; then + AUDIOBOOK_PATH="$DEFAULT_AUDIOBOOK_PATH" + fi + + DATA_PATH="" + read -p "Enter path for data files, i.e. streams, downloads, database [Default: $DEFAULT_DATA_PATH]: " DATA_PATH + + if [[ -z "$DATA_PATH" ]]; then + DATA_PATH="$DEFAULT_DATA_PATH" + fi + + PORT="" + read -p "Port for the web ui [Default: $DEFAULT_PORT]: " PORT + + if [[ -z "$PORT" ]]; then + PORT="$DEFAULT_PORT" + fi + fi + + config_text="AUDIOBOOK_PATH=$AUDIOBOOK_PATH +METADATA_PATH=$DATA_PATH/metadata +CONFIG_PATH=$DATA_PATH/config +FFMPEG_PATH=/usr/lib/audiobookshelf-ffmpeg/ffmpeg +PORT=$PORT" + + echo "$config_text" + + echo "$config_text" > /etc/default/audiobookshelf; + + echo "Config created" +} + +setup_config + +install_ffmpeg diff --git a/build/debian/etc/default/audiobookshelf b/build/debian/etc/default/audiobookshelf index f9c59c60..7f731f62 100644 --- a/build/debian/etc/default/audiobookshelf +++ b/build/debian/etc/default/audiobookshelf @@ -1,4 +1,5 @@ AUDIOBOOK_PATH=/usr/share/audiobookshelf/audiobooks METADATA_PATH=/usr/share/audiobookshelf/metadata CONFIG_PATH=/usr/share/audiobookshelf/config +FFMPEG_PATH=/usr/lib/audiobookshelf-ffmpeg/ffmpeg PORT=1337 diff --git a/build/debian/usr/lib/audiobookshelf-ffmpeg/.gitkeep b/build/debian/usr/lib/audiobookshelf-ffmpeg/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/package.json b/package.json index 13458852..e079a251 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "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 . && cp dist/linux/audiobookshelf build/debian/usr/share/audiobookshelf/ && chmod -R 775 build/debian/" + "build-linux": "npm run build-prep && pkg -t node12-linux-x64 -o dist/linux/audiobookshelf . && cp dist/linux/audiobookshelf build/debian/usr/share/audiobookshelf/ && chmod -R 775 build/debian/ && fakeroot dpkg-deb --build build/debian" }, "bin": "prod.js", "pkg": { diff --git a/server/DownloadManager.js b/server/DownloadManager.js index 563deed1..c2bd0326 100644 --- a/server/DownloadManager.js +++ b/server/DownloadManager.js @@ -263,7 +263,6 @@ class DownloadManager { var worker = null try { var workerPath = Path.join(global.appRoot, 'server/utils/downloadWorker.js') - Logger.info(`[${TAG}] Worker Path: ${workerPath}`) worker = new workerThreads.Worker(workerPath, { workerData }) } catch (error) { Logger.error(`[${TAG}] Start worker thread failed`, error)