Skip to content

Instantly share code, notes, and snippets.

@shyamzzp
Last active March 30, 2026 04:38
Show Gist options
  • Select an option

  • Save shyamzzp/d683e204c364c853f5474d3c3a30307f to your computer and use it in GitHub Desktop.

Select an option

Save shyamzzp/d683e204c364c853f5474d3c3a30307f to your computer and use it in GitHub Desktop.
GhostDrive install bootstrap for curl | bash
#!/usr/bin/env bash
set -euo pipefail
GHOSTDRIVE_REPO="${GHOSTDRIVE_REPO:-shyamzzp/ghost-drive}"
GHOSTDRIVE_REF="${GHOSTDRIVE_REF:-main}"
GHOSTDRIVE_INSTALL_DIR="${GHOSTDRIVE_INSTALL_DIR:-$HOME/.local/bin}"
GHOSTDRIVE_SKIP_PROFILE_HINT="${GHOSTDRIVE_SKIP_PROFILE_HINT:-0}"
GHOSTDRIVE_WORKDIR=""
GHOSTDRIVE_GITHUB_TOKEN=""
cleanup() {
if [[ -n "${GHOSTDRIVE_WORKDIR:-}" && -d "${GHOSTDRIVE_WORKDIR}" ]]; then
rm -rf "$GHOSTDRIVE_WORKDIR"
fi
}
usage() {
cat <<'EOF'
Usage:
curl -fsSL https://raw.githubusercontent.com/shyamzzp/ghost-drive/main/scripts/install-remote.sh | bash
Environment overrides:
GHOSTDRIVE_REPO=owner/repo
GHOSTDRIVE_REF=branch-or-tag
GHOSTDRIVE_INSTALL_DIR=/custom/bin
GITHUB_TOKEN=token-with-repo-access
GH_TOKEN=token-with-repo-access
If neither token is set and GitHub CLI is installed, the installer will
try `gh auth token` automatically.
EOF
}
require_command() {
local command_name="$1"
if ! command -v "$command_name" >/dev/null 2>&1; then
echo "Error: required command not found: $command_name" >&2
exit 1
fi
}
resolve_github_token() {
if [[ -n "${GITHUB_TOKEN:-}" ]]; then
GHOSTDRIVE_GITHUB_TOKEN="$GITHUB_TOKEN"
return
fi
if [[ -n "${GH_TOKEN:-}" ]]; then
GHOSTDRIVE_GITHUB_TOKEN="$GH_TOKEN"
return
fi
if command -v gh >/dev/null 2>&1; then
if GHOSTDRIVE_GITHUB_TOKEN="$(gh auth token 2>/dev/null)"; then
GHOSTDRIVE_GITHUB_TOKEN="${GHOSTDRIVE_GITHUB_TOKEN//$'\r'/}"
GHOSTDRIVE_GITHUB_TOKEN="${GHOSTDRIVE_GITHUB_TOKEN//$'\n'/}"
if [[ -n "$GHOSTDRIVE_GITHUB_TOKEN" ]]; then
echo "Using GitHub token from gh auth."
return
fi
fi
fi
GHOSTDRIVE_GITHUB_TOKEN=""
}
download_archive() {
local output_path="$1"
local repo_visibility_url="https://api.github.com/repos/${GHOSTDRIVE_REPO}"
local tarball_api_url="https://api.github.com/repos/${GHOSTDRIVE_REPO}/tarball/${GHOSTDRIVE_REF}"
local public_url="https://codeload.github.com/${GHOSTDRIVE_REPO}/tar.gz/${GHOSTDRIVE_REF}"
if [[ -n "$GHOSTDRIVE_GITHUB_TOKEN" ]]; then
curl -fsSL \
-H "Authorization: Bearer ${GHOSTDRIVE_GITHUB_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"$tarball_api_url" \
-o "$output_path"
return
fi
if curl -fsSL "$repo_visibility_url" >/dev/null 2>&1; then
curl -fsSL "$public_url" -o "$output_path"
return
fi
echo "Error: ${GHOSTDRIVE_REPO} appears to be private. Set GITHUB_TOKEN with repo access and retry." >&2
exit 1
}
main() {
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
exit 0
fi
require_command bash
require_command curl
require_command tar
require_command mktemp
require_command go
resolve_github_token
local archive_path extracted_dir
GHOSTDRIVE_WORKDIR="$(mktemp -d "${TMPDIR:-/tmp}/ghost-drive-install.XXXXXX")"
trap cleanup EXIT
archive_path="$GHOSTDRIVE_WORKDIR/ghost-drive.tar.gz"
echo "Downloading ${GHOSTDRIVE_REPO}@${GHOSTDRIVE_REF}..."
download_archive "$archive_path"
tar -xzf "$archive_path" -C "$GHOSTDRIVE_WORKDIR"
extracted_dir="$(find "$GHOSTDRIVE_WORKDIR" -mindepth 1 -maxdepth 1 -type d | head -n 1)"
if [[ -z "$extracted_dir" ]]; then
echo "Error: failed to unpack repository archive." >&2
exit 1
fi
echo "Installing ghost-drive to $GHOSTDRIVE_INSTALL_DIR..."
bash "$extracted_dir/scripts/install.sh" --global --install-dir "$GHOSTDRIVE_INSTALL_DIR"
if [[ "$GHOSTDRIVE_SKIP_PROFILE_HINT" != "1" ]]; then
echo
echo "Quick start:"
echo " export PATH=\"$GHOSTDRIVE_INSTALL_DIR:\$PATH\""
echo " ghost-drive --help"
echo " ghost-drive upgrade"
fi
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment