#!/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) TEST_ROOT=$(mktemp -d -- "$SCRIPT_DIR/.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/service" 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" cat > "$root/manifest.json" <<'EOF' { "schemaVersion": 2, "version": "1.2.3", "files": [ {"path": "bin/echoiond"} ] } EOF cat > "$root/bin/echoiond" <<'EOF' #!/usr/bin/env bash if [[ ${1:-} == --validate-install && -n ${2:-} ]]; then printf '%s\n' "$2" >> "${VALIDATOR_LOG:?}" if [[ -n ${VALIDATOR_FAIL_PATH:-} && $2 == "$VALIDATOR_FAIL_PATH" ]]; then exit 1 fi exit 0 fi 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" 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" printf 'fake dynamic core\n' > "$root/lib/Echoion.ts" cat > "$root/share/echoion/config.example.json" <<'EOF' { "web": { "webRoot": "./web", "enabled": false } } EOF printf '\n' > "$root/share/echoion/web/index.html" } 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 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 SYSTEMCTL_LOG=$TEST_ROOT/systemctl.log export DAEMON_LOG=$TEST_ROOT/daemon.log export VALIDATOR_LOG=$TEST_ROOT/validator.log : > "$SYSTEMCTL_LOG" : > "$DAEMON_LOG" : > "$VALIDATOR_LOG" bash -n "$PACKAGING_DIR/install.sh" bash -n "$PACKAGING_DIR/uninstall.sh" 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 VALIDATOR_FAIL_PATH=$metadata_prefix/versions/1.2.3 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 validation failure' fi unset VALIDATOR_FAIL_PATH 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/config/config.json" [[ -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=data' assert_contains "$self_prefix/.echoion-install" 'launcher=echoion' assert_contains "$self_prefix/config/config.json" '"webRoot": "./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' assert_contains "$VALIDATOR_LOG" "$self_prefix/versions/1.2.3" 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/data" 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/data" 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" 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 unit=$XDG_CONFIG_HOME/systemd/user/echoion.service assert_file "$unit" assert_contains "$unit" 'WorkingDirectory="' assert_contains "$unit" 'portable path %% dollar$/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" '--config "' assert_contains "$unit" '--state-dir "' if grep -E '@[A-Z_]+@' "$unit" >/dev/null; then fail 'generated systemd 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" 2> "$verify_log" && grep -E 'echoion\.service:|Failed to load unit' "$verify_log" >/dev/null; then cat "$verify_log" >&2 fail 'generated systemd unit did not verify' fi fi assert_contains "$SYSTEMCTL_LOG" '--user daemon-reload' 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' : > "$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" '--user restart echoion.service' assert_contains "$SYSTEMCTL_LOG" '--user is-active --quiet echoion.service' : > "$SYSTEMCTL_LOG" "$service_prefix/uninstall.sh" --non-interactive assert_not_exists "$unit" 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%% *} 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" 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" 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' assert_contains "$rollback_prefix/.echoion-install" 'version=1.2.3' "$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%% *} 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" 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_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' "$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" 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'