Skip to content
Merged
Changes from 2 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
29 changes: 29 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@

set -euo pipefail

# Global cleanup state — ensures background processes are killed and temp files
# are removed on any exit path (set -e, unhandled signal, unexpected error).
_cleanup_pids=()
_cleanup_files=()
_global_cleanup() {
for pid in "${_cleanup_pids[@]:-}"; do
kill "$pid" 2>/dev/null || true
done
for f in "${_cleanup_files[@]:-}"; do
rm -f "$f" 2>/dev/null || true
done
}
trap _global_cleanup EXIT

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
DEFAULT_NEMOCLAW_VERSION="0.1.0"
TOTAL_STEPS=3
Expand Down Expand Up @@ -210,16 +224,31 @@ spin() {
local pid=$! i=0
local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏')

# Register with global cleanup so any exit path reaps the child and temp file.
_cleanup_pids+=("$pid")
_cleanup_files+=("$log")

# Ensure Ctrl+C kills the background process and cleans up the temp file.
trap 'kill "$pid" 2>/dev/null; rm -f "$log"; exit 130' INT TERM

while kill -0 "$pid" 2>/dev/null; do
printf "\r ${C_GREEN}%s${C_RESET} %s" "${frames[$((i++ % 10))]}" "$msg"
sleep 0.08
done

# Restore default signal handling after the background process exits.
trap - INT TERM

if wait "$pid"; then
local status=0
else
local status=$?
fi

# Remove from global cleanup since we handled it here.
_cleanup_pids=("${_cleanup_pids[@]/$pid/}")
_cleanup_files=("${_cleanup_files[@]/$log/}")

if [[ $status -eq 0 ]]; then
printf "\r ${C_GREEN}✓${C_RESET} %s\n" "$msg"
else
Expand Down