update and simplify
This commit is contained in:
@@ -1,51 +1,47 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
readonly toolName=postfixadmin
|
||||
# since php8.0 json is always available
|
||||
readonly toolPhpDeps=(bz2 curl fpm gmp imap intl mbstring mysql xml zip)
|
||||
readonly toolConfName="config.local.php"
|
||||
readonly toolTemplates="templates_c"
|
||||
readonly latestUrl="https://api.github.com/repos/$toolName/$toolName/releases/latest"
|
||||
readonly fetchmailUser="fetchmail"
|
||||
readonly fetchmailDeps="fetchmail liblockfile-simple-perl"
|
||||
|
||||
toolName=postfixadmin
|
||||
toolPhpDeps='php${PFA_PHP_VERSION:-}-fpm php${PFA_PHP_VERSION:-}-imap php${PFA_PHP_VERSION:-}-mbstring php${PFA_PHP_VERSION:-}-mysql php${PFA_PHP_VERSION:-}-json php${PFA_PHP_VERSION:-}-curl php${PFA_PHP_VERSION:-}-zip php${PFA_PHP_VERSION:-}-xml php${PFA_PHP_VERSION:-}-bz2 php${PFA_PHP_VERSION:-}-intl php${PFA_PHP_VERSION:-}-gmp'
|
||||
toolConfName="config.local.php"
|
||||
toolTemplates="templates_c"
|
||||
toolTemplatesLoc=
|
||||
toolAdditionsLoc=
|
||||
latestUrl="https://api.github.com/repos/$toolName/$toolName/releases/latest"
|
||||
fetchmailUser="fetchmail"
|
||||
fetchmailDeps="fetchmail liblockfile-simple-perl"
|
||||
|
||||
# Get script working directory
|
||||
# (when called from a different directory)
|
||||
WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
|
||||
CONFIG=0
|
||||
CONFIG_FILE_NAME="${toolName}.cfg"
|
||||
CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example"
|
||||
sq_aptOpt=
|
||||
sq_config=0
|
||||
|
||||
seq_config() {
|
||||
if initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" ; then
|
||||
if initSeqConfig "${seq_configName:?}" "${seq_configTemplate:?}" ; then
|
||||
info "${toolName} path: ${PFA_WEB_LOC:-}"
|
||||
info -a "${toolName} backup: ${PFA_BACKUP:-}"
|
||||
info -a " php Version: ${PFA_PHP_VERSION:-}"
|
||||
CONFIG=1
|
||||
sq_config=1
|
||||
toolTemplatesLoc="$PFA_SRV_LOC/$toolTemplates"
|
||||
toolAdditionsLoc="$PFA_SRV_LOC/ADDITIONS"
|
||||
else
|
||||
dry || return 1
|
||||
fi
|
||||
|
||||
## Apt cmdline option to suppress user interaction
|
||||
interactive || sq_aptOpt="-y"
|
||||
|
||||
## Return of non zero value will abort the sequence
|
||||
return 0
|
||||
}
|
||||
|
||||
step_1_info() {
|
||||
# eval needed to expand sourced configuration variables
|
||||
local localDeps=`eval "echo \"$toolPhpDeps\""`
|
||||
echo "Install $toolName dependencies:"
|
||||
echoinfo "$localDeps"
|
||||
echoinfo "${toolPhpDeps[@]/#/php${PFA_PHP_VERSION:-}-}"
|
||||
}
|
||||
step_1_alias() { echo "install"; }
|
||||
step_1() {
|
||||
# eval needed to expand sourced configuration variables
|
||||
local localDeps=`eval "echo \"$toolPhpDeps\""`
|
||||
local aptOpt=
|
||||
if quiet;then
|
||||
aptOpt="-y"
|
||||
fi
|
||||
exe apt update
|
||||
exe apt install $localDeps $aptOpt
|
||||
exe apt install "${toolPhpDeps[@]/#/php${PFA_PHP_VERSION:?}-}" ${sq_aptOpt:-}
|
||||
}
|
||||
|
||||
step_2_info() { echo "Install $toolName to ${PFA_SRV_LOC:-}"; }
|
||||
@@ -56,11 +52,7 @@ step_2() {
|
||||
step_3_info() { echo "Install fetchmail"; }
|
||||
step_3_alias() { echo "install_fetchmail"; }
|
||||
step_3() {
|
||||
local aptOpt=
|
||||
if quiet;then
|
||||
aptOpt="-y"
|
||||
fi
|
||||
exe apt install $fetchmailDeps $aptOpt
|
||||
exe apt install $fetchmailDeps ${sq_aptOpt:-}
|
||||
endReturn -o $? "Failed to install fetchmail"
|
||||
exe systemctl stop fetchmail
|
||||
exe systemctl disable fetchmail
|
||||
@@ -69,7 +61,7 @@ step_3() {
|
||||
step_4_info() { echo "Configure postfixadmin to use fetchmail"; }
|
||||
step_4() {
|
||||
echo "# Create mysql config"
|
||||
echo " [$PFA_SRV_LOC/fetchmail.conf]"
|
||||
echo " [/etc/mail/postfixadmin/fetchmail.conf]"
|
||||
echo " # Follow instructions in $toolAdditionsLoc/fetchmail.pl"
|
||||
echo " \$db_type = 'mysql';"
|
||||
echo " \$run_dir=\"/var/lock\";"
|
||||
@@ -172,7 +164,7 @@ step_18() {
|
||||
step_20_info() {
|
||||
echoinfoArgs "[POSTFIXADMIN SRV ROOT]"
|
||||
echo -n "Create a backup"
|
||||
if [ $CONFIG -ne 0 ] ; then
|
||||
if [ $sq_config -ne 0 ] ; then
|
||||
echo " at $PFA_BACKUP"
|
||||
else
|
||||
echo
|
||||
@@ -182,7 +174,7 @@ step_20_alias() { echo "backup"; }
|
||||
step_20() {
|
||||
shift
|
||||
local tempRoot=
|
||||
if [ $CONFIG -eq 0 ] ; then
|
||||
if [ $sq_config -eq 0 ] ; then
|
||||
error -e "No configuration file found"
|
||||
return 1
|
||||
fi
|
||||
@@ -200,7 +192,7 @@ step_20() {
|
||||
exe cd "$tempRoot/.."
|
||||
exe tar czf "$srvBackup" $(basename "$tempRoot")
|
||||
|
||||
exe $WDIR/mysql.sh -qq backup "$PFA_DATABASE" "$PFA_BACKUP"
|
||||
exe ${seq_origin:?}/mysql.sh -qq backup "$PFA_DATABASE" "$PFA_BACKUP"
|
||||
}
|
||||
|
||||
step_22_info() {
|
||||
@@ -291,7 +283,7 @@ step_22() {
|
||||
exe cp -ar "$webConf" "$PFA_SRV_LOC/"
|
||||
else
|
||||
echo " [I] Creating empty configuration file $PFA_SRV_LOC/$toolConfName"
|
||||
exep "echo -e \"# Created gy $WDIR/$(basename $0)\\n\\n# Changeme\" > \"$PFA_SRV_LOC/$toolConfName\""
|
||||
exep "echo -e \"# Created by ${seq_origin:?}/$(basename $0)\\n\\n# Changeme\" > \"$PFA_SRV_LOC/$toolConfName\""
|
||||
fi
|
||||
|
||||
# Templates
|
||||
@@ -327,5 +319,7 @@ step_100() {
|
||||
exe ${PFA_SRV_LOC}/scripts/$toolName-cli $@
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2034 # Appears unused
|
||||
readonly sqr_minVersion=16
|
||||
# shellcheck disable=SC1091 # Don't follow this source
|
||||
. /usr/local/bin/sequencer.sh
|
||||
|
Reference in New Issue
Block a user