From ebcdbb88bdc75de251b80dc061e73c5f527ec9f4 Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Sat, 26 Feb 2022 23:03:29 +0100 Subject: [PATCH] calibre-web - new seq for installation from pip and basic setup --- seqs/calibreweb.cfg.example | 17 +++++ seqs/calibreweb.sh | 131 ++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 seqs/calibreweb.cfg.example create mode 100755 seqs/calibreweb.sh diff --git a/seqs/calibreweb.cfg.example b/seqs/calibreweb.cfg.example new file mode 100644 index 0000000..e90be9b --- /dev/null +++ b/seqs/calibreweb.cfg.example @@ -0,0 +1,17 @@ +#!/bin/bash + +CALWEB_BASE="/opt/calibre-web" +CALWEB_VENV_ROOT="$CALWEB_BASE/venv" +CALWEB_USER_HOME="$CALWEB_BASE/home" +CALWEB_USER="calibreweb" +CALWEB_SERVICE="[Unit] +Description=Calibre-Web +After=network-online.target + +[Service] +Type=simple +User=$CALWEB_USER +ExecStart="$CALWEB_VENV_ROOT/bin/cps" + +[Install] +WantedBy=multi-user.target" diff --git a/seqs/calibreweb.sh b/seqs/calibreweb.sh new file mode 100755 index 0000000..25061a9 --- /dev/null +++ b/seqs/calibreweb.sh @@ -0,0 +1,131 @@ +#!/bin/bash + +toolName=calibre-web +toolPipName=calibreweb +toolDeps="python3-pip python3-venv" +toolFeatures=( metadata comics ) + +# Get script working directory +# (when called from a different directory) +WDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)" +APTOPT= +CONFIG=0 +SCRIPT_FILE=$(basename -- $0) +SCRIPT_NAME=${SCRIPT_FILE%%.*} +CONFIG_FILE_NAME="${SCRIPT_NAME}.cfg" +CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example" + +step_config() { + ## or to use sequencer api with global config file: + initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" + if [ $? -eq 0 ] ; then + CONFIG=1 + else + # End if no configuration file exists + [ $DRY -eq 0 ] && return -1 + fi + + ## Apt cmdline option to suppress user interaction + [ $QUIET -ne 0 ] && APTOPT="-y" + + ## Return of non zero value will abort the sequence + return 0 +} + +step_1_info() { echo "Install dependencies"; } +step_1_alias() { ALIAS="install"; } +step_1() { + exe apt install $toolDeps $APTOPT +} + +step_2_info() { echo "Setup python virtual environment"; } +step_2() { + if ! id $CALWEB_USER &>/dev/null; then + exe adduser --disabled-password --disabled-login --home-dir "$CALWEB_USER_HOME" --gecos "" $CALWEB_USER + exe usermod -aG users $CALWEB_USER + else + echoseq " [W] User $CALWEB_USER already exists" + fi + if [ ! -e "$CALWEB_VENV_ROOT/bin" ]; then + exe python3 -m venv "$CALWEB_VENV_ROOT" + endReturn -o $? "Creating virtual environment failed" + exe chown -R ${CALWEB_USER}: "$CALWEB_BASE" + else + echoseq " [W] Virtual env. $CALWEB_VENV_ROOT already exists" + fi +} + +step_3_info() { echo "Install $toolName using pip"; } +step_3() { + step upgradepip + exe ${CALWEB_VENV_ROOT}/bin/pip install $toolPipName +} + +step_4_info() { + echo "Install $toolName features" + echoinfo ${toolFeatures[*]} +} +step_4() { + for i in "${!toolFeatures[@]}"; do + toolFeatures[$i]="$toolPipName[${toolFeatures[$i]}]" + done + exe ${CALWEB_VENV_ROOT}/bin/pip install "${toolFeatures[@]}" +} + +step_5_info() { echo "Install systemd service"; } +step_5() { + addConf -s "$CALWEB_SERVICE" "$calweb_service_loc" + [ $? -eq 0 ] && exe systemctl daemon-reload +} +calweb_service_name="calibreweb.service" +calweb_service_loc="/etc/systemd/system/$calweb_service_name" + +step_6_info() { echo "Enable and start systemd service"; } +step_6() { + exe systemctl enable $calweb_service_name --now +} + +step_15_info() { echo "Upgrade python pip"; } +step_15_alias() { ALIAS="upgradepip"; } +step_15() +{ + exe ${CALWEB_VENV_ROOT}/bin/pip install --upgrade pip +} + +step_100_info() { echo "Setup notes"; } +step_100_alias() { ALIAS="notes"; } +step_100() { + outColor green + cat <