Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ VERSION=""
INSTALL_DIR=""
NEED_SUDO=0
PATH_HINT=0
UPDATING=0
tmp=""

say() { printf '%s\n' "$*"; }
Expand Down Expand Up @@ -156,6 +157,19 @@ install_binary() {
fi
}

# next_step_hint closes with what to run next. A first install needs the
# login service set up, so: flue enable. An update overwrote a binary that
# was already there, and a running daemon keeps executing the old build
# until it is restarted, so: flue restart. UPDATING is decided before the
# new binary lands, otherwise every install would look like an update.
next_step_hint() {
if [ "$UPDATING" = 1 ]; then
say "next: flue restart"
else
say "next: flue enable"
fi
}

path_hint() {
[ "$PATH_HINT" = 1 ] || return 0
case ":${PATH}:" in
Expand All @@ -182,12 +196,15 @@ main() {
asset="flue_${VERSION}_${OS}_${ARCH}.tar.gz"
base_url="https://github.com/${REPO}/releases/download/${TAG}"
choose_install_dir
if [ -x "${INSTALL_DIR}/flue" ]; then
UPDATING=1
fi

if [ "$DRY_RUN" = 1 ]; then
say "dry-run: would download ${base_url}/${asset}"
say "dry-run: would verify its sha256 against ${base_url}/checksums.txt"
say "dry-run: would install to ${INSTALL_DIR}/flue"
say "next: flue enable"
next_step_hint
return 0
fi

Expand All @@ -200,7 +217,7 @@ main() {

say "flue ${VERSION} installed to ${INSTALL_DIR}/flue"
path_hint
say "next: flue enable"
next_step_hint
}

# When sourced by the test suite (FLUE_INSTALL_SOURCED=1) nothing runs; the
Expand Down
29 changes: 28 additions & 1 deletion scripts/install_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,33 @@ assert_contains "dry-run names the asset on the contract" "flue_0.1.0_darwin_arm
assert_contains "dry-run honours FLUE_INSTALL_DIR" "/nowhere/bin/flue" "$out"
assert_contains "dry-run ends with the next step" "next: flue enable" "$out"

# --- an existing install makes the next step a restart, not enable -----------
# The same script serves first installs and updates. When a flue binary is
# already at the install path, the daemon keeps running the old build until
# restarted, so the closing hint must say restart.
utmp=$(mktemp -d)
trap 'rm -rf "$tmp" "$utmp"' EXIT
printf '#!/bin/sh\n' >"${utmp}/flue"
chmod +x "${utmp}/flue"

out=$(bash -c '
FLUE_INSTALL_SOURCED=1
. ./install.sh
fetch_latest() { printf "%s" "{\"tag_name\": \"v0.1.0\"}" >"$1"; printf "%s" 200; }
FLUE_OS=Darwin FLUE_ARCH=arm64 FLUE_INSTALL_DIR="$1" main --dry-run
' _ "$utmp" 2>&1)
rc=$?
assert_eq "update dry-run exits 0" 0 "$rc"
assert_contains "update ends with restart, not enable" "next: flue restart" "$out"
case "$out" in
*"next: flue enable"*)
echo "FAIL update dry-run must not suggest flue enable"
printf '%s\n' "$out" | sed 's/^/ | /'
failures=$((failures + 1))
;;
*) echo "ok update dry-run does not suggest flue enable" ;;
esac

# --- x86_64 normalizes to amd64 ----------------------------------------------
out=$(bash -c '
FLUE_INSTALL_SOURCED=1
Expand All @@ -107,7 +134,7 @@ assert_contains "x86_64 becomes amd64 in the asset name" "flue_0.1.0_linux_amd64
# directly: a real archive file plus a checksums.txt that names the wrong
# sha256 for it, same as a tampered or corrupted download would produce.
ctmp=$(mktemp -d)
trap 'rm -rf "$tmp" "$ctmp"' EXIT
trap 'rm -rf "$tmp" "$utmp" "$ctmp"' EXIT
printf 'not the real archive bytes' >"${ctmp}/flue_0.1.0_darwin_arm64.tar.gz"
printf 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef flue_0.1.0_darwin_arm64.tar.gz\n' \
>"${ctmp}/checksums.txt"
Expand Down