install_quota_clone.sh: remove hardcoded PostfixAdmin path and add interactive symlink detection
This commit is contained in:
+34
-11
@@ -24,7 +24,6 @@ set -uo pipefail
|
|||||||
|
|
||||||
# ── paths ─────────────────────────────────────────────────────────────────────
|
# ── paths ─────────────────────────────────────────────────────────────────────
|
||||||
DOVECOT_LINK="/usr/local/dovecot"
|
DOVECOT_LINK="/usr/local/dovecot"
|
||||||
PFA_LINK="/var/www/adm.oopen.de/postfixadmin"
|
|
||||||
BACKUP_BASE="/root/backup"
|
BACKUP_BASE="/root/backup"
|
||||||
|
|
||||||
# ── colour helpers ────────────────────────────────────────────────────────────
|
# ── colour helpers ────────────────────────────────────────────────────────────
|
||||||
@@ -41,20 +40,44 @@ die() { echo -e "\n${_red}FATAL: ${*}${_nc}" >&2; exit 1; }
|
|||||||
# ── root check ────────────────────────────────────────────────────────────────
|
# ── root check ────────────────────────────────────────────────────────────────
|
||||||
[[ $EUID -eq 0 ]] || die "This script must be run as root."
|
[[ $EUID -eq 0 ]] || die "This script must be run as root."
|
||||||
|
|
||||||
# ── resolve symlinks ──────────────────────────────────────────────────────────
|
|
||||||
[[ -L "$DOVECOT_LINK" ]] || die "$DOVECOT_LINK is not a symlink."
|
|
||||||
[[ -L "$PFA_LINK" ]] || die "$PFA_LINK is not a symlink."
|
|
||||||
|
|
||||||
DOVECOT_REAL=$(realpath "$DOVECOT_LINK")
|
|
||||||
PFA_REAL=$(realpath "$PFA_LINK")
|
|
||||||
DOVECOT_CONF_D="${DOVECOT_REAL}/etc/dovecot/conf.d"
|
|
||||||
SQL_CONNECT="${DOVECOT_REAL}/etc/dovecot/sql-connect.conf.ext"
|
|
||||||
PFA_CONFIG="${PFA_REAL}/config.local.php"
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo -e "${_bold}Dovecot quota_clone + PostfixAdmin quota display${_nc}"
|
echo -e "${_bold}Dovecot quota_clone + PostfixAdmin quota display${_nc}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
# ── Dovecot path ──────────────────────────────────────────────────────────────
|
||||||
|
[[ -L "$DOVECOT_LINK" ]] || die "$DOVECOT_LINK is not a symlink."
|
||||||
|
DOVECOT_REAL=$(realpath "$DOVECOT_LINK")
|
||||||
|
DOVECOT_CONF_D="${DOVECOT_REAL}/etc/dovecot/conf.d"
|
||||||
|
SQL_CONNECT="${DOVECOT_REAL}/etc/dovecot/sql-connect.conf.ext"
|
||||||
info "Dovecot : $DOVECOT_REAL"
|
info "Dovecot : $DOVECOT_REAL"
|
||||||
|
|
||||||
|
# ── PostfixAdmin path (interactive) ──────────────────────────────────────────
|
||||||
|
# Auto-detect: look for a 'postfixadmin' symlink under /var/www/*/htdocs/
|
||||||
|
_pfa_default=""
|
||||||
|
mapfile -t _pfa_candidates < <(find /var/www -maxdepth 3 -name "postfixadmin" -type l 2>/dev/null | sort)
|
||||||
|
if [[ ${#_pfa_candidates[@]} -eq 1 ]]; then
|
||||||
|
_pfa_default="${_pfa_candidates[0]}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
if [[ -n "$_pfa_default" ]]; then
|
||||||
|
read -rp " PostfixAdmin symlink [${_pfa_default}]: " PFA_LINK
|
||||||
|
PFA_LINK="${PFA_LINK:-$_pfa_default}"
|
||||||
|
else
|
||||||
|
read -rp " PostfixAdmin symlink (e.g. /var/www/hostname/htdocs/postfixadmin): " PFA_LINK
|
||||||
|
fi
|
||||||
|
if [[ -L "$PFA_LINK" ]]; then
|
||||||
|
break
|
||||||
|
elif [[ -d "$PFA_LINK" ]]; then
|
||||||
|
echo -e " ${_yellow}Warning: $PFA_LINK is a directory, not a symlink — continuing anyway.${_nc}"
|
||||||
|
break
|
||||||
|
else
|
||||||
|
echo -e " ${_red}Not found or not a symlink: $PFA_LINK — please try again.${_nc}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
PFA_REAL=$(realpath "$PFA_LINK")
|
||||||
|
PFA_CONFIG="${PFA_REAL}/config.local.php"
|
||||||
info "PFA : $PFA_REAL"
|
info "PFA : $PFA_REAL"
|
||||||
|
|
||||||
# ── read DB credentials from Dovecot's sql-connect.conf.ext ──────────────────
|
# ── read DB credentials from Dovecot's sql-connect.conf.ext ──────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user