This commit is contained in:
@@ -156,12 +156,14 @@ bash -c '
|
||||
# A RETURN trap installed by install_release must be cleared while its local
|
||||
# temporary variables still exist; otherwise set -u fails at the end of main.
|
||||
release_fixture="$tmp/release-fixture"
|
||||
mkdir -p "$release_fixture/dist/server" "$release_fixture/dist/web" "$release_fixture/bin" \
|
||||
mkdir -p "$release_fixture/dist/server/cli" "$release_fixture/dist/web" "$release_fixture/bin" \
|
||||
"$release_fixture/scripts" "$release_fixture/runtime/bin" "$release_fixture/systemd"
|
||||
printf '%s\n' '{"version":"1.0.0"}' > "$release_fixture/package.json"
|
||||
printf '%s\n' server > "$release_fixture/dist/server/index.js"
|
||||
printf '%s\n' cli > "$release_fixture/dist/server/cli/admin-init.js"
|
||||
printf '%s\n' web > "$release_fixture/dist/web/index.html"
|
||||
printf '%s\n' '#!/bin/sh' > "$release_fixture/bin/tallynote"
|
||||
cp "$root/bin/tallynote-admin-init" "$release_fixture/bin/tallynote-admin-init"
|
||||
printf '%s\n' '#!/bin/sh' > "$release_fixture/scripts/tallynote-update.sh"
|
||||
printf '%s\n' '#!/bin/sh' > "$release_fixture/scripts/tallynote-update-runner.sh"
|
||||
printf '%s\n' '#!/bin/sh' > "$release_fixture/uninstall.sh"
|
||||
@@ -169,7 +171,7 @@ printf '%s\n' '[Unit]' > "$release_fixture/systemd/tallynote.service"
|
||||
printf '%s\n' '[Unit]' > "$release_fixture/systemd/tallynote-update.service"
|
||||
printf '%s\n' '[Unit]' > "$release_fixture/systemd/tallynote-update.path"
|
||||
printf '%s\n' 'TALLYNOTE_HOST=127.0.0.1' > "$release_fixture/systemd/tallynote.env.example"
|
||||
chmod 755 "$release_fixture/bin/tallynote" "$release_fixture/scripts"/*.sh "$release_fixture/uninstall.sh"
|
||||
chmod 755 "$release_fixture/bin/tallynote" "$release_fixture/bin/tallynote-admin-init" "$release_fixture/scripts"/*.sh "$release_fixture/uninstall.sh"
|
||||
release_archive="$tmp/release-fixture.tar.gz"
|
||||
tar -C "$release_fixture" -czf "$release_archive" .
|
||||
bash -c '
|
||||
@@ -185,10 +187,105 @@ bash -c '
|
||||
if [[ "${1:-}" == -Tf ]]; then shift; /bin/mv -f "$@"; else /bin/mv "$@"; fi
|
||||
}
|
||||
install_release "$archive" 1.0.0
|
||||
[[ -x "$PREFIX/releases/1.0.0/bin/tallynote-admin-init" ]]
|
||||
set_env_key() { local key=$1 value=$2 escaped; :; }
|
||||
set_env_key test value
|
||||
' _ "$installer_lib" "$release_archive" "$tmp/install-release"
|
||||
|
||||
# The production admin wrapper must load a release-relative runtime, change to
|
||||
# the release root, and forward CLI arguments without requiring pnpm.
|
||||
wrapper_prefix="$tmp/wrapper-prefix"
|
||||
mkdir -p "$wrapper_prefix/releases/1.0.0/runtime/bin" "$wrapper_prefix/releases/1.0.0/dist/server/cli"
|
||||
ln -s "$wrapper_prefix/releases/1.0.0" "$wrapper_prefix/current"
|
||||
printf '%s\n' '#!/usr/bin/env bash' 'pwd -P > "$TALLYNOTE_WRAPPER_LOG"' 'printf "%s\n" "$@" >> "$TALLYNOTE_WRAPPER_LOG"' > "$wrapper_prefix/releases/1.0.0/runtime/bin/node"
|
||||
chmod 755 "$wrapper_prefix/releases/1.0.0/runtime/bin/node"
|
||||
printf '%s\n' cli > "$wrapper_prefix/releases/1.0.0/dist/server/cli/admin-init.js"
|
||||
TALLYNOTE_INSTALL_PREFIX="$wrapper_prefix" TALLYNOTE_CONFIG_DIR="$tmp/no-config" TALLYNOTE_WRAPPER_LOG="$tmp/wrapper.log" \
|
||||
bash "$root/bin/tallynote-admin-init" --generate
|
||||
wrapper_expected_root=$(cd "$wrapper_prefix/releases/1.0.0" && pwd -P)
|
||||
grep -Fxq "$wrapper_expected_root" "$tmp/wrapper.log"
|
||||
grep -Fxq -- '--generate' "$tmp/wrapper.log"
|
||||
|
||||
# The first-install prompt is optional and must support an explicit later
|
||||
# initialization path without blocking the rest of the install.
|
||||
admin_wizard_dir="$tmp/admin-wizard"
|
||||
mkdir -p "$admin_wizard_dir"
|
||||
printf '%s\n' yes remaining-input > "$admin_wizard_dir/input"
|
||||
: > "$admin_wizard_dir/output"
|
||||
cat > "$admin_wizard_dir/admin-init" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
if [[ "${1:-}" == --check ]]; then
|
||||
printf '%s\n' empty
|
||||
else
|
||||
printf '%s\n' initialized > "$TALLYNOTE_ADMIN_WIZARD_RESULT"
|
||||
fi
|
||||
EOF
|
||||
chmod 755 "$admin_wizard_dir/admin-init"
|
||||
bash -c '
|
||||
script=$1
|
||||
dir=$2
|
||||
set --
|
||||
source "$script"
|
||||
INSTALL_FIRST_INSTALL=1
|
||||
NON_INTERACTIVE=0
|
||||
PROMPT_INPUT="$dir/input"
|
||||
PROMPT_OUTPUT="$dir/output"
|
||||
ADMIN_INIT_PATH="$dir/admin-init"
|
||||
TALLYNOTE_ADMIN_WIZARD_RESULT="$dir/result"
|
||||
export TALLYNOTE_ADMIN_WIZARD_RESULT
|
||||
run_initial_admin_wizard
|
||||
[[ -f "$dir/result" ]]
|
||||
' _ "$installer_lib" "$admin_wizard_dir"
|
||||
|
||||
# An upgrade must never reopen the first-admin wizard, even if a damaged or
|
||||
# deliberately empty database would otherwise report an uninitialized state.
|
||||
printf '%s\n' yes > "$admin_wizard_dir/upgrade-input"
|
||||
rm -f "$admin_wizard_dir/upgrade-result"
|
||||
bash -c '
|
||||
script=$1
|
||||
dir=$2
|
||||
set --
|
||||
source "$script"
|
||||
INSTALL_FIRST_INSTALL=0
|
||||
NON_INTERACTIVE=0
|
||||
PROMPT_INPUT="$dir/upgrade-input"
|
||||
PROMPT_OUTPUT="$dir/upgrade-output"
|
||||
ADMIN_INIT_PATH="$dir/admin-init"
|
||||
TALLYNOTE_ADMIN_WIZARD_RESULT="$dir/upgrade-result"
|
||||
export TALLYNOTE_ADMIN_WIZARD_RESULT
|
||||
run_initial_admin_wizard
|
||||
[[ ! -e "$dir/upgrade-result" ]]
|
||||
' _ "$installer_lib" "$admin_wizard_dir"
|
||||
|
||||
# Validation or password errors after the base service is committed must leave
|
||||
# the installation usable and point the operator at the standalone command.
|
||||
failed_wizard_dir="$tmp/failed-admin-wizard"
|
||||
mkdir -p "$failed_wizard_dir"
|
||||
printf '%s\n' yes > "$failed_wizard_dir/input"
|
||||
: > "$failed_wizard_dir/output"
|
||||
cat >"$failed_wizard_dir/admin-init" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
if [[ "${1:-}" == --check ]]; then
|
||||
printf '%s\n' empty
|
||||
exit 0
|
||||
fi
|
||||
exit 1
|
||||
EOF
|
||||
chmod 755 "$failed_wizard_dir/admin-init"
|
||||
bash -c '
|
||||
script=$1
|
||||
dir=$2
|
||||
set --
|
||||
source "$script"
|
||||
INSTALL_FIRST_INSTALL=1
|
||||
NON_INTERACTIVE=0
|
||||
PROMPT_INPUT="$dir/input"
|
||||
PROMPT_OUTPUT="$dir/output"
|
||||
ADMIN_INIT_PATH="$dir/admin-init"
|
||||
run_initial_admin_wizard
|
||||
[[ -x "$dir/admin-init" ]]
|
||||
' _ "$installer_lib" "$failed_wizard_dir"
|
||||
|
||||
# Duplicate security-sensitive EnvironmentFile assignments are rejected even
|
||||
# when the first value looks valid (systemd uses the later value).
|
||||
duplicate_env="$tmp/duplicate.env"
|
||||
|
||||
Reference in New Issue
Block a user