这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: improve installation script by using a temporary directory for downloads #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
13 changes: 7 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@ fi
TARBALL="kubectl-ai_${OS}_${ARCH}.tar.gz"
URL="https://github.com/$REPO/releases/download/$LATEST_TAG/$TARBALL"

# Create temp dir and clean up on exit
tmpdir="$(mktemp -d)"
trap "rm -rf '$tmpdir'" EXIT
Copy link
Preview

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trap command encloses $tmpdir in single quotes, which prevents variable expansion at the time the trap is executed, causing the temporary directory not to be cleaned up. Consider changing the command to: trap "rm -rf "$tmpdir"" EXIT.

Suggested change
trap "rm -rf '$tmpdir'" EXIT
trap "rm -rf \"$tmpdir\"" EXIT

Copilot uses AI. Check for mistakes.


# Download and extract
echo "Downloading $URL ..."
curl -fSL --retry 3 "$URL" -o "$TARBALL"
tar --no-same-owner -xzf "$TARBALL"
curl -fSL --retry 3 "$URL" -o "$tmpdir/$TARBALL"
tar --no-same-owner -xzf "$tmpdir/$TARBALL" -C "$tmpdir"

# Move binary to /usr/local/bin (may require sudo)
echo "Installing $BINARY to /usr/local/bin (may require sudo)..."
sudo install -m 0755 "$BINARY" /usr/local/bin/

# Clean up
rm "$TARBALL"
sudo install -m 0755 "$tmpdir/$BINARY" /usr/local/bin/

echo "✅ $BINARY installed successfully! Run '$BINARY --help' to get started."