Skip to content
Open
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
fix: add trap to clean up temp directory on unexpected exit
install.sh uses \set -e\ which terminates the script on any command
failure. When this happens (e.g., download 404, network error), the
temp directory created by \mktemp -d\ is never cleaned up because
the manual \
m -rf\ calls only cover explicitly handled error paths.

Add a \	rap ... EXIT\ immediately after creating the temp directory
to ensure cleanup on all exit paths. This also removes the now-
redundant manual cleanup calls, simplifying the error handling.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
  • Loading branch information
AnveshKolluri and Copilot committed Feb 21, 2026
commit e8eff4a1c3b43b4148871fb88143dc138ec79230
6 changes: 1 addition & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ echo "Downloading from: $DOWNLOAD_URL"

# Download and extract with error handling
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
TMP_TARBALL="$TMP_DIR/copilot-${PLATFORM}-${ARCH}.tar.gz"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$DOWNLOAD_URL" -o "$TMP_TARBALL"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$TMP_TARBALL" "$DOWNLOAD_URL"
else
echo "Error: Neither curl nor wget found. Please install one of them."
rm -rf "$TMP_DIR"
exit 1
fi

Expand All @@ -91,15 +91,13 @@ if [ "$CHECKSUMS_AVAILABLE" = true ]; then
echo "✓ Checksum validated"
else
echo "Error: Checksum validation failed." >&2
rm -rf "$TMP_DIR"
exit 1
fi
elif command -v shasum >/dev/null 2>&1; then
if (cd "$TMP_DIR" && shasum -a 256 -c --ignore-missing SHA256SUMS.txt >/dev/null 2>&1); then
echo "✓ Checksum validated"
else
echo "Error: Checksum validation failed." >&2
rm -rf "$TMP_DIR"
exit 1
fi
else
Expand All @@ -110,7 +108,6 @@ fi
# Check that the file is a valid tarball
if ! tar -tzf "$TMP_TARBALL" >/dev/null 2>&1; then
echo "Error: Downloaded file is not a valid tarball or is corrupted." >&2
rm -rf "$TMP_DIR"
exit 1
fi

Expand All @@ -134,7 +131,6 @@ fi
tar -xz -C "$INSTALL_DIR" -f "$TMP_TARBALL"
chmod +x "$INSTALL_DIR/copilot"
echo "✓ GitHub Copilot CLI installed to $INSTALL_DIR/copilot"
rm -rf "$TMP_DIR"

# Check if installed binary is accessible
if ! command -v copilot >/dev/null 2>&1; then
Expand Down
Loading