2021-09-25 20:01:53 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
FFMPEG_INSTALL_DIR="/usr/lib/audiobookshelf-ffmpeg"
|
|
|
|
DEFAULT_DATA_DIR="/usr/share/audiobookshelf"
|
|
|
|
CONFIG_PATH="/etc/default/audiobookshelf"
|
2022-09-03 00:53:43 +02:00
|
|
|
DEFAULT_PORT=13378
|
2022-03-17 14:18:39 +01:00
|
|
|
DEFAULT_HOST="0.0.0.0"
|
2021-09-25 20:01:53 +02:00
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
add_user() {
|
|
|
|
: "${1:?'User was not defined'}"
|
|
|
|
declare -r user="$1"
|
|
|
|
declare -r uid="$2"
|
2021-09-25 20:01:53 +02:00
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
if [ -z "$uid" ]; then
|
|
|
|
declare -r uid_flags=""
|
|
|
|
else
|
|
|
|
declare -r uid_flags="--uid $uid"
|
2021-09-25 20:01:53 +02:00
|
|
|
fi
|
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
declare -r group="${3:-$user}"
|
|
|
|
declare -r descr="${4:-No description}"
|
|
|
|
declare -r shell="${5:-/bin/false}"
|
2021-09-25 20:01:53 +02:00
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
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
|
2021-09-25 20:01:53 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
add_group() {
|
|
|
|
: "${1:?'Group was not defined'}"
|
|
|
|
declare -r group="$1"
|
|
|
|
declare -r gid="$2"
|
2021-09-25 20:01:53 +02:00
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
if [ -z "$gid" ]; then
|
|
|
|
declare -r gid_flags=""
|
|
|
|
else
|
|
|
|
declare -r gid_flags="--gid $gid"
|
|
|
|
fi
|
2021-09-25 20:01:53 +02:00
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
if ! getent group | grep -q "^$group:" ; then
|
|
|
|
echo "Creating system group: $group"
|
|
|
|
groupadd $gid_flags --system $group
|
|
|
|
fi
|
|
|
|
}
|
2021-09-25 20:01:53 +02:00
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
install_ffmpeg() {
|
|
|
|
echo "Starting FFMPEG Install"
|
2021-09-26 00:37:21 +02:00
|
|
|
|
2022-10-27 00:13:56 +02:00
|
|
|
WGET="wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz --output-document=ffmpeg-git-amd64-static.tar.xz"
|
2023-04-20 00:22:25 +02:00
|
|
|
WGET_TONE="wget https://github.com/sandreas/tone/releases/download/v0.1.5/tone-0.1.5-linux-x64.tar.gz --output-document=tone-0.1.5-linux-x64.tar.gz"
|
2021-09-25 20:01:53 +02:00
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
if ! cd "$FFMPEG_INSTALL_DIR"; then
|
|
|
|
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
|
2021-09-25 20:01:53 +02:00
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
$WGET
|
|
|
|
tar xvf ffmpeg-git-amd64-static.tar.xz --strip-components=1
|
|
|
|
rm ffmpeg-git-amd64-static.tar.xz
|
2021-09-25 20:01:53 +02:00
|
|
|
|
2022-09-11 23:05:53 +02:00
|
|
|
# Temp downloading tone library to the ffmpeg dir
|
|
|
|
echo "Getting tone.."
|
|
|
|
$WGET_TONE
|
2023-04-20 00:22:25 +02:00
|
|
|
tar xvf tone-0.1.5-linux-x64.tar.gz --strip-components=1
|
|
|
|
rm tone-0.1.5-linux-x64.tar.gz
|
2022-09-11 23:05:53 +02:00
|
|
|
|
|
|
|
echo "Good to go on Ffmpeg (& tone)... hopefully"
|
2021-09-25 20:01:53 +02:00
|
|
|
}
|
|
|
|
|
2021-12-15 01:56:09 +01:00
|
|
|
setup_config() {
|
|
|
|
if [ -f "$CONFIG_PATH" ]; then
|
|
|
|
echo "Existing config found."
|
|
|
|
cat $CONFIG_PATH
|
2022-09-11 23:55:33 +02:00
|
|
|
|
|
|
|
# TONE_PATH variable added in 2.1.6, if it doesnt exist then add it
|
|
|
|
if ! grep -q "TONE_PATH" "$CONFIG_PATH"; then
|
|
|
|
echo "Adding TONE_PATH to existing config"
|
|
|
|
echo "TONE_PATH=$FFMPEG_INSTALL_DIR/tone" >> "$CONFIG_PATH"
|
|
|
|
fi
|
2022-09-11 23:57:36 +02:00
|
|
|
|
2021-12-15 01:56:09 +01:00
|
|
|
else
|
2022-05-20 02:51:27 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-12-15 01:56:09 +01:00
|
|
|
echo "Creating default config."
|
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
config_text="METADATA_PATH=$DEFAULT_DATA_DIR/metadata
|
2022-09-11 23:55:33 +02:00
|
|
|
CONFIG_PATH=$DEFAULT_DATA_DIR/config
|
|
|
|
FFMPEG_PATH=$FFMPEG_INSTALL_DIR/ffmpeg
|
2022-09-11 23:57:36 +02:00
|
|
|
FFPROBE_PATH=$FFMPEG_INSTALL_DIR/ffprobe
|
2022-09-11 23:55:33 +02:00
|
|
|
TONE_PATH=$FFMPEG_INSTALL_DIR/tone
|
|
|
|
PORT=$DEFAULT_PORT
|
|
|
|
HOST=$DEFAULT_HOST"
|
2021-12-15 01:56:09 +01:00
|
|
|
|
|
|
|
echo "$config_text"
|
|
|
|
|
|
|
|
echo "$config_text" > /etc/default/audiobookshelf;
|
|
|
|
|
|
|
|
echo "Config created"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
add_group 'audiobookshelf' ''
|
|
|
|
|
|
|
|
add_user 'audiobookshelf' '' 'audiobookshelf' 'audiobookshelf user-daemon' '/bin/false'
|
|
|
|
|
2021-09-25 20:01:53 +02:00
|
|
|
setup_config
|
|
|
|
|
|
|
|
install_ffmpeg
|