Merge pull request #143 from marcodelpin/fix/install-script-safety

fix(install): prevent shell corruption from directory deletion
This commit is contained in:
Steve Yegge
2025-10-24 14:57:29 -07:00
committed by GitHub

View File

@@ -3,6 +3,11 @@
# Beads (bd) installation script
# Usage: curl -fsSL https://raw.githubusercontent.com/steveyegge/beads/main/scripts/install.sh | bash
#
# ⚠️ IMPORTANT: This script must be EXECUTED, never SOURCED
# ❌ WRONG: source install.sh (will exit your shell on errors)
# ✅ CORRECT: bash install.sh
# ✅ CORRECT: curl -fsSL ... | bash
#
set -e
@@ -81,12 +86,12 @@ install_from_release() {
version=$(wget -qO- "$latest_url" | grep '"tag_name"' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
else
log_error "Neither curl nor wget found. Please install one of them."
return 1
return 0
fi
if [ -z "$version" ]; then
log_error "Failed to fetch latest version"
return 1
return 0
fi
log_info "Latest version: $version"
@@ -101,23 +106,26 @@ install_from_release() {
if command -v curl &> /dev/null; then
if ! curl -fsSL -o "$archive_name" "$download_url"; then
log_error "Download failed"
cd - > /dev/null || cd "$HOME"
rm -rf "$tmp_dir"
return 1
return 0
fi
elif command -v wget &> /dev/null; then
if ! wget -q -O "$archive_name" "$download_url"; then
log_error "Download failed"
cd - > /dev/null || cd "$HOME"
rm -rf "$tmp_dir"
return 1
return 0
fi
fi
# Extract archive
log_info "Extracting archive..."
cd - > /dev/null || cd "$HOME"
if ! tar -xzf "$archive_name"; then
log_error "Failed to extract archive"
rm -rf "$tmp_dir"
return 1
return 0
fi
# Determine install location
@@ -146,6 +154,7 @@ install_from_release() {
echo "Add this to your shell profile (~/.bashrc, ~/.zshrc, etc.):"
echo " export PATH=\"\$PATH:$install_dir\""
echo ""
cd - > /dev/null || cd "$HOME"
fi
cd - > /dev/null
@@ -171,12 +180,12 @@ check_go() {
echo " - Download from https://go.dev/dl/"
echo " - Or use your package manager to update"
echo ""
return 1
return 0
fi
return 0
else
return 1
return 0
fi
}
@@ -200,7 +209,7 @@ install_with_go() {
return 0
else
log_error "go install failed"
return 1
return 0
fi
}
@@ -243,22 +252,25 @@ build_from_source() {
echo ""
echo "Add this to your shell profile (~/.bashrc, ~/.zshrc, etc.):"
echo " export PATH=\"\$PATH:$install_dir\""
cd - > /dev/null || cd "$HOME"
echo ""
fi
cd - > /dev/null
cd - > /dev/null || cd "$HOME"
rm -rf "$tmp_dir"
return 0
else
log_error "Build failed"
cd - > /dev/null || cd "$HOME"
cd - > /dev/null
rm -rf "$tmp_dir"
return 1
return 0
fi
else
log_error "Failed to clone repository"
rm -rf "$tmp_dir"
return 1
return 0
fi
}
@@ -277,7 +289,7 @@ verify_installation() {
return 0
else
log_error "bd was installed but is not in PATH"
return 1
return 0
fi
}