Skip to content

Commit ab7e4a9

Browse files
refactor: updates for better project management
1 parent 7176992 commit ab7e4a9

5 files changed

Lines changed: 113 additions & 107 deletions

File tree

install.sh

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,50 @@ set -euo pipefail
33

44
# Usage: curl -sSL https://raw.githubusercontent.com/penguinranch/bootstrap/main/install.sh | bash
55

6+
# Basic logging for the installer (no external dependencies)
7+
log_info() { echo -e "\033[0;34mℹ️ [INFO]\033[0m $1"; }
8+
log_success() { echo -e "\033[0;32m✅ [SUCCESS]\033[0m $1"; }
9+
log_error() { echo -e "\033[0;31m❌ [ERROR]\033[0m $1"; }
10+
611
REPO_TAR_URL="${REPO_TAR_URL:-https://github.com/penguinranch/bootstrap/tarball/main}"
712

8-
echo "🚀 Initializing Gold Standard Environment..."
9-
10-
# Guard: prevent overwriting an existing project (bypass with BOOTSTRAP_DEV=1 for local testing)
11-
if [ -d ".devcontainer" ] && [ "${BOOTSTRAP_DEV:-0}" != "1" ]; then
12-
echo "⚠️ Existing project structure detected. Aborting bootstrap to prevent overwriting files."
13-
echo " (Set BOOTSTRAP_DEV=1 to bypass this check for local development.)"
14-
exit 1
15-
fi
16-
17-
# Download and extract the templates directory
18-
echo "Downloading the latest templates..."
19-
# Try GNU tar (with --wildcards) first, then fallback to BSD tar (macOS)
20-
if ! curl -sL "$REPO_TAR_URL" | tar -xz --wildcards --strip-components=2 "*/templates/" 2>/dev/null; then
21-
if ! curl -sL "$REPO_TAR_URL" | tar -xz --strip-components=2 2>/dev/null; then
22-
echo "❌ Failed to download or extract templates. Check your network connection."
13+
check_environment() {
14+
log_info "Initializing Gold Standard Environment..."
15+
# Guard: prevent overwriting an existing project (bypass with BOOTSTRAP_DEV=1 for local testing)
16+
if [ -d ".devcontainer" ] && [ "${BOOTSTRAP_DEV:-0}" != "1" ]; then
17+
log_error "Existing project structure detected. Aborting bootstrap to prevent overwriting files."
18+
echo " (Set BOOTSTRAP_DEV=1 to bypass this check for local development.)"
2319
exit 1
2420
fi
25-
# If fallback used, we might have extracted more than templates; cleanup if needed
26-
# But strip-components=2 for a github tarball (user-repo-hash/templates) usually lands templates content in pwd
27-
fi
21+
}
22+
23+
extract_templates() {
24+
log_info "Downloading the latest templates..."
25+
# Try GNU tar (with --wildcards) first, then fallback to BSD tar (macOS)
26+
if ! curl -sL "$REPO_TAR_URL" | tar -xz --wildcards --strip-components=2 "*/templates/" 2>/dev/null; then
27+
if ! curl -sL "$REPO_TAR_URL" | tar -xz --strip-components=2 2>/dev/null; then
28+
log_error "Failed to download or extract templates. Check your network connection."
29+
exit 1
30+
fi
31+
fi
32+
}
33+
34+
finalize_setup() {
35+
# Ensure standard directory structure
36+
mkdir -p docs/decisions
37+
38+
# Make scripts executable
39+
chmod +x .devcontainer/boot-check.sh scripts/*.sh 2>/dev/null || true
40+
chmod +x .githooks/* 2>/dev/null || true
2841

29-
# Ensure standard directory structure
30-
mkdir -p docs/decisions
42+
log_success "Bootstrap complete. Open in VS Code or Antigravity to start the Devcontainer."
43+
}
3144

32-
# Make scripts executable
45+
# Main execution
46+
check_environment
47+
extract_templates
48+
finalize_setup
49+
table
3350
chmod +x .devcontainer/boot-check.sh scripts/*.sh
3451
chmod +x .githooks/*
3552

templates/scripts/setup-env.sh

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,42 @@
11
#!/bin/bash
2-
set -euo pipefail
2+
# shellcheck shell=bash
3+
# Source shared utilities
4+
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
5+
# shellcheck source=scripts/utils.sh
6+
source "$SCRIPT_DIR/utils.sh"
7+
8+
ensure_root
39

410
# Re-runnable script to initialize or update .env
511
if [ ! -f .env.example ]; then
6-
echo "Error: .env.example not found. Please create it first."
12+
log_error ".env.example not found. Please create it first."
713
exit 1
814
fi
915

1016
if [ ! -f .env ]; then
1117
cp .env.example .env
12-
echo ".env created from template."
18+
log_success ".env created from template."
1319
fi
1420

15-
echo "Setting up environment variables..."
21+
log_info "Setting up environment variables..."
1622
read -rp "Enter your Git Name: " GIT_NAME
1723
read -rp "Enter your Git Email: " GIT_EMAIL
1824

1925
echo ""
20-
echo "Optional: SSH Public Key for commit signing."
26+
log_info "Optional: SSH Public Key for commit signing."
2127
echo "If you use 1Password as your SSH agent, you can copy the public key string directly."
2228
echo "(e.g., ssh-ed25519 AAAAC3Nz...)"
2329
read -rp "Enter your SSH Public Key (press Enter to skip): " SSH_PUBLIC_KEY
2430

2531
echo ""
26-
echo "Optional: The Gemini API Key is used by the Gemini CLI inside this Devcontainer."
32+
log_info "Optional: The Gemini API Key is used by the Gemini CLI inside this Devcontainer."
2733
echo "You can get an API key from: https://aistudio.google.com/app/apikey"
2834
read -rp "Enter your Gemini API Key (press Enter to skip): " GEMINI_API_KEY
2935

3036
echo ""
31-
echo "Optional: Authenticate with GitHub CLI for automations inside the Devcontainer."
37+
log_info "Optional: Authenticate with GitHub CLI for automations inside the Devcontainer."
3238
echo "To authenticate, you can run: gh auth login"
3339

34-
# Portable sed: works on both macOS (BSD sed) and Linux (GNU sed)
35-
portable_sed() {
36-
if sed --version 2>/dev/null | grep -q GNU; then
37-
sed -i "$@"
38-
else
39-
sed -i '' "$@"
40-
fi
41-
}
42-
43-
# Function to securely update or append inside .env
44-
update_env() {
45-
local key=$1
46-
local value=$2
47-
if grep -q "^${key}=" .env; then
48-
portable_sed "s|^${key}=.*|${key}=${value}|" .env
49-
else
50-
echo "${key}=${value}" >> .env
51-
fi
52-
}
53-
5440
update_env "GIT_NAME" "$GIT_NAME"
5541
update_env "GIT_EMAIL" "$GIT_EMAIL"
5642

@@ -72,13 +58,11 @@ if [ -n "$GEMINI_API_KEY" ]; then
7258
update_env "GEMINI_API_KEY" "$GEMINI_API_KEY"
7359
fi
7460

75-
76-
7761
# Update the LICENSE file if it exists
7862
if [ -f "LICENSE" ] && [ -n "$GIT_NAME" ]; then
7963
CURRENT_YEAR=$(date +"%Y")
8064
portable_sed "s|\[Year\]|${CURRENT_YEAR}|g" LICENSE
8165
portable_sed "s|\[Full Name\]|${GIT_NAME}|g" LICENSE
8266
fi
8367

84-
echo "Configuration complete. Restart your terminal or source the .env file."
68+
log_success "Configuration complete. Restart your terminal or source the .env file."

templates/scripts/setup-gemini.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#!/bin/bash
2-
set -euo pipefail
2+
# Source shared utilities
3+
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
4+
# shellcheck source=scripts/utils.sh
5+
source "$SCRIPT_DIR/utils.sh"
6+
7+
ensure_root
38

49
# Install Gemini CLI globally
510
if command -v gemini &> /dev/null; then
6-
echo "Gemini CLI is already installed."
11+
log_success "Gemini CLI is already installed."
712
else
8-
echo "Installing Gemini CLI..."
13+
log_info "Installing Gemini CLI..."
914
npm install -g @google/gemini-cli
15+
log_success "Gemini CLI setup complete! Run 'gemini' to start."
1016
fi
11-
12-
echo "✅ Gemini CLI setup complete! Run 'gemini' to start."
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#!/bin/bash
2-
set -euo pipefail
2+
# Source shared utilities
3+
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
4+
# shellcheck source=scripts/utils.sh
5+
source "$SCRIPT_DIR/utils.sh"
36

4-
# Change to the repository root relative to the script's location
5-
cd "$(dirname "${BASH_SOURCE[0]}")/.."
7+
ensure_root
68

7-
echo "🚀 Starting Antigravity Devcontainer environment..."
9+
log_info "Starting Antigravity Devcontainer environment..."
810

911
# 1. Check existing environment variables and apply Git configuration
10-
echo "Checking environment variables..."
12+
log_info "Checking environment variables and Git configuration..."
1113
bash ./.devcontainer/boot-check.sh
1214

1315
# 2. Configure Git hooks via Makefile
14-
echo "Ensuring Git hooks are configured..."
16+
log_info "Ensuring Git hooks are configured..."
1517
make setup
1618

17-
echo "Container startup complete."
19+
log_success "Container startup complete."
Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,83 @@
11
#!/bin/bash
2-
set -u
2+
set -euo pipefail
33

4-
echo "🔍 Starting Devcontainer Troubleshooting..."
5-
echo "----------------------------------------"
4+
# Source shared utilities
5+
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
6+
# shellcheck source=scripts/utils.sh
7+
source "$SCRIPT_DIR/utils.sh"
8+
9+
ensure_root
610

7-
# Change to the repository root relative to the script's location
8-
cd "$(dirname "${BASH_SOURCE[0]}")/.." || exit
11+
log_info "Starting Devcontainer Troubleshooting..."
12+
echo "----------------------------------------"
913

1014
ISSUE_FOUND=0
1115

1216
# 1. Check for .env file
13-
echo "Checking for .env file..."
17+
log_info "Checking for .env file..."
1418
if [ ! -f .env ]; then
15-
echo "❌ Error: .env file is missing."
19+
log_error ".env file is missing."
1620
if [ -f .env.example ]; then
17-
echo " -> .env.example found. Creating .env from template..."
21+
log_info ".env.example found. Creating .env from template..."
1822
cp .env.example .env
19-
echo ".env created. Please run './scripts/setup-env.sh' to populate it."
23+
log_success ".env created. Please run './scripts/setup-env.sh' to populate it."
2024
else
21-
echo " ❌ Error: .env.example is also missing. Cannot create .env block automatically."
25+
log_error ".env.example is also missing. Cannot create .env block automatically."
2226
ISSUE_FOUND=1
2327
fi
2428
else
25-
# Basic check to see if .env has been filled out (checking for placeholder values or empty critical values)
29+
# Basic check to see if .env has been filled out (checking for placeholder values)
2630
if grep -q "YOUR_GIT_NAME_HERE" .env || grep -q "YOUR_GIT_EMAIL_HERE" .env; then
27-
echo "⚠️ Warning: .env file contains placeholder values."
28-
echo " -> Please run './scripts/setup-env.sh' to configure your environment variables."
31+
log_warn ".env file contains placeholder values."
32+
log_info "Please run './scripts/setup-env.sh' to configure your environment variables."
2933
ISSUE_FOUND=1
3034
else
31-
echo ".env file found and appears to be configured."
35+
log_success ".env file found and appears to be configured."
3236
fi
3337
fi
3438
echo "----------------------------------------"
3539

3640
# 2. Check script permissions
37-
echo "Checking script permissions..."
41+
log_info "Checking script permissions..."
3842
PERM_ISSUE=0
39-
for script in scripts/*.sh templates/scripts/*.sh; do
40-
if [ -f "$script" ]; then
41-
if [ ! -x "$script" ]; then
42-
echo "❌ Error: $script is missing execute permissions."
43-
PERM_ISSUE=1
44-
fi
43+
# Check scripts in current scripts dir
44+
for script in scripts/*.sh; do
45+
if [ -f "$script" ] && [ ! -x "$script" ]; then
46+
log_error "$script is missing execute permissions."
47+
PERM_ISSUE=1
4548
fi
4649
done
4750

4851
if [ $PERM_ISSUE -eq 1 ]; then
49-
echo " -> Attempting to fix permissions..."
50-
chmod +x scripts/*.sh templates/scripts/*.sh 2>/dev/null || true
51-
echo "Added execute permissions to scripts."
52+
log_info "Attempting to fix permissions..."
53+
chmod +x scripts/*.sh 2>/dev/null || true
54+
log_success "Added execute permissions to scripts."
5255
else
53-
echo "All scripts have correct execute permissions."
56+
log_success "All scripts have correct execute permissions."
5457
fi
5558
echo "----------------------------------------"
5659

57-
# 3. Check for specific dependencies (e.g., Make, Git)
58-
echo "Checking dependencies..."
59-
if ! command -v make &> /dev/null; then
60-
echo "❌ Error: 'make' is not installed."
61-
echo " -> Please ensure your Devcontainer has the necessary build tools."
62-
ISSUE_FOUND=1
63-
else
64-
echo "✅ 'make' is installed."
65-
fi
60+
# 3. Check for specific dependencies
61+
log_info "Checking dependencies..."
62+
check_dep() {
63+
if ! command -v "$1" &> /dev/null; then
64+
log_error "'$1' is not installed."
65+
ISSUE_FOUND=1
66+
else
67+
log_success "'$1' is installed."
68+
fi
69+
}
6670

67-
if ! command -v git &> /dev/null; then
68-
echo "❌ Error: 'git' is not installed."
69-
echo " -> Git is required for this Devcontainer."
70-
ISSUE_FOUND=1
71-
else
72-
echo "✅ 'git' is installed."
73-
fi
71+
check_dep "make"
72+
check_dep "git"
73+
check_dep "gh"
7474
echo "----------------------------------------"
7575

7676
# Final summary
7777
if [ $ISSUE_FOUND -eq 1 ]; then
78-
echo "⚠️ Troubleshooting complete, but some issues require your attention."
79-
echo " Please review the warnings and errors above."
78+
log_warn "Troubleshooting complete, but some issues require your attention."
8079
exit 1
8180
else
82-
echo "🚀 Troubleshooting complete. Everything looks good!"
81+
log_success "Troubleshooting complete. Everything looks good!"
8382
exit 0
8483
fi

0 commit comments

Comments
 (0)