`inbuxa uninstall [--dry-run] [--yes] [--purge]` takes away what the installer put on this machine: the compose project's containers, the units, the server's binary and the older ones kept for rollback, the console's and the webmail's files, the webmail's user, the installer's own Node. The data stays -- the server's volumes or its directory and user, Caddy's certificates, credentials.txt, .env, dns.zone -- and the install record, marked removed, so `install` run again with the same options converges onto it: the same mailboxes, no first boot. --purge takes the data too, volumes by name as well (after an uninstall that kept them there is no compose file left to name them), all but <dir>/backups, which it names for the operator to delete. Docker, other distribution packages and the configuration an operator's own web server loads are never touched; the last is said, as is a joined server that still lists these front ends. One component off is `install` with it skipped, and uninstall says so rather than doing it a second way. status says what was uninstalled and what was kept; upgrade has nothing to do on it. Tests: what is removed and kept, with and without --purge, in each shape. e2e: uninstall-containers 22/22 (a dry run and a run without --yes change nothing; uninstalled with volumes, credentials and backups kept; installed again with the same mailbox signing in; purged to the backups alone), uninstall-host 14/14 (units, binaries, the webmail's user and Node gone, the server's data and user kept, back again, then purged). upgrade-containers, install-local, install-host, status-export, topology, interface, all-host and webmail-host pass.
61 lines
3.1 KiB
Bash
61 lines
3.1 KiB
Bash
#!/bin/bash
|
|
# SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
#
|
|
# inbuxa uninstall, the server and the webmail on the host: units, binaries,
|
|
# the webmail's files and user and the installer's Node go; the server's
|
|
# directory and user stay, and install run again brings the server back on
|
|
# them; --purge takes those too.
|
|
#
|
|
# Run from the host with: e2e/vm/run.sh e2e/cases/uninstall-host.sh
|
|
set -uo pipefail
|
|
|
|
pass=0; fail=0
|
|
ok() { echo " ok $*"; pass=$((pass+1)); }
|
|
bad() { echo " FAIL $*"; fail=$((fail+1)); }
|
|
DIR=/var/lib/inbuxa
|
|
signs_in() {
|
|
local user pass
|
|
user=$(awk '/^first mailbox/ {print $3}' "$DIR/credentials.txt")
|
|
pass=$(awk '/^first mailbox/{getline; print $2}' "$DIR/credentials.txt")
|
|
curl -s -X POST http://127.0.0.1:8081/api/auth -H 'Content-Type: application/json' -H 'Accept: application/json' \
|
|
-d "{\"type\":\"authCode\",\"accountName\":\"$user\",\"accountSecret\":\"$pass\",\"clientId\":\"ihasmail-inbuxa\",\"redirectUri\":\"http://127.0.0.1:8080/api/auth/callback\",\"codeChallenge\":\"E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM\",\"codeChallengeMethod\":\"S256\"}" \
|
|
| grep -q '"client_\{0,1\}[cC]ode"'
|
|
}
|
|
user() { getent passwd "$1" >/dev/null; }
|
|
INSTALL=(/tmp/inbuxa install --local --domain example.test --server host --webmail host --install-deps --yes)
|
|
|
|
echo "==> installed on the host"
|
|
"${INSTALL[@]}" >/dev/null 2>&1 && ok "installed" || bad "install"
|
|
signs_in && ok "the first mailbox signs in" || bad "no sign-in to start with"
|
|
|
|
echo
|
|
echo "==> uninstalling"
|
|
OUT="$(/tmp/inbuxa uninstall --yes 2>&1)"; rc=$?
|
|
[ $rc -eq 0 ] && ok "uninstalled (exit 0)" || { bad "exit $rc"; echo "$OUT" | tail -6 | sed 's/^/ /'; }
|
|
for u in inbuxa-server inbuxa-webmail; do
|
|
[ ! -f /etc/systemd/system/$u.service ] && ! systemctl is-active --quiet $u && ok "$u is gone" || bad "$u is still there"
|
|
done
|
|
[ ! -e /usr/local/bin/inbuxa-server ] && ok "the server's binary is gone" || bad "the binary is still there"
|
|
[ ! -e $DIR/webmail ] && ! user inbuxa-webmail && ok "the webmail's files and user are gone" || bad "webmail files or user left"
|
|
[ ! -e /opt/inbuxa/node ] && ok "the installer's Node is gone" || bad "/opt/inbuxa/node is still there"
|
|
[ -f $DIR/server/config.json ] && user inbuxa && ok "the server's directory and user are kept" || bad "the server's data or user went"
|
|
|
|
echo
|
|
echo "==> installed again, on what was kept"
|
|
OUT="$("${INSTALL[@]}" 2>&1)"; rc=$?
|
|
[ $rc -eq 0 ] && ok "install again (exit 0)" || { bad "reinstall exit $rc"; echo "$OUT" | tail -8 | sed 's/^/ /'; }
|
|
for _ in $(seq 1 30); do signs_in && break; sleep 2; done
|
|
signs_in && ok "the same mailbox signs in" || bad "the first mailbox no longer signs in"
|
|
curl -fsS http://127.0.0.1:8080/api/health | grep -q '"ok":true' && ok "the webmail is back" || bad "no webmail"
|
|
|
|
echo
|
|
echo "==> purged"
|
|
OUT="$(/tmp/inbuxa uninstall --purge --yes 2>&1)"; rc=$?
|
|
[ $rc -eq 0 ] && ok "purged (exit 0)" || bad "purge exit $rc"
|
|
[ ! -e $DIR ] && ! user inbuxa && ok "$DIR and the inbuxa user are gone" || bad "left: $(ls -A $DIR 2>/dev/null | tr '\n' ' ') user=$(user inbuxa && echo yes)"
|
|
|
|
echo
|
|
echo "==> $pass passed, $fail failed"
|
|
[ "$fail" -eq 0 ]
|