Skip to content

Instantly share code, notes, and snippets.

@boazadato
Last active May 19, 2026 15:34
Show Gist options
  • Select an option

  • Save boazadato/9c8d9fce464900c7b8dd0920bebf64af to your computer and use it in GitHub Desktop.

Select an option

Save boazadato/9c8d9fce464900c7b8dd0920bebf64af to your computer and use it in GitHub Desktop.
setup git
#!/bin/bash
# ─── Debug log setup ──────────────────────────
DEBUG_LOG="/tmp/hb-setup-debug.log"
exec > >(tee -a "$DEBUG_LOG") 2>&1
echo "===== HB SETUP DEBUG LOG ====="
echo "Timestamp : $(date)"
echo "Script path : $0"
echo "Running as : $(id)"
echo "Effective user: $(whoami)"
echo "--- Key env vars ---"
echo "TERM : ${TERM:-<unset>}"
echo "TERM_PROGRAM : ${TERM_PROGRAM:-<unset>}"
echo "HOME : ${HOME:-<unset>}"
echo "USER : ${USER:-<unset>}"
echo "LOGNAME : ${LOGNAME:-<unset>}"
echo "SUDO_USER : ${SUDO_USER:-<unset>}"
echo "JAMF_POLICY_ID: ${JAMF_POLICY_ID:-<unset>}"
echo "--- /dev/console user ---"
CONSOLE_USER=$(stat -f "%Su" /dev/console 2>/dev/null || echo "<stat failed>")
echo "Console user : $CONSOLE_USER"
CONSOLE_UID=$(id -u "$CONSOLE_USER" 2>/dev/null || echo "<id failed>")
echo "Console UID : $CONSOLE_UID"
echo "--- Full env dump ---"
env | sort
echo "============================="
# ─── Auto-launch Terminal if not running in one ──
# Detect Jamf/MDM context: script path or sudo command contains "jamf"
RUNNING_UNDER_JAMF=false
[[ "$0" == *"/JAMF/"* || "$0" == *"/jamf/"* ]] && RUNNING_UNDER_JAMF=true
[[ "${SUDO_COMMAND:-}" == *"jamf"* ]] && RUNNING_UNDER_JAMF=true
echo "[auto-launch] RUNNING_UNDER_JAMF=$RUNNING_UNDER_JAMF TERM_PROGRAM=${TERM_PROGRAM:-<unset>} TERM=${TERM:-<unset>}"
if $RUNNING_UNDER_JAMF || { [ -z "$TERM_PROGRAM" ] && [ -z "$TERM" ]; }; then
echo "[auto-launch] Non-interactive context detected — attempting to open Terminal.app"
STABLE_PATH="/tmp/hb-setup.sh"
echo "[auto-launch] Copying $0 -> $STABLE_PATH"
cp "$0" "$STABLE_PATH" && echo "[auto-launch] Copy OK" || echo "[auto-launch] Copy FAILED: $?"
CURRENT_USER=$(stat -f "%Su" /dev/console 2>/dev/null || echo "")
USER_ID=$(id -u "$CURRENT_USER" 2>/dev/null || echo "")
chmod 755 "$STABLE_PATH"
chown "$CURRENT_USER" "$STABLE_PATH"
echo "[auto-launch] CURRENT_USER=$CURRENT_USER USER_ID=$USER_ID"
echo "[auto-launch] Running osascript via launchctl asuser..."
launchctl asuser "$USER_ID" sudo -u "$CURRENT_USER" \
osascript -e "tell application \"Terminal\"
do script \"bash $STABLE_PATH\"
activate
end tell" \
&& echo "[auto-launch] osascript OK" \
|| echo "[auto-launch] osascript FAILED: $?"
echo "[auto-launch] Exiting MDM wrapper. Check $DEBUG_LOG for details."
exit 0
else
echo "[auto-launch] Interactive terminal detected — running normally"
fi
set -euo pipefail
# ─────────────────────────────────────────────
# HoneyBook GitHub Setup Script
# Sets up Xcode CLT → Homebrew → gh CLI → auth → Claude Code
# ─────────────────────────────────────────────
GITHUB_ORG="HoneyStorageAI"
# Colors
RED=$'\033[0;31m'
GREEN=$'\033[0;32m'
YELLOW=$'\033[1;33m'
CYAN=$'\033[0;36m'
BOLD=$'\033[1m'
RESET=$'\033[0m'
info() { echo -e "${CYAN}${BOLD}==>${RESET} $1"; }
success() { echo -e "${GREEN}✔${RESET} $1"; }
warn() { echo -e "${YELLOW}⚠${RESET} $1"; }
error() { echo -e "${RED}✖ $1${RESET}"; exit 1; }
step() { echo -e "\n${BOLD}$1${RESET}"; }
# ─── Sanity check: macOS only ────────────────
if [[ "$(uname)" != "Darwin" ]]; then
error "This script is for macOS only."
fi
echo ""
echo -e "${BOLD}╔══════════════════════════════════════════╗${RESET}"
echo -e "${BOLD}║ HoneyBook GitHub Setup — Let's go! ║${RESET}"
echo -e "${BOLD}╚══════════════════════════════════════════╝${RESET}"
echo ""
echo "This script will set up everything you need to use GitHub."
echo "It may take up to 15 minutes if this is a fresh Mac."
echo "Please keep this window open and don't let your Mac sleep."
echo ""
read -rp "Press Enter to start..."
# ─── Step 1: Xcode Command Line Tools ────────
step "Step 1/5 — Checking Apple Developer Tools"
if xcode-select -p &>/dev/null; then
success "Apple Developer Tools already installed ($(xcode-select -p))"
else
warn "Apple Developer Tools not found. Starting installation..."
echo ""
echo " A dialog box should appear on your screen asking you to install"
echo " 'Command Line Developer Tools'. Click ${BOLD}Install${RESET} (not 'Get Xcode')."
echo " Then come back to this window and wait — it takes around 10-15 minutes."
echo ""
xcode-select --install 2>/dev/null || true
echo -n " Waiting for installation to complete"
# Poll until xcode-select -p succeeds
until xcode-select -p &>/dev/null; do
echo -n "."
sleep 10
done
echo ""
success "Apple Developer Tools installed!"
fi
# ─── Step 2: Homebrew ────────────────────────
step "Step 2/5 — Checking Homebrew"
if command -v brew &>/dev/null; then
success "Homebrew already installed ($(brew --version | head -1))"
else
echo ""
echo " ${BOLD}You will be asked for your Mac login password.${RESET}"
echo " This is normal — Homebrew needs it to install software."
echo " You won't see the password as you type; that's also normal. Just type and press Enter."
echo ""
read -rp " Press Enter when ready..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add Homebrew to PATH for Apple Silicon and Intel — write to both zprofile and zshrc
BREW_SHELLENV_LINE=""
if [[ -f /opt/homebrew/bin/brew ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
BREW_SHELLENV_LINE='eval "$(/opt/homebrew/bin/brew shellenv)"'
elif [[ -f /usr/local/bin/brew ]]; then
eval "$(/usr/local/bin/brew shellenv)"
BREW_SHELLENV_LINE='eval "$(/usr/local/bin/brew shellenv)"'
fi
if [[ -n "$BREW_SHELLENV_LINE" ]]; then
for PROFILE in "$HOME/.zprofile" "$HOME/.zshrc"; do
if ! grep -q "brew shellenv" "$PROFILE" 2>/dev/null; then
echo "$BREW_SHELLENV_LINE" >> "$PROFILE"
fi
done
fi
if command -v brew &>/dev/null; then
success "Homebrew installed!"
else
error "Homebrew installation failed. Please contact your IT team."
fi
fi
# ─── PATH: ensure ~/.local/bin is present ────
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
mkdir -p "$HOME/.local/bin"
for PROFILE in "$HOME/.zprofile" "$HOME/.zshrc"; do
if ! grep -q '\.local/bin' "$PROFILE" 2>/dev/null; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$PROFILE"
fi
done
export PATH="$HOME/.local/bin:$PATH"
# shellcheck disable=SC1090
source ~/.zshrc 2>/dev/null || true
fi
# ─── Step 3: GitHub CLI ──────────────────────
step "Step 3/5 — Checking GitHub CLI (gh)"
if command -v gh &>/dev/null; then
success "GitHub CLI already installed ($(gh --version | head -1))"
else
info "Installing GitHub CLI..."
brew install gh
success "GitHub CLI installed!"
fi
# ─── Step 5: GitHub Auth ─────────────────────
step "Step 4/5 — Connecting to GitHub"
if gh auth status &>/dev/null; then
success "Already logged in to GitHub!"
gh auth status
else
echo ""
echo " Time to connect your GitHub account."
echo " A browser window will open — sign in with your HoneyBook Okta account."
echo " When asked, select ${BOLD}HTTPS${RESET} and ${BOLD}Login with a web browser${RESET}."
echo " After signing in, you may see a page listing organizations — look for"
echo " ${BOLD}${GITHUB_ORG}${RESET} and click ${BOLD}Authorize${RESET} next to it."
echo ""
read -rp " Press Enter when you're ready..."
echo ""
gh auth login --hostname github.com --git-protocol https --web --scopes read:org
if ! gh auth status &>/dev/null; then
error "GitHub login failed. Please try running the script again."
fi
success "Logged in to GitHub!"
fi
# Verify org access
echo ""
info "Verifying access to ${GITHUB_ORG}..."
if gh org list 2>/dev/null | grep -qi "$GITHUB_ORG"; then
success "You have access to ${GITHUB_ORG}!"
else
warn "Could not confirm org access automatically — this may be normal."
echo " If you have issues accessing repos, contact your team lead."
fi
# ─── git config ─────────────────────────────
info "Setting git identity from GitHub..."
GIT_NAME=$(git config --global user.name 2>/dev/null || true)
GIT_EMAIL=$(git config --global user.email 2>/dev/null || true)
[[ -z "$GIT_NAME" ]] && GIT_NAME=$(gh api user --jq '.name' 2>/dev/null || true)
[[ -z "$GIT_EMAIL" ]] && GIT_EMAIL=$(gh api user/emails --jq '[.[] | select(.primary==true)] | .[0].email' 2>/dev/null || true)
[[ -n "$GIT_NAME" ]] && git config --global user.name "$GIT_NAME"
[[ -n "$GIT_EMAIL" ]] && git config --global user.email "$GIT_EMAIL"
if [[ -n "$GIT_NAME" && -n "$GIT_EMAIL" ]]; then
success "git identity: ${GIT_NAME} <${GIT_EMAIL}>"
else
warn "Could not set git identity automatically — this won't affect most tasks."
fi
# ─── Claude Code ──────────────────────────────
step "Step 5/5 — Installing Claude Code"
if command -v claude &>/dev/null; then
success "Claude Code already installed ($(claude --version 2>/dev/null || echo 'unknown version'))"
else
info "Installing Claude Code..."
curl -fsSL https://claude.ai/install.sh | bash
# Reload PATH so claude is available immediately in this session
export PATH="$HOME/.local/bin:$PATH"
# shellcheck disable=SC1090
source ~/.zshrc 2>/dev/null || true
if command -v claude &>/dev/null; then
success "Claude Code installed!"
else
warn "Claude Code install completed but 'claude' command not found yet — open a new terminal window and try running: claude"
fi
fi
# ─── Done ─────────────────────────────────────
echo ""
echo -e "${GREEN}${BOLD}╔══════════════════════════════════════════╗${RESET}"
echo -e "${GREEN}${BOLD}║ ✔ Setup complete! ║${RESET}"
echo -e "${GREEN}${BOLD}╚══════════════════════════════════════════╝${RESET}"
echo ""
echo " Here's what was set up:"
echo " • Apple Developer Tools (includes git)"
echo " • Homebrew (package manager)"
echo " • GitHub CLI (gh)"
echo " • GitHub account connected (${GITHUB_ORG})"
echo " • git identity: ${GIT_NAME} <${GIT_EMAIL}>"
echo " • Claude Code"
echo ""
echo " To start Claude Code, open a new terminal window and run:"
echo -e " ${CYAN}claude${RESET}"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment