Files
faumaray d2e057988f
Modular container CI / release-build (push) Failing after 2s
Keep manifest fixtures on RelWithDebInfo
2026-08-01 18:37:46 +03:00

1015 lines
43 KiB
Bash
Executable File

#!/usr/bin/env bash
# shellcheck disable=SC1091,SC2034,SC2329
set -euo pipefail
SCRIPT_DIR=$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)
PACKAGING_DIR=$(cd -P -- "$SCRIPT_DIR/.." && pwd -P)
if [[ $(id -u) -eq 0 && ${ECHOION_INSTALLER_TEST_NONROOT:-0} != 1 ]]; then
command -v runuser >/dev/null 2>&1 ||
{
printf 'FAIL: runuser is required for root-run installer tests\n' >&2
exit 1
}
id nobody >/dev/null 2>&1 ||
{
printf 'FAIL: nobody account is required for root-run installer tests\n' >&2
exit 1
}
nonroot_parent=$(mktemp -d -- /opt/echoion-installer-test.XXXXXX)
trap 'rm -rf -- "$nonroot_parent"' EXIT
chown "$(id -u nobody):$(id -g nobody)" -- "$nonroot_parent"
runuser -u nobody -- env \
"ECHOION_INSTALLER_TEST_NONROOT=1" \
"ECHOION_INSTALLER_TEST_PARENT=$nonroot_parent" \
"PATH=$PATH" \
bash "$0"
exit
fi
TEST_ROOT_PARENT=${ECHOION_INSTALLER_TEST_PARENT:-$SCRIPT_DIR}
TEST_ROOT=$(mktemp -d -- "$TEST_ROOT_PARENT/.installer-test.XXXXXX")
trap 'rm -rf -- "$TEST_ROOT"' EXIT
fail() {
printf 'FAIL: %s\n' "$*" >&2
exit 1
}
assert_file() {
[[ -f $1 ]] || fail "missing file: $1"
}
assert_not_exists() {
[[ ! -e $1 ]] || fail "unexpected path: $1"
}
assert_contains() {
local path=$1
local text=$2
grep -F -- "$text" "$path" >/dev/null || fail "$path does not contain: $text"
}
assert_not_contains() {
local path=$1
local text=$2
if grep -F -- "$text" "$path" >/dev/null; then
fail "$path unexpectedly contains: $text"
fi
}
make_payload() {
local root=$1
install -d -- "$root/bin" "$root/lib" "$root/share/echoion/web" \
"$root/share/echoion/tools" "$root/share/echoion/certs" "$root/service" \
"$root/share/echoion/bootstrap-plugins/url-shortener-internal/1.0.0" \
"$root/share/echoion/bootstrap-plugins/url-shortener-external/1.0.0"
install -m 0755 -- "$PACKAGING_DIR/install.sh" "$root/install.sh"
install -m 0755 -- "$PACKAGING_DIR/uninstall.sh" "$root/uninstall.sh"
install -m 0644 -- "$PACKAGING_DIR/service/echoion.service.in" "$root/service/echoion.service.in"
install -m 0644 -- "$PACKAGING_DIR/service/echoion-updater.service.in" \
"$root/service/echoion-updater.service.in"
install -m 0644 -- "$PACKAGING_DIR/service/echoion-updater.timer.in" \
"$root/service/echoion-updater.timer.in"
install -m 0755 -- "$PACKAGING_DIR/../scripts/validate-release-manifest.py" \
"$root/share/echoion/tools/validate-release-manifest.py"
cat > "$root/bin/echoiond" <<'EOF'
#!/usr/bin/env bash
if [[ ${ALLOW_DAEMON_RUN:-0} == 1 ]]; then
printf 'ECHOION_HOME=%s\n' "${ECHOION_HOME:-}" >> "${DAEMON_LOG:?}"
printf 'ECHOION_CORE_PATH=%s\n' "${ECHOION_CORE_PATH:-}" >> "$DAEMON_LOG"
printf 'ECHOION_STATE_DIR=%s\n' "${ECHOION_STATE_DIR:-}" >> "$DAEMON_LOG"
printf 'ECHOION_INCOMING_DIR=%s\n' "${ECHOION_INCOMING_DIR:-}" >> "$DAEMON_LOG"
printf 'LD_LIBRARY_PATH=%s\n' "${LD_LIBRARY_PATH:-}" >> "$DAEMON_LOG"
printf 'PWD=%s\n' "$PWD" >> "$DAEMON_LOG"
argument_index=0
for argument in "$@"; do
printf 'ARG_%d=%s\n' "$argument_index" "$argument" >> "$DAEMON_LOG"
argument_index=$((argument_index + 1))
done
exit 0
fi
printf 'daemon unexpectedly ran\n' >> "${DAEMON_LOG:?}"
exit 1
EOF
chmod 0755 "$root/bin/echoiond"
cat > "$root/bin/echoion-updater" <<'EOF'
#!/usr/bin/env bash
printf 'updater unexpectedly ran\n' >> "${DAEMON_LOG:?}"
exit 1
EOF
chmod 0755 "$root/bin/echoion-updater"
printf 'fake dynamic core\n' > "$root/lib/Echoion.ts"
cat > "$root/share/echoion/config.example.json" <<'EOF'
{
"web": {
"webRoot": "./web",
"enabled": false
}
}
EOF
printf '<!doctype html>\n' > "$root/share/echoion/web/index.html"
printf 'test trust bundle\n' \
>"$root/share/echoion/certs/ca-certificates.crt"
printf 'fake internal shortener plugin 1.0.0\n' > \
"$root/share/echoion/bootstrap-plugins/url-shortener-internal/1.0.0/url-shortener-internal.so"
printf 'fake external shortener plugin 1.0.0\n' > \
"$root/share/echoion/bootstrap-plugins/url-shortener-external/1.0.0/url-shortener-external.so"
python3 "$PACKAGING_DIR/../scripts/generate-release-manifest.py" \
--root "$root" --version 1.2.3 \
--build-type RelWithDebInfo
}
fake_bin=$TEST_ROOT/fake-bin
home=$TEST_ROOT/home
install -d -- "$fake_bin" "$home"
REAL_MV=$(command -v mv)
export REAL_MV
cat > "$fake_bin/systemctl" <<'EOF'
#!/usr/bin/env bash
printf '%s\n' "$*" >> "${SYSTEMCTL_LOG:?}"
if [[ ${SYSTEMCTL_FAIL_RESTART:-0} == 1 && " $* " == *' restart '* ]]; then
exit 1
fi
if [[ ${SYSTEMCTL_FAIL_UPDATER_STOP:-0} == 1 &&
" $* " == *' stop echoion-updater.service '* ]]; then
exit 1
fi
exit 0
EOF
chmod 0755 "$fake_bin/systemctl"
cat > "$fake_bin/mv" <<'EOF'
#!/usr/bin/env bash
last=
for last in "$@"; do :; done
if [[ ${RECORD_COMMIT_FAIL:-0} == 1 && ${last##*/} == .echoion-install ]]; then
exit 73
fi
exec "${REAL_MV:?}" "$@"
EOF
chmod 0755 "$fake_bin/mv"
export PATH=$fake_bin:$PATH
export HOME=$home
export XDG_CONFIG_HOME=$home/.config
export XDG_STATE_HOME=$home/.state
export XDG_CACHE_HOME=$home/.cache
export SYSTEMCTL_LOG=$TEST_ROOT/systemctl.log
export DAEMON_LOG=$TEST_ROOT/daemon.log
: > "$SYSTEMCTL_LOG"
: > "$DAEMON_LOG"
bash -n "$PACKAGING_DIR/install.sh"
bash -n "$PACKAGING_DIR/uninstall.sh"
escaped_systemd_path=$(
# shellcheck source=../install.sh
source "$PACKAGING_DIR/install.sh"
systemd_path_escape '/srv/echoion path/%/dollar$'
)
[[ $escaped_systemd_path == '/srv/echoion\x20path/%%/dollar$' ]] ||
fail 'systemd path escaping did not preserve space, percent, and dollar characters'
escaped_systemd_path_controls=$(
# shellcheck source=../install.sh
source "$PACKAGING_DIR/install.sh"
systemd_path_escape $'/srv/line\ncarriage\rtab\tend'
)
[[ $escaped_systemd_path_controls == \
'/srv/line\x0acarriage\x0dtab\x09end' ]] ||
fail 'systemd path escaping emitted a raw control character'
escaped_systemd_setting_controls=$(
# shellcheck source=../install.sh
source "$PACKAGING_DIR/install.sh"
systemd_setting_escape $'line\ncarriage\rtab\tend'
)
[[ $escaped_systemd_setting_controls == 'line\ncarriage\rtab\tend' ]] ||
fail 'systemd setting escaping emitted a raw control character'
escaped_systemd_exec_dollar=$(
# shellcheck source=../install.sh
source "$PACKAGING_DIR/install.sh"
systemd_exec_escape "/srv/\$HOME/path"
)
[[ $escaped_systemd_exec_dollar == "/srv/\$\$HOME/path" ]] ||
fail 'systemd executable escaping did not protect a literal dollar variable'
escaped_json_controls=$(
# shellcheck source=../install.sh
source "$PACKAGING_DIR/install.sh"
json_escape $'line\ncarriage\rtab\tend'
)
[[ $escaped_json_controls == 'line\ncarriage\rtab\tend' ]] ||
fail 'JSON escaping emitted a raw control character'
trusted_parent=$TEST_ROOT/trusted-parent
trusted_prefix=$trusted_parent/echoion
install -d -m 0700 -- "$trusted_prefix"
(
# shellcheck source=../install.sh
source "$PACKAGING_DIR/install.sh"
validate_trusted_path_ancestors user "$trusted_prefix" "$(id -u)" 1
) || fail 'trusted user service prefix was rejected'
chmod 0770 "$trusted_parent"
if (
# shellcheck source=../install.sh
source "$PACKAGING_DIR/install.sh"
validate_trusted_path_ancestors user "$trusted_prefix" "$(id -u)" 1
) >/dev/null 2>&1; then
fail 'group-writable service prefix ancestor was accepted'
fi
chmod 0700 "$trusted_parent"
if (
# shellcheck source=../install.sh
source "$PACKAGING_DIR/install.sh"
validate_trusted_path_ancestors system "$trusted_prefix" 0 1
) >/dev/null 2>&1; then
fail 'non-root-owned system service prefix was accepted'
fi
if (
# shellcheck source=../install.sh
source "$PACKAGING_DIR/install.sh"
validate_registration_identity user 0
) >/dev/null 2>&1; then
fail 'root user-scope service registration was accepted'
fi
CHOWN_LOG=$TEST_ROOT/chown.log
export CHOWN_LOG
(
# shellcheck source=../install.sh
source "$PACKAGING_DIR/install.sh"
chown() { printf '%s\n' "$*" >> "$CHOWN_LOG"; }
find() { return 0; }
runuser() {
[[ " $* " == *' test -w '* ]] && return 1
return 0
}
normalize_and_validate_system_runtime "$trusted_prefix"
)
assert_contains "$CHOWN_LOG" '-R root:root'
USERDEL_LOG=$TEST_ROOT/userdel.log
export USERDEL_LOG
(
# shellcheck source=../install.sh
source "$PACKAGING_DIR/install.sh"
ACCOUNT_CREATED_THIS_RUN=1
ACCOUNT_IDENTITY_CAPTURED=1
SERVICE_UID=4242
SERVICE_GID=4343
MOCK_UID=4242
MOCK_GID=4343
id() {
case $1 in
-u) printf '%s\n' "$MOCK_UID" ;;
-g) printf '%s\n' "$MOCK_GID" ;;
esac
}
userdel() { printf '%s\n' "$*" >> "$USERDEL_LOG"; }
remove_new_system_user
)
assert_contains "$USERDEL_LOG" 'echoion'
: > "$USERDEL_LOG"
(
# shellcheck source=../install.sh
source "$PACKAGING_DIR/install.sh"
ACCOUNT_CREATED_THIS_RUN=1
ACCOUNT_IDENTITY_CAPTURED=1
SERVICE_UID=4242
SERVICE_GID=4343
MOCK_UID=9999
MOCK_GID=4343
id() {
case $1 in
-u) printf '%s\n' "$MOCK_UID" ;;
-g) printf '%s\n' "$MOCK_GID" ;;
esac
}
userdel() { printf '%s\n' "$*" >> "$USERDEL_LOG"; }
remove_new_system_user
) 2>/dev/null
[[ ! -s $USERDEL_LOG ]] || fail 'recreated service account was deleted'
symlink_prefix=$TEST_ROOT/symlink-versions
install -d -- "$symlink_prefix" "$TEST_ROOT/external-versions"
ln -s -- "$TEST_ROOT/external-versions" "$symlink_prefix/versions"
payload=$TEST_ROOT/payload
make_payload "$payload"
locked_prefix=$TEST_ROOT/locked-prefix
install -d -- "$locked_prefix"
exec {TEST_LOCK_FD}< "$locked_prefix"
flock -n "$TEST_LOCK_FD"
if "$payload/install.sh" --mode portable --prefix "$locked_prefix" \
--register-service none --non-interactive >/dev/null 2>&1; then
fail 'concurrent installer acquired an already-held prefix lock'
fi
flock -u "$TEST_LOCK_FD"
exec {TEST_LOCK_FD}<&-
assert_not_exists "$locked_prefix/versions/1.2.3"
metadata_prefix=$TEST_ROOT/metadata-rollback
metadata_config=$TEST_ROOT/metadata-config
metadata_state=$TEST_ROOT/metadata-state
install -d -m 0750 -- "$metadata_config"
install -d -m 0710 -- "$metadata_state"
printf '{}\n' > "$metadata_config/config.json"
chmod 0640 "$metadata_config/config.json"
config_metadata_before=$(stat -c '%u:%g:%a' -- "$metadata_config")
state_metadata_before=$(stat -c '%u:%g:%a' -- "$metadata_state")
file_metadata_before=$(stat -c '%u:%g:%a' -- "$metadata_config/config.json")
export RECORD_COMMIT_FAIL=1
if "$payload/install.sh" --mode portable --prefix "$metadata_prefix" \
--config-dir "$metadata_config" --state-dir "$metadata_state" \
--register-service none --non-interactive >/dev/null 2>&1; then
fail 'installer accepted injected post-metadata record failure'
fi
unset RECORD_COMMIT_FAIL
config_metadata_after=$(stat -c '%u:%g:%a' -- "$metadata_config")
state_metadata_after=$(stat -c '%u:%g:%a' -- "$metadata_state")
file_metadata_after=$(stat -c '%u:%g:%a' -- "$metadata_config/config.json")
[[ $config_metadata_after == "$config_metadata_before" ]] ||
fail 'failed install did not restore configuration directory uid/gid/mode'
[[ $state_metadata_after == "$state_metadata_before" ]] ||
fail 'failed install did not restore state directory uid/gid/mode'
[[ $file_metadata_after == "$file_metadata_before" ]] ||
fail 'failed install did not restore configuration file uid/gid/mode'
assert_not_exists "$metadata_prefix/versions/1.2.3"
runtime_root=$TEST_ROOT/runtime-directory
install -d -m 0700 -- "$runtime_root"
if XDG_RUNTIME_DIR=$runtime_root "$payload/install.sh" --mode portable \
--prefix "$runtime_root/echoion" --register-service user \
--non-interactive >/dev/null 2>&1; then
fail 'XDG runtime portable service prefix was accepted'
fi
unsafe_mutable_parent=$TEST_ROOT/group-writable-mutable
install -d -m 0770 -- "$unsafe_mutable_parent"
if "$payload/install.sh" --mode portable --prefix "$TEST_ROOT/mutable-trust-install" \
--config-dir "$unsafe_mutable_parent/config" \
--state-dir "$TEST_ROOT/mutable-trust-state" --register-service user \
--non-interactive >/dev/null 2>&1; then
fail 'group-writable mutable-path ancestor was accepted for a service'
fi
if "$payload/install.sh" --mode portable --prefix "$symlink_prefix" \
--register-service none --non-interactive >/dev/null 2>&1; then
fail 'symlinked versions directory was accepted'
fi
bad_payload=$TEST_ROOT/bad-payload
make_payload "$bad_payload"
sed -i 's/"schemaVersion": 2/"schemaVersion": 1/' "$bad_payload/manifest.json"
if "$bad_payload/install.sh" --mode portable --prefix "$TEST_ROOT/bad-install" \
--register-service none --non-interactive >/dev/null 2>&1; then
fail 'legacy payload manifest was accepted'
fi
self_prefix=$TEST_ROOT/self-contained
"$payload/install.sh" --mode portable --prefix "$self_prefix" \
--data-layout self-contained --register-service none --non-interactive
[[ $(readlink -- "$self_prefix/current") == versions/1.2.3 ]] || fail 'wrong current target'
assert_file "$self_prefix/versions/1.2.3/bin/echoiond"
assert_file "$self_prefix/versions/1.2.3/bin/echoion-updater"
assert_file "$self_prefix/libexec/updater/1.2.3/bin/echoion-updater"
[[ -d $self_prefix/libexec/updater/1.2.3/lib ]] ||
fail 'privileged updater has no private dynamic library closure'
assert_file "$self_prefix/config/config.json"
assert_file "$self_prefix/state/plugins/.managed/url-shortener-internal/versions/1.0.0/url-shortener-internal.so"
assert_file "$self_prefix/state/plugins/.managed/url-shortener-external/versions/1.0.0/url-shortener-external.so"
[[ -d $self_prefix/state/plugins/.managed/url-shortener-internal/staging ]] ||
fail 'internal shortener managed staging directory was not created'
[[ $(readlink -- "$self_prefix/state/plugins/.managed/url-shortener-internal/current") == versions/1.0.0 ]] ||
fail 'internal shortener bootstrap did not select its bundled version'
[[ $(readlink -- "$self_prefix/state/plugins/.managed/url-shortener-external/current") == versions/1.0.0 ]] ||
fail 'external shortener bootstrap did not select its bundled version'
[[ -d $self_prefix/config/plugins.d ]] ||
fail 'per-plugin configuration directory was not created'
assert_file "$self_prefix/install.json"
[[ -d $self_prefix/state && -d $self_prefix/cache && -d $self_prefix/logs &&
-d $self_prefix/incoming ]] || fail 'single-root mutable layout is incomplete'
[[ -x $self_prefix/echoion ]] || fail 'portable launcher is not executable'
assert_contains "$self_prefix/.echoion-install" 'relocatable=1'
assert_contains "$self_prefix/.echoion-install" 'prefix=.'
assert_contains "$self_prefix/.echoion-install" 'config_dir=config'
assert_contains "$self_prefix/.echoion-install" 'state_dir=state'
assert_contains "$self_prefix/.echoion-install" 'launcher=echoion'
assert_contains "$self_prefix/.echoion-install" \
'updater_helper=libexec/updater/1.2.3/bin/echoion-updater'
assert_contains "$self_prefix/install.json" \
'"privilegedHelper": "libexec/updater/1.2.3/bin/echoion-updater"'
assert_contains "$self_prefix/config/config.json" \
'"webRoot": "./share/echoion/web"'
assert_not_contains "$self_prefix/config/config.json" "$self_prefix/current"
[[ ! -s $SYSTEMCTL_LOG ]] || fail 'service command ran for register-service none'
[[ ! -s $DAEMON_LOG ]] || fail 'daemon ran during installation'
self_moved_prefix=$TEST_ROOT/self-contained-moved
mv -- "$self_prefix" "$self_moved_prefix"
assert_not_exists "$self_prefix"
: > "$DAEMON_LOG"
ALLOW_DAEMON_RUN=1 "$self_moved_prefix/echoion" --probe 'two words'
assert_contains "$DAEMON_LOG" "ECHOION_HOME=$self_moved_prefix/current"
assert_contains "$DAEMON_LOG" "ECHOION_CORE_PATH=$self_moved_prefix/current/lib/Echoion.ts"
assert_contains "$DAEMON_LOG" "ECHOION_STATE_DIR=$self_moved_prefix/state"
assert_contains "$DAEMON_LOG" "ECHOION_INCOMING_DIR=$self_moved_prefix/incoming"
assert_contains "$DAEMON_LOG" \
"LD_LIBRARY_PATH=$self_moved_prefix/current/lib"
assert_contains "$DAEMON_LOG" "PWD=$self_moved_prefix/current"
assert_contains "$DAEMON_LOG" 'ARG_0=--config'
assert_contains "$DAEMON_LOG" "ARG_1=$self_moved_prefix/config/config.json"
assert_contains "$DAEMON_LOG" 'ARG_2=--state-dir'
assert_contains "$DAEMON_LOG" "ARG_3=$self_moved_prefix/state"
assert_contains "$DAEMON_LOG" 'ARG_4=--probe'
assert_contains "$DAEMON_LOG" 'ARG_5=two words'
: > "$DAEMON_LOG"
if ALLOW_DAEMON_RUN=1 "$self_moved_prefix/echoion" --config /tmp/override \
>/dev/null 2>&1; then
fail 'portable launcher accepted a managed config override'
fi
[[ ! -s $DAEMON_LOG ]] || fail 'portable launcher executed daemon after rejected override'
"$self_moved_prefix/uninstall.sh" --purge --non-interactive >/dev/null
assert_not_exists "$self_moved_prefix"
dots_prefix=$TEST_ROOT/consecutive-dot-version
dots_payload=$TEST_ROOT/consecutive-dot-payload
dots_upgrade_payload=$TEST_ROOT/consecutive-dot-upgrade-payload
cp -a -- "$payload" "$dots_payload"
sed -i 's/"version": "1.2.3"/"version": "1.0..rc1"/' "$dots_payload/manifest.json"
cp -a -- "$dots_payload" "$dots_upgrade_payload"
sed -i 's/"version": "1.0..rc1"/"version": "1.0..rc2"/' \
"$dots_upgrade_payload/manifest.json"
"$dots_payload/install.sh" --mode portable --prefix "$dots_prefix" \
--data-layout self-contained --register-service none --non-interactive >/dev/null
"$dots_upgrade_payload/install.sh" --mode portable --prefix "$dots_prefix" \
--data-layout self-contained --register-service none --non-interactive >/dev/null
[[ $(readlink -- "$dots_prefix/current") == versions/1.0..rc2 ]] ||
fail 'legal consecutive-dot version did not upgrade'
"$dots_prefix/uninstall.sh" --purge --non-interactive >/dev/null
assert_not_exists "$dots_prefix"
custom_prefix=$TEST_ROOT/custom-purge-install
custom_config=$TEST_ROOT/custom-configuration
custom_state=$TEST_ROOT/custom-runtime-state
"$payload/install.sh" --mode portable --prefix "$custom_prefix" \
--config-dir "$custom_config" --state-dir "$custom_state" \
--register-service none --non-interactive >/dev/null
assert_file "$custom_config/.echoion-managed"
assert_file "$custom_state/.echoion-managed"
assert_contains "$custom_prefix/.echoion-install" 'config_purge_allowed=1'
assert_contains "$custom_prefix/.echoion-install" 'state_purge_allowed=1'
exec {TEST_LOCK_FD}< "$custom_prefix"
flock -n "$TEST_LOCK_FD"
if "$custom_prefix/uninstall.sh" --purge --non-interactive >/dev/null 2>&1; then
fail 'concurrent uninstaller acquired an already-held prefix lock'
fi
assert_file "$custom_prefix/current/bin/echoiond"
flock -u "$TEST_LOCK_FD"
exec {TEST_LOCK_FD}<&-
"$custom_prefix/uninstall.sh" --purge --non-interactive >/dev/null
assert_not_exists "$custom_prefix"
assert_not_exists "$custom_config"
assert_not_exists "$custom_state"
unit=$XDG_CONFIG_HOME/systemd/user/echoion.service
updater_unit=$XDG_CONFIG_HOME/systemd/user/echoion-updater.service
updater_timer=$XDG_CONFIG_HOME/systemd/user/echoion-updater.timer
self_service_prefix=$TEST_ROOT/portable-self-contained-service
: > "$SYSTEMCTL_LOG"
: > "$DAEMON_LOG"
"$payload/install.sh" --mode portable --prefix "$self_service_prefix" \
--data-layout self-contained --register-service user --non-interactive
assert_file "$unit"
assert_file "$updater_unit"
assert_file "$updater_timer"
assert_file "$self_service_prefix/config/config.json"
[[ -d $self_service_prefix/state && -d $self_service_prefix/cache &&
-d $self_service_prefix/logs && -d $self_service_prefix/incoming ]] ||
fail 'self-contained service mutable layout escaped the portable prefix'
assert_contains "$unit" "WorkingDirectory=$self_service_prefix/current"
assert_contains "$unit" "Environment=\"ECHOION_STATE_DIR=$self_service_prefix/state\""
assert_contains "$unit" \
"Environment=\"ECHOION_INCOMING_DIR=$self_service_prefix/incoming\""
assert_contains "$unit" \
"Environment=\"LD_LIBRARY_PATH=$self_service_prefix/current/lib\""
assert_contains "$unit" \
"--config \"$self_service_prefix/config/config.json\" --state-dir \"$self_service_prefix/state\""
assert_contains "$updater_unit" \
"WorkingDirectory=$self_service_prefix"
assert_contains "$SYSTEMCTL_LOG" '--user daemon-reload'
assert_contains "$SYSTEMCTL_LOG" '--user stop echoion-updater.service'
assert_contains "$SYSTEMCTL_LOG" \
'--user disable --now echoion.service echoion-updater.timer'
if grep -E -- '(^| )(enable|restart|start)( |$)' "$SYSTEMCTL_LOG" >/dev/null; then
fail 'self-contained portable service was activated without --start'
fi
[[ ! -s $DAEMON_LOG ]] ||
fail 'daemon or updater ran during self-contained service registration'
"$self_service_prefix/uninstall.sh" --purge --non-interactive >/dev/null
assert_not_exists "$unit"
assert_not_exists "$updater_unit"
assert_not_exists "$updater_timer"
assert_not_exists "$self_service_prefix"
service_prefix="$TEST_ROOT/portable path % dollar\$"
: > "$SYSTEMCTL_LOG"
"$payload/install.sh" --mode portable --prefix "$service_prefix" \
--data-layout standard --register-service user --non-interactive
assert_file "$unit"
assert_file "$updater_unit"
assert_file "$updater_timer"
assert_contains "$unit" 'WorkingDirectory='
assert_not_contains "$unit" 'WorkingDirectory="'
assert_contains "$unit" 'portable\x20path\x20%%\x20dollar$/current'
assert_contains "$unit" 'ExecStart="'
assert_contains "$unit" 'portable path %% dollar$$/current/bin/echoiond"'
assert_contains "$unit" 'Environment="ECHOION_HOME='
assert_contains "$unit" 'Environment="ECHOION_CORE_PATH='
assert_contains "$unit" 'Environment="ECHOION_STATE_DIR='
assert_contains "$unit" 'Environment="ECHOION_INCOMING_DIR='
assert_contains "$unit" 'Environment="LD_LIBRARY_PATH='
assert_contains "$unit" '--config "'
assert_contains "$unit" '--state-dir "'
assert_contains "$updater_unit" \
'portable path %% dollar$$/libexec/updater/1.2.3/bin/echoion-updater"'
assert_not_contains "$updater_unit" '/current/bin/echoion-updater'
assert_contains "$updater_unit" \
'WorkingDirectory='"$TEST_ROOT"'/portable\x20path\x20%%\x20dollar$'
assert_not_contains "$updater_unit" 'WorkingDirectory="'
if grep -E '@[A-Z_]+@' "$unit" >/dev/null; then
fail 'generated systemd unit contains an unresolved template marker'
fi
if grep -E '@[A-Z_]+@' "$updater_unit" "$updater_timer" >/dev/null; then
fail 'generated updater unit contains an unresolved template marker'
fi
if command -v systemd-analyze >/dev/null 2>&1; then
verify_log=$TEST_ROOT/systemd-verify.log
if ! systemd-analyze verify "$unit" "$updater_unit" "$updater_timer" \
2> "$verify_log" &&
grep -E 'not absolute|Unknown escape|Failed to parse|Invalid argument|fatal error|bad unit file setting|Failed to load unit' \
"$verify_log" >/dev/null; then
cat "$verify_log" >&2
fail 'generated systemd units did not verify'
fi
fi
assert_contains "$SYSTEMCTL_LOG" '--user daemon-reload'
assert_contains "$SYSTEMCTL_LOG" '--user stop echoion-updater.service'
assert_contains "$SYSTEMCTL_LOG" '--user disable --now echoion.service'
if grep -E -- '(^| )enable( |$)|(^| )restart( |$)' "$SYSTEMCTL_LOG" >/dev/null; then
fail 'service was activated without --start'
fi
[[ ! -s $DAEMON_LOG ]] || fail 'daemon ran during service registration'
command -v fakeroot >/dev/null 2>&1 ||
fail 'fakeroot is required for rootless system-service installer coverage'
system_fake_bin=$TEST_ROOT/system-fake-bin
system_payload=$TEST_ROOT/system-payload
system_service_prefix="$TEST_ROOT/portable system % dollar\$"
system_unit_root=$TEST_ROOT/systemd/system
install -d -- "$system_fake_bin" "$system_service_prefix" "$system_unit_root"
make_payload "$system_payload"
sed -i "s#/etc/systemd/system#$system_unit_root#g" \
"$system_payload/install.sh"
python3 "$PACKAGING_DIR/../scripts/generate-release-manifest.py" \
--root "$system_payload" --version 1.2.3 \
--build-type RelWithDebInfo
REAL_CHOWN=$(command -v chown)
REAL_CP=$(command -v cp)
REAL_GETENT=$(command -v getent)
REAL_ID=$(command -v id)
export REAL_CHOWN REAL_CP REAL_GETENT REAL_ID
export SYSTEM_SERVICE_PREFIX=$system_service_prefix
cat > "$system_fake_bin/chown" <<'EOF'
#!/usr/bin/env bash
arguments=()
for argument in "$@"; do
case $argument in
echoion:echoion) arguments+=(4242:4242) ;;
root:echoion) arguments+=(0:4242) ;;
*) arguments+=("$argument") ;;
esac
done
"${REAL_CHOWN:?}" "${arguments[@]}" 2>/dev/null || true
EOF
cat > "$system_fake_bin/cp" <<'EOF'
#!/usr/bin/env bash
arguments=()
for argument in "$@"; do
if [[ $argument == -a ]]; then
arguments+=(-R --preserve=mode,timestamps,links)
else
arguments+=("$argument")
fi
done
exec "${REAL_CP:?}" "${arguments[@]}"
EOF
cat > "$system_fake_bin/getent" <<'EOF'
#!/usr/bin/env bash
case ${1:-}:${2:-} in
passwd:echoion) printf 'echoion:x:4242:4242::/nonexistent:/usr/sbin/nologin\n' ;;
group:echoion) printf 'echoion:x:4242:\n' ;;
*) exec "${REAL_GETENT:?}" "$@" ;;
esac
EOF
cat > "$system_fake_bin/id" <<'EOF'
#!/usr/bin/env bash
case ${1:-}:${2:-} in
-u:echoion | -g:echoion) printf '4242\n' ;;
*) exec "${REAL_ID:?}" "$@" ;;
esac
EOF
cat > "$system_fake_bin/runuser" <<'EOF'
#!/usr/bin/env bash
[[ ${1:-} == -u && ${2:-} == echoion && ${3:-} == -- ]] || exit 64
shift 3
if [[ ${1:-} == find ]]; then
exit 0
fi
if [[ ${1:-} == test && ${2:-} == -w ]]; then
case ${3:-} in
"${SYSTEM_SERVICE_PREFIX:?}/state" | "${SYSTEM_SERVICE_PREFIX:?}/state"/* | \
"${SYSTEM_SERVICE_PREFIX:?}/cache" | "${SYSTEM_SERVICE_PREFIX:?}/logs" | \
"${SYSTEM_SERVICE_PREFIX:?}/incoming") exit 0 ;;
*) exit 1 ;;
esac
fi
exec "$@"
EOF
chmod 0755 "$system_fake_bin/chown" "$system_fake_bin/cp" \
"$system_fake_bin/getent" "$system_fake_bin/id" "$system_fake_bin/runuser"
: > "$SYSTEMCTL_LOG"
: > "$DAEMON_LOG"
# shellcheck disable=SC2016 # Expanded by the fakeroot child shell.
SYSTEM_PAYLOAD=$system_payload PATH=$system_fake_bin:$PATH fakeroot -- \
bash -euo pipefail -c '
current=${SYSTEM_SERVICE_PREFIX:?}
while :; do
chown root:root -- "$current"
[[ $current == / ]] && break
current=$(dirname -- "$current")
done
"${SYSTEM_PAYLOAD:?}/install.sh" --mode portable \
--prefix "$SYSTEM_SERVICE_PREFIX" --data-layout self-contained \
--register-service system --non-interactive
'
system_unit=$system_unit_root/echoion.service
system_updater_unit=$system_unit_root/echoion-updater.service
system_updater_timer=$system_unit_root/echoion-updater.timer
assert_file "$system_unit"
assert_file "$system_updater_unit"
assert_file "$system_updater_timer"
assert_contains "$system_unit" 'User=echoion'
assert_contains "$system_unit" 'Group=echoion'
assert_contains "$system_unit" 'WantedBy=multi-user.target'
assert_contains "$system_unit" \
'portable\x20system\x20%%\x20dollar$/current'
assert_not_contains "$system_unit" 'WorkingDirectory="'
assert_contains "$system_updater_unit" \
'WorkingDirectory='"$TEST_ROOT"'/portable\x20system\x20%%\x20dollar$'
assert_contains "$system_updater_unit" 'ReadWritePaths='
assert_contains "$system_updater_unit" \
'portable\x20system\x20%%\x20dollar$'
assert_not_contains "$system_updater_unit" 'ReadWritePaths="'
assert_contains "$SYSTEMCTL_LOG" 'daemon-reload'
assert_contains "$SYSTEMCTL_LOG" 'stop echoion-updater.service'
assert_contains "$SYSTEMCTL_LOG" \
'disable --now echoion.service echoion-updater.timer'
assert_not_contains "$SYSTEMCTL_LOG" '--user'
if grep -E -- '(^| )(enable|restart|start)( |$)' "$SYSTEMCTL_LOG" >/dev/null; then
fail 'portable system service was activated without --start'
fi
[[ ! -s $DAEMON_LOG ]] ||
fail 'daemon or updater ran during portable system service registration'
if command -v systemd-analyze >/dev/null 2>&1; then
verify_log=$TEST_ROOT/system-systemd-verify.log
if ! systemd-analyze verify "$system_unit" "$system_updater_unit" \
"$system_updater_timer" 2> "$verify_log" &&
grep -E 'not absolute|Unknown escape|Failed to parse|Invalid argument|fatal error|bad unit file setting|Failed to load unit' \
"$verify_log" >/dev/null; then
cat "$verify_log" >&2
fail 'generated system-scope systemd units did not verify'
fi
fi
: > "$SYSTEMCTL_LOG"
"$payload/install.sh" --mode portable --prefix "$service_prefix" \
--data-layout standard --register-service user --start --non-interactive
assert_contains "$SYSTEMCTL_LOG" '--user enable echoion.service'
assert_contains "$SYSTEMCTL_LOG" 'echoion-updater.timer'
assert_contains "$SYSTEMCTL_LOG" '--user restart echoion.service'
assert_contains "$SYSTEMCTL_LOG" '--user start echoion-updater.timer'
assert_contains "$SYSTEMCTL_LOG" '--user is-active --quiet echoion.service'
: > "$SYSTEMCTL_LOG"
export SYSTEMCTL_FAIL_UPDATER_STOP=1
if "$service_prefix/uninstall.sh" --non-interactive >/dev/null 2>&1; then
fail 'uninstaller continued after the updater service could not be stopped'
fi
unset SYSTEMCTL_FAIL_UPDATER_STOP
assert_file "$service_prefix/current/bin/echoiond"
assert_file "$unit"
: > "$SYSTEMCTL_LOG"
"$service_prefix/uninstall.sh" --non-interactive
assert_contains "$SYSTEMCTL_LOG" '--user stop echoion-updater.service'
assert_not_exists "$unit"
assert_not_exists "$updater_unit"
assert_not_exists "$updater_timer"
assert_not_exists "$service_prefix/versions"
assert_file "$XDG_CONFIG_HOME/echoion/config.json"
[[ -d $XDG_STATE_HOME/echoion ]] || fail 'state directory was not preserved'
purge_retry_prefix=$TEST_ROOT/purge-retry
purge_retry_config=$TEST_ROOT/purge-retry-config
purge_retry_state=$TEST_ROOT/purge-retry-state
"$payload/install.sh" --mode portable --prefix "$purge_retry_prefix" \
--config-dir "$purge_retry_config" --state-dir "$purge_retry_state" \
--register-service user --non-interactive >/dev/null
marker_backup=$TEST_ROOT/config-marker.backup
cp -a -- "$purge_retry_config/.echoion-managed" "$marker_backup"
printf 'tampered\n' >> "$purge_retry_config/.echoion-managed"
if "$purge_retry_prefix/uninstall.sh" --purge --non-interactive >/dev/null 2>&1; then
fail 'purge accepted a modified ownership marker'
fi
assert_file "$unit"
assert_file "$purge_retry_prefix/current/bin/echoiond"
assert_file "$purge_retry_prefix/.echoion-install"
cp -a -- "$marker_backup" "$purge_retry_config/.echoion-managed"
"$purge_retry_prefix/uninstall.sh" --purge --non-interactive >/dev/null
assert_not_exists "$unit"
assert_not_exists "$purge_retry_prefix"
assert_not_exists "$purge_retry_config"
assert_not_exists "$purge_retry_state"
rollback_prefix=$TEST_ROOT/rollback
"$payload/install.sh" --mode portable --prefix "$rollback_prefix" \
--register-service user --non-interactive >/dev/null
old_unit_hash=$(sha256sum -- "$unit")
old_unit_hash=${old_unit_hash%% *}
old_updater_helper_hash=$(sha256sum -- \
"$rollback_prefix/libexec/updater/1.2.3/bin/echoion-updater")
old_updater_helper_hash=${old_updater_helper_hash%% *}
upgrade_payload=$TEST_ROOT/upgrade-payload
cp -a -- "$payload" "$upgrade_payload"
sed -i 's/"version": "1.2.3"/"version": "1.2.4"/' "$upgrade_payload/manifest.json"
for plugin_id in url-shortener-internal url-shortener-external; do
mv -- "$upgrade_payload/share/echoion/bootstrap-plugins/$plugin_id/1.0.0" \
"$upgrade_payload/share/echoion/bootstrap-plugins/$plugin_id/1.1.0"
printf 'fake %s plugin 1.1.0\n' "$plugin_id" > \
"$upgrade_payload/share/echoion/bootstrap-plugins/$plugin_id/1.1.0/$plugin_id.so"
done
printf '# changed in 1.2.4\n' >> "$upgrade_payload/service/echoion.service.in"
printf '# changed installer helper in 1.2.4\n' >> "$upgrade_payload/install.sh"
printf '# changed uninstaller helper in 1.2.4\n' >> "$upgrade_payload/uninstall.sh"
printf '# changed privileged updater helper in 1.2.4\n' >> \
"$upgrade_payload/bin/echoion-updater"
python3 "$PACKAGING_DIR/../scripts/generate-release-manifest.py" \
--root "$upgrade_payload" --version 1.2.4 \
--build-type RelWithDebInfo
v2_payload=$TEST_ROOT/v2-payload
cp -a -- "$upgrade_payload" "$v2_payload"
sed -i 's/"version": "1.2.4"/"version": "2.0.0"/' \
"$v2_payload/manifest.json"
python3 "$PACKAGING_DIR/../scripts/generate-release-manifest.py" \
--root "$v2_payload" --version 2.0.0 \
--build-type RelWithDebInfo
legacy_migration_prefix=$TEST_ROOT/legacy-migration
legacy_config_home=$TEST_ROOT/legacy-home
XDG_CONFIG_HOME=$legacy_config_home \
"$payload/install.sh" --mode portable --prefix "$legacy_migration_prefix" \
--register-service user --non-interactive >/dev/null
printf 'preserved database bytes\n' \
>"$legacy_migration_prefix/state/echoion.db"
legacy_tree_hash=$(sha256sum -- \
"$legacy_migration_prefix/current/bin/echoiond")
legacy_tree_hash=${legacy_tree_hash%% *}
: >"$SYSTEMCTL_LOG"
XDG_CONFIG_HOME=$legacy_config_home \
"$v2_payload/install.sh" --mode portable --prefix "$legacy_migration_prefix" \
--register-service user --non-interactive >/dev/null
[[ $(readlink -- "$legacy_migration_prefix/current") == versions/2.0.0 ]] ||
fail 'v1 migration did not activate the initial v2 generation'
assert_file "$legacy_migration_prefix/legacy/v1/tree/bin/echoiond"
archived_tree_hash=$(sha256sum -- \
"$legacy_migration_prefix/legacy/v1/tree/bin/echoiond")
archived_tree_hash=${archived_tree_hash%% *}
[[ $archived_tree_hash == "$legacy_tree_hash" ]] ||
fail 'v1 migration did not preserve the complete legacy executable tree'
assert_file "$legacy_migration_prefix/legacy/v1/service/echoion.service"
assert_file \
"$legacy_migration_prefix/state/updates/pending-install-generation"
assert_file "$legacy_migration_prefix/state/echoion.db"
assert_contains "$legacy_migration_prefix/.echoion-install" \
'legacy_rollback=legacy/v1'
assert_contains "$SYSTEMCTL_LOG" '--user stop echoion.service'
"$legacy_migration_prefix/uninstall.sh" --purge --non-interactive >/dev/null
bootstrap_upgrade_prefix=$TEST_ROOT/bootstrap-upgrade
"$payload/install.sh" --mode portable --prefix "$bootstrap_upgrade_prefix" \
--register-service none --non-interactive >/dev/null
install -d -- \
"$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/versions/9.0.0" \
"$bootstrap_upgrade_prefix/state/plugins/data/url-shortener-internal"
printf 'custom internal plugin\n' > \
"$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/versions/9.0.0/url-shortener-internal.so"
rm -f -- \
"$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/current"
ln -s -- versions/9.0.0 \
"$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/current"
printf '{"allowHttp":false}\n' > \
"$bootstrap_upgrade_prefix/config/plugins.d/url-shortener-internal.json"
printf 'persistent sqlite bytes\n' > \
"$bootstrap_upgrade_prefix/state/plugins/data/url-shortener-internal/links.db"
"$upgrade_payload/install.sh" --mode portable --prefix "$bootstrap_upgrade_prefix" \
--register-service none --non-interactive >/dev/null
# Installing the exact release twice must be a no-op for managed plugin state.
"$upgrade_payload/install.sh" --mode portable --prefix "$bootstrap_upgrade_prefix" \
--register-service none --non-interactive >/dev/null
[[ $(readlink -- "$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/current") == versions/9.0.0 ]] ||
fail 'upgrade replaced a custom active internal shortener version'
[[ $(readlink -- "$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-external/current") == versions/1.0.0 ]] ||
fail 'upgrade changed an existing external shortener selection'
assert_file "$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/versions/1.1.0/url-shortener-internal.so"
assert_file "$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-external/versions/1.1.0/url-shortener-external.so"
assert_contains \
"$bootstrap_upgrade_prefix/config/plugins.d/url-shortener-internal.json" \
'"allowHttp":false'
assert_contains \
"$bootstrap_upgrade_prefix/state/plugins/data/url-shortener-internal/links.db" \
'persistent sqlite bytes'
"$bootstrap_upgrade_prefix/uninstall.sh" --purge --non-interactive >/dev/null
assert_not_exists "$bootstrap_upgrade_prefix"
missing_plugin_current_prefix=$TEST_ROOT/missing-plugin-current
"$payload/install.sh" --mode portable --prefix "$missing_plugin_current_prefix" \
--register-service none --non-interactive >/dev/null
rm -f -- \
"$missing_plugin_current_prefix/state/plugins/.managed/url-shortener-internal/current"
sed -i 's#\./share/echoion/web#./web#' \
"$missing_plugin_current_prefix/config/config.json"
export RECORD_COMMIT_FAIL=1
if "$payload/install.sh" --mode portable --prefix "$missing_plugin_current_prefix" \
--register-service none --non-interactive >/dev/null 2>&1; then
fail 'missing plugin selection upgrade accepted a failed record commit'
fi
unset RECORD_COMMIT_FAIL
assert_not_exists \
"$missing_plugin_current_prefix/state/plugins/.managed/url-shortener-internal/current"
assert_contains "$missing_plugin_current_prefix/config/config.json" \
'"webRoot": "./web"'
"$payload/install.sh" --mode portable --prefix "$missing_plugin_current_prefix" \
--register-service none --non-interactive >/dev/null
[[ $(readlink -- \
"$missing_plugin_current_prefix/state/plugins/.managed/url-shortener-internal/current") == \
versions/1.0.0 ]] ||
fail 'reinstall did not initialize a missing managed plugin selection'
assert_contains "$missing_plugin_current_prefix/config/config.json" \
'"webRoot": "./share/echoion/web"'
sed -i 's#\./share/echoion/web#/srv/custom-echoion-web#' \
"$missing_plugin_current_prefix/config/config.json"
"$payload/install.sh" --mode portable --prefix "$missing_plugin_current_prefix" \
--register-service none --non-interactive >/dev/null
assert_contains "$missing_plugin_current_prefix/config/config.json" \
'"webRoot": "/srv/custom-echoion-web"'
"$missing_plugin_current_prefix/uninstall.sh" --purge --non-interactive >/dev/null
assert_not_exists "$missing_plugin_current_prefix"
export SYSTEMCTL_FAIL_RESTART=1
if "$upgrade_payload/install.sh" --mode portable --prefix "$rollback_prefix" \
--register-service user --start --non-interactive >/dev/null 2>&1; then
fail 'installer accepted a failed service restart'
fi
unset SYSTEMCTL_FAIL_RESTART
[[ $(readlink -- "$rollback_prefix/current") == versions/1.2.3 ]] ||
fail 'failed service upgrade did not restore current'
restored_unit_hash=$(sha256sum -- "$unit")
restored_unit_hash=${restored_unit_hash%% *}
[[ $restored_unit_hash == "$old_unit_hash" ]] || fail 'failed upgrade did not restore unit bytes'
restored_updater_helper_hash=$(sha256sum -- \
"$rollback_prefix/libexec/updater/1.2.3/bin/echoion-updater")
restored_updater_helper_hash=${restored_updater_helper_hash%% *}
[[ $restored_updater_helper_hash == "$old_updater_helper_hash" ]] ||
fail 'failed upgrade did not restore the privileged updater helper'
assert_contains "$rollback_prefix/.echoion-install" 'version=1.2.3'
assert_not_exists \
"$rollback_prefix/state/plugins/.managed/url-shortener-internal/versions/1.1.0"
"$rollback_prefix/uninstall.sh" --non-interactive >/dev/null
record_rollback_prefix=$TEST_ROOT/record-rollback
"$payload/install.sh" --mode portable --prefix "$record_rollback_prefix" \
--register-service user --non-interactive >/dev/null
record_old_unit_hash=$(sha256sum -- "$unit")
record_old_unit_hash=${record_old_unit_hash%% *}
record_old_install_hash=$(sha256sum -- "$record_rollback_prefix/install.sh")
record_old_install_hash=${record_old_install_hash%% *}
record_old_uninstall_hash=$(sha256sum -- "$record_rollback_prefix/uninstall.sh")
record_old_uninstall_hash=${record_old_uninstall_hash%% *}
record_old_updater_helper_hash=$(sha256sum -- \
"$record_rollback_prefix/libexec/updater/1.2.3/bin/echoion-updater")
record_old_updater_helper_hash=${record_old_updater_helper_hash%% *}
export RECORD_COMMIT_FAIL=1
if "$upgrade_payload/install.sh" --mode portable --prefix "$record_rollback_prefix" \
--register-service user --non-interactive >/dev/null 2>&1; then
fail 'installer accepted a failed atomic record commit'
fi
unset RECORD_COMMIT_FAIL
[[ $(readlink -- "$record_rollback_prefix/current") == versions/1.2.3 ]] ||
fail 'record-commit failure did not restore current'
record_restored_unit_hash=$(sha256sum -- "$unit")
record_restored_unit_hash=${record_restored_unit_hash%% *}
[[ $record_restored_unit_hash == "$record_old_unit_hash" ]] ||
fail 'record-commit failure did not restore unit bytes'
assert_contains "$record_rollback_prefix/.echoion-install" 'version=1.2.3'
assert_not_exists "$record_rollback_prefix/versions/1.2.4"
assert_not_exists \
"$record_rollback_prefix/state/plugins/.managed/url-shortener-internal/versions/1.1.0"
record_restored_install_hash=$(sha256sum -- "$record_rollback_prefix/install.sh")
record_restored_install_hash=${record_restored_install_hash%% *}
record_restored_uninstall_hash=$(sha256sum -- "$record_rollback_prefix/uninstall.sh")
record_restored_uninstall_hash=${record_restored_uninstall_hash%% *}
[[ $record_restored_install_hash == "$record_old_install_hash" ]] ||
fail 'record-commit failure did not restore installer helper bytes'
[[ $record_restored_uninstall_hash == "$record_old_uninstall_hash" ]] ||
fail 'record-commit failure did not restore uninstaller helper bytes'
record_restored_updater_helper_hash=$(sha256sum -- \
"$record_rollback_prefix/libexec/updater/1.2.3/bin/echoion-updater")
record_restored_updater_helper_hash=${record_restored_updater_helper_hash%% *}
[[ $record_restored_updater_helper_hash == "$record_old_updater_helper_hash" ]] ||
fail 'record-commit failure did not restore privileged updater helper bytes'
"$record_rollback_prefix/uninstall.sh" --non-interactive >/dev/null
scope_rollback_prefix=$TEST_ROOT/scope-rollback
"$payload/install.sh" --mode portable --prefix "$scope_rollback_prefix" \
--register-service user --non-interactive >/dev/null
scope_old_unit_hash=$(sha256sum -- "$unit")
scope_old_unit_hash=${scope_old_unit_hash%% *}
export RECORD_COMMIT_FAIL=1
if "$upgrade_payload/install.sh" --mode portable --prefix "$scope_rollback_prefix" \
--register-service none --non-interactive >/dev/null 2>&1; then
fail 'scope migration accepted a failed record commit'
fi
unset RECORD_COMMIT_FAIL
assert_file "$unit"
scope_restored_unit_hash=$(sha256sum -- "$unit")
scope_restored_unit_hash=${scope_restored_unit_hash%% *}
[[ $scope_restored_unit_hash == "$scope_old_unit_hash" ]] ||
fail 'scope migration failure did not restore old unit bytes'
[[ $(readlink -- "$scope_rollback_prefix/current") == versions/1.2.3 ]] ||
fail 'scope migration failure did not restore current'
assert_contains "$scope_rollback_prefix/.echoion-install" 'service_scope=user'
assert_not_exists \
"$scope_rollback_prefix/state/plugins/.managed/url-shortener-internal/versions/1.1.0"
"$scope_rollback_prefix/uninstall.sh" --non-interactive >/dev/null
tamper_prefix=$TEST_ROOT/tamper
"$payload/install.sh" --mode portable --prefix "$tamper_prefix" \
--register-service user --non-interactive >/dev/null
printf '# local change\n' >> "$unit"
if "$tamper_prefix/uninstall.sh" --non-interactive >/dev/null 2>&1; then
fail 'uninstaller removed a modified unit'
fi
assert_file "$unit"
rm -f -- "$unit"
helper_tamper_prefix=$TEST_ROOT/helper-tamper
"$payload/install.sh" --mode portable --prefix "$helper_tamper_prefix" \
--register-service none --non-interactive >/dev/null
printf '# local change\n' >> \
"$helper_tamper_prefix/libexec/updater/1.2.3/bin/echoion-updater"
if "$helper_tamper_prefix/uninstall.sh" --non-interactive >/dev/null 2>&1; then
fail 'uninstaller removed a modified privileged updater helper'
fi
assert_file "$helper_tamper_prefix/libexec/updater/1.2.3/bin/echoion-updater"
unrecognized_helper_prefix=$TEST_ROOT/unrecognized-helper
install -d -- "$unrecognized_helper_prefix/libexec/updater/1.2.3/bin"
printf '#!/bin/sh\nexit 0\n' > \
"$unrecognized_helper_prefix/libexec/updater/1.2.3/bin/echoion-updater"
chmod 0755 \
"$unrecognized_helper_prefix/libexec/updater/1.2.3/bin/echoion-updater"
if "$payload/install.sh" --mode portable --prefix "$unrecognized_helper_prefix" \
--register-service none --non-interactive >/dev/null 2>&1; then
fail 'installer overwrote an unrecognized privileged updater helper'
fi
if "$payload/install.sh" --mode portable --prefix "/tmp/echoion-installer-test-$$" \
--register-service user --non-interactive >/dev/null 2>&1; then
fail 'temporary portable service prefix was accepted'
fi
unsafe_mutable_prefix=$TEST_ROOT/unsafe-mutable/install
if "$payload/install.sh" --mode portable --prefix "$unsafe_mutable_prefix" \
--config-dir "$TEST_ROOT/unsafe-mutable" --register-service none \
--non-interactive >/dev/null 2>&1; then
fail 'mutable directory containing the install prefix was accepted'
fi
in_place=$TEST_ROOT/in-place
make_payload "$in_place"
"$in_place/install.sh" --mode portable --prefix "$in_place" \
--data-layout self-contained --register-service none --non-interactive >/dev/null
assert_file "$in_place/versions/1.2.3/bin/echoiond"
assert_not_exists "$in_place/bin"
[[ $(readlink -- "$in_place/current") == versions/1.2.3 ]] || fail 'in-place current target is wrong'
printf 'installer tests passed\n'