#!/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" seq_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 || return -1 fi ## Apt cmdline option to suppress user interaction quiet && APTOPT="-y" ## Return of non zero value will abort the sequence return 0 } step_1_info() { echo "Install dependencies"; } step_1_alias() { echo "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 warning "User $CALWEB_USER already exists" fi if [ ! -e "$CALWEB_VENV_ROOT/bin" ]; then exe python3 -m venv "$CALWEB_VENV_ROOT" endReturn "Creating virtual environment failed" exe chown -R ${CALWEB_USER}: "$CALWEB_BASE" else warning "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[@]}" # Needed for in-app update exe chown -R "${CALWEB_USER}": "${CALWEB_VENV_ROOT}/lib/python*/site-packages/calibreweb" } 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() { echo "upgradepip"; } step_15() { exe ${CALWEB_VENV_ROOT}/bin/pip install --upgrade pip } step_100_info() { echo "Setup notes"; } step_100_alias() { echo "notes"; } step_100() { color green cat <