diff --git a/build/debian/DEBIAN/postinst b/build/debian/DEBIAN/postinst index 51cfe75b..b80d18c6 100644 --- a/build/debian/DEBIAN/postinst +++ b/build/debian/DEBIAN/postinst @@ -2,49 +2,11 @@ set -e set -o pipefail -FFMPEG_INSTALL_DIR="/usr/lib/audiobookshelf-ffmpeg/" +ABS_LOG_DIR="/var/log/audiobookshelf" 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" @@ -76,13 +38,10 @@ start_service () { 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' -chown -R 'audiobookshelf:audiobookshelf' '/usr/share/audiobookshelf' -chown -R 'audiobookshelf:audiobookshelf' "$FFMPEG_INSTALL_DIR" +# Create log directory if not there and set ownership +if [ ! -d "$ABS_LOG_DIR" ]; then + mkdir -p "$ABS_LOG_DIR" + chown -R 'audiobookshelf:audiobookshelf' "$ABS_LOG_DIR" +fi start_service 'audiobookshelf' diff --git a/build/debian/DEBIAN/preinst b/build/debian/DEBIAN/preinst index e8ba4b47..bf4a3b17 100644 --- a/build/debian/DEBIAN/preinst +++ b/build/debian/DEBIAN/preinst @@ -2,12 +2,51 @@ set -e set -o pipefail -FFMPEG_INSTALL_DIR="/usr/lib/audiobookshelf-ffmpeg/" -DEFAULT_DATA_PATH="/usr/share/audiobookshelf" +FFMPEG_INSTALL_DIR="/usr/lib/audiobookshelf-ffmpeg" +DEFAULT_DATA_DIR="/usr/share/audiobookshelf" +CONFIG_PATH="/etc/default/audiobookshelf" DEFAULT_PORT=7331 DEFAULT_HOST="0.0.0.0" -CONFIG_PATH="/etc/default/audiobookshelf" + + +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 +} install_ffmpeg() { echo "Starting FFMPEG Install" @@ -15,8 +54,9 @@ install_ffmpeg() { WGET="wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz" if ! cd "$FFMPEG_INSTALL_DIR"; then - echo "WARNING: can't access working directory ($FFMPEG_INSTALL_DIR) creating it" >&2 + echo "Creating ffmpeg install dir at $FFMPEG_INSTALL_DIR" mkdir "$FFMPEG_INSTALL_DIR" + chown -R 'audiobookshelf:audiobookshelf' "$FFMPEG_INSTALL_DIR" cd "$FFMPEG_INSTALL_DIR" fi @@ -27,73 +67,23 @@ install_ffmpeg() { 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_interactive() { - if should_build_config; then - echo "Okay, let's setup a new config." - - 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 - - config_text="METADATA_PATH=$DATA_PATH/metadata - CONFIG_PATH=$DATA_PATH/config - FFMPEG_PATH=/usr/lib/audiobookshelf-ffmpeg/ffmpeg - FFPROBE_PATH=/usr/lib/audiobookshelf-ffmpeg/ffprobe - PORT=$PORT - HOST=$DEFAULT_HOST" - - echo "$config_text" - - echo "$config_text" > /etc/default/audiobookshelf; - - echo "Config created" - - fi -} - setup_config() { if [ -f "$CONFIG_PATH" ]; then echo "Existing config found." cat $CONFIG_PATH else + + if [ ! -d "$DEFAULT_DATA_DIR" ]; then + # Create directory and set permissions + echo "Creating default data dir at $DEFAULT_DATA_DIR" + mkdir "$DEFAULT_DATA_DIR" + chown -R 'audiobookshelf:audiobookshelf' "$DEFAULT_DATA_DIR" + fi + echo "Creating default config." - config_text="METADATA_PATH=$DEFAULT_DATA_PATH/metadata - CONFIG_PATH=$DEFAULT_DATA_PATH/config + config_text="METADATA_PATH=$DEFAULT_DATA_DIR/metadata + CONFIG_PATH=$DEFAULT_DATA_DIR/config FFMPEG_PATH=/usr/lib/audiobookshelf-ffmpeg/ffmpeg FFPROBE_PATH=/usr/lib/audiobookshelf-ffmpeg/ffprobe PORT=$DEFAULT_PORT @@ -107,6 +97,10 @@ setup_config() { fi } +add_group 'audiobookshelf' '' + +add_user 'audiobookshelf' '' 'audiobookshelf' 'audiobookshelf user-daemon' '/bin/false' + setup_config install_ffmpeg diff --git a/build/debian/usr/lib/audiobookshelf-ffmpeg/.gitkeep b/build/debian/usr/lib/.gitkeep similarity index 100% rename from build/debian/usr/lib/audiobookshelf-ffmpeg/.gitkeep rename to build/debian/usr/lib/.gitkeep diff --git a/build/debian/usr/share/audiobookshelf/.gitkeep b/build/debian/usr/share/.gitkeep similarity index 100% rename from build/debian/usr/share/audiobookshelf/.gitkeep rename to build/debian/usr/share/.gitkeep