#!/usr/bin/env bash readonly toolName=whoogle readonly toolDeps=(libcurl4-openssl-dev libssl-dev) sq_aptOpt= readonly sq_gitUrl="https://github.com/benbusby/whoogle-search.git" seq_config() { ## or to use sequencer api with global config file: if ! initSeqConfig "${seq_configName:?}" "${seq_configTemplate:?}" ; then # End if no configuration file exists dry || return 1 fi ## Apt cmdline option to suppress user interaction interactive || sq_aptOpt="-y" ## Disable error checks if external scripts are used ## e.g. error on unbound variables #disableErrorCheck ## Return of non zero value will abort the sequence return 0 } step_1_info() { echo "Show status of ${toolName}"; } step_1_alias() { echo "status"; } step_1() { exep service whoogle status '2>/dev/null' || error "${toolName}" not installed } step_20_info() { echo "Git clone ${toolName} and use as python venv" echoinfo "(${sq_gitUrl})" } step_20_alias() { echo "install"; } step_20() { info "Installing dependencies" exe apt-get install "${toolDeps[@]}" ${sq_aptOpt} info "Installing ${toolName} from ${sq_gitUrl}" exe git clone "${sq_gitUrl}" "${sc_whoogleDir:?}" endReturn -o $? "Cloning ${toolName} failed" exe cd "${sc_whoogleDir:?}" exe python3 -m venv venv #exe source venv/bin/activate step postupgrade } step_21_info() { echo "Create system user ${sc_whoogleUser:-'whoogle'}"; } step_21() { exe adduser --disabled-password --disabled-login --no-create-home --gecos "" "${sc_whoogleUser:?}" } step_22_info() { echo "Create systemd service"; } step_22() { addConf -s "${sc_whoogleService}" "${sc_whoogleServiceLoc}" exe systemctl daemon-reload exe systemctl enable --now "${toolName}.service" } sc_whoogleServiceLoc="/etc/systemd/system/whoogle.service" sc_whoogleService="[Unit] Description=Whoogle [Service] # Load values from dotenv only Environment=WHOOGLE_DOTENV=1 Type=simple User=${sc_whoogleUser} WorkingDirectory=${sc_whoogleDir} ExecStart=${sc_whoogleDir}/venv/bin/python3 -um app --host ${sc_whoogleHost:-"0.0.0.0"} --port ${sc_whooglePort:-"5000"} ExecReload=/bin/kill -HUP $MAINPID Restart=always RestartSec=3 SyslogIdentifier=whoogle [Install] WantedBy=multi-user.target" step_30_info() { echo "Upgrade installation using git"; } step_30_alias() { echo "upgrade"; } step_30() { exe cd "${sc_whoogleDir:?}" endReturn -o $? "${toolName} doesn't seam to be installed" exe service "${toolName}" stop exe git pull } step_31_info() { echo "Post upgrade steps"; } step_31_alias() { echo "postupgrade"; } step_31() { exe "${sc_whoogleDir:?}/venv/bin/pip" install -r "${sc_whoogleDir:?}/requirements.txt" exe chown "${sc_whoogleUser:?}": "${sc_whoogleDir:?}" -R } step_32_info() { echo "Restart ${toolName} service"; } step_32_alias() { echo "restart"; } step_32() { exe service "${toolName}" restart } # shellcheck disable=SC2034 # Appears unused readonly sqr_minVersion=16 # shellcheck disable=SC1091 # Don't follow this source . /usr/local/bin/sequencer.sh