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"
|
2021-09-25 20:01:53 +02:00
|
|
|
DEFAULT_PORT=7331
|
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-05-20 02:51:27 +02:00
|
|
|
WGET="wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz"
|
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-05-20 02:51:27 +02:00
|
|
|
echo "Good to go on Ffmpeg... 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
|
|
|
|
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
|
|
|
|
CONFIG_PATH=$DEFAULT_DATA_DIR/config
|
2021-12-15 01:56:09 +01:00
|
|
|
FFMPEG_PATH=/usr/lib/audiobookshelf-ffmpeg/ffmpeg
|
2022-01-11 00:57:51 +01:00
|
|
|
FFPROBE_PATH=/usr/lib/audiobookshelf-ffmpeg/ffprobe
|
2022-03-17 14:18:39 +01:00
|
|
|
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
|