`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.
75 lines
4.5 KiB
Bash
75 lines
4.5 KiB
Bash
#!/bin/bash
|
|
# SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
#
|
|
# inbuxa uninstall, everything in containers: the programs go and the data
|
|
# stays; install run again brings it back with the same mailbox; --purge
|
|
# then removes the data too, all but the backups.
|
|
#
|
|
# Run from the host with: e2e/vm/run.sh e2e/cases/uninstall-containers.sh
|
|
set -uo pipefail
|
|
|
|
pass=0; fail=0
|
|
ok() { echo " ok $*"; pass=$((pass+1)); }
|
|
bad() { echo " FAIL $*"; fail=$((fail+1)); }
|
|
DIR=/var/lib/inbuxa
|
|
rt() { command -v docker >/dev/null 2>&1 && echo docker || echo podman; }
|
|
containers() { $(rt) ps -a --filter label=com.docker.compose.project=inbuxa --format '{{.Names}}' | wc -l; }
|
|
volumes() { $(rt) volume ls --format '{{.Name}}' | grep -c '^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"'
|
|
}
|
|
|
|
echo "==> installed, with an archive from an upgrade"
|
|
/tmp/inbuxa install --local --domain example.test --install-deps --yes >/dev/null 2>&1 && ok "installed" || bad "install"
|
|
mkdir -p $DIR/backups && echo archive > $DIR/backups/server-test.tar.gz
|
|
signs_in && ok "the first mailbox signs in" || bad "no sign-in to start with"
|
|
|
|
echo
|
|
echo "==> what it would do"
|
|
DRY="$(/tmp/inbuxa uninstall --dry-run 2>&1)"; rc=$?
|
|
grep -q "inbuxa_inbuxa-data" <<<"$(sed -n '/^Kept:/,$p' <<<"$DRY")" && ok "the server's volumes are kept" || { bad "dry run"; echo "$DRY" | sed 's/^/ /'; }
|
|
[ "$(containers)" = 3 ] && ok "a dry run changed nothing" || bad "containers: $(containers)"
|
|
OUT="$(/tmp/inbuxa uninstall 2>&1)"; rc=$?
|
|
[ $rc -ne 0 ] && [ "$(containers)" = 3 ] && ok "without --yes, nothing happens" || bad "it ran without --yes"
|
|
OUT="$(/tmp/inbuxa uninstall console --yes 2>&1)"; rc=$?
|
|
[ $rc -eq 2 ] && grep -q -- "--console skip" <<<"$OUT" && ok "one component points to install --console skip" || bad "uninstall console: exit $rc"
|
|
|
|
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/^/ /'; }
|
|
[ "$(containers)" = 0 ] && ok "no containers left" || bad "$(containers) containers left"
|
|
[ "$(volumes)" -ge 2 ] && ok "the volumes are kept ($(volumes))" || bad "the volumes are gone"
|
|
[ -f $DIR/credentials.txt ] && [ -f $DIR/.env ] && ok "credentials.txt and .env are kept" || bad "the credentials are gone"
|
|
[ ! -f $DIR/compose.yaml ] && ok "the compose file is gone" || bad "compose.yaml is still there"
|
|
/tmp/inbuxa status 2>&1 | grep -q "uninstalled" && ok "status says it was uninstalled, data kept" || bad "status: $(/tmp/inbuxa status 2>&1 | head -2)"
|
|
/tmp/inbuxa upgrade --yes >/dev/null 2>&1 && bad "upgrade ran on nothing" || ok "upgrade has nothing to do"
|
|
|
|
echo
|
|
echo "==> installed again, on what was kept"
|
|
OUT="$(/tmp/inbuxa install --local --domain example.test --yes 2>&1)"; rc=$?
|
|
[ $rc -eq 0 ] && ok "install again (exit 0)" || { bad "reinstall exit $rc"; echo "$OUT" | tail -8 | sed 's/^/ /'; }
|
|
[ "$(containers)" = 3 ] && ok "three containers again" || bad "$(containers) containers"
|
|
for _ in $(seq 1 30); do signs_in && break; sleep 2; done
|
|
signs_in && ok "the same mailbox signs in: the data came back" || bad "the first mailbox no longer signs in"
|
|
/tmp/inbuxa status >/dev/null 2>&1 && ok "status: installed and in agreement" || bad "status after reinstall"
|
|
|
|
echo
|
|
echo "==> purged"
|
|
OUT="$(/tmp/inbuxa uninstall --purge --yes 2>&1)"; rc=$?
|
|
[ $rc -eq 0 ] && ok "purged (exit 0)" || { bad "purge exit $rc"; echo "$OUT" | tail -6 | sed 's/^/ /'; }
|
|
[ "$(containers)" = 0 ] && [ "$(volumes)" = 0 ] && ok "no containers, no volumes" || bad "containers $(containers), volumes $(volumes)"
|
|
[ "$(ls -A $DIR)" = backups ] && ok "only $DIR/backups is left" || bad "left in $DIR: $(ls -A $DIR | tr '\n' ' ')"
|
|
[ ! -f /etc/inbuxa/install.json ] && ok "the install record is gone" || bad "install.json is still there"
|
|
/tmp/inbuxa status 2>&1 | grep -q "Nothing is installed" && ok "status: nothing installed" || bad "status after purge"
|
|
|
|
echo
|
|
echo "==> $pass passed, $fail failed"
|
|
[ "$fail" -eq 0 ]
|