#!/bin/bash # Initialize a new VPS project with automatic Gitea remote configuration # # Usage: init-project # Example: init-project my-app # # This script: # - Creates a new project directory # - Initializes git repository # - Configures Gitea SSH remote automatically # - Copies agents to .claude/agents/ for Claude Code # - Sets up git user info set -e PROJECT_NAME="${1:?Error: Project name required. Usage: init-project }" # Verify valid project name if [[ ! "$PROJECT_NAME" =~ ^[a-zA-Z0-9._-]+$ ]]; then echo "❌ Invalid project name: $PROJECT_NAME" echo " Use only alphanumeric characters, dots, hyphens, and underscores" exit 1 fi GITEA_HOST="100.120.125.113" GITEA_ORG="pdm" REPO_URL="git@$GITEA_HOST:$GITEA_ORG/$PROJECT_NAME.git" AGENTS_SOURCE="$HOME/.homelab-agents/agents" # Check if directory already exists if [[ -d "$PROJECT_NAME" ]]; then echo "❌ Directory already exists: $PROJECT_NAME" exit 1 fi # Check for SSH key (needed for git push to work) if [[ ! -f "$HOME/.ssh/id_ed25519" ]] && [[ ! -f "$HOME/.ssh/id_rsa" ]]; then echo "⚠️ Warning: No SSH key found" echo " For git push to work, you need to:" echo " 1. Generate SSH key: ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519" echo " 2. Add to Gitea: http://100.120.125.113:3000 → Settings → SSH Keys" echo "" fi echo "📁 Creating project directory: $PROJECT_NAME" mkdir -p "$PROJECT_NAME" cd "$PROJECT_NAME" echo "🔧 Initializing git repository..." git init git config user.name "Homelab Automation" git config user.email "automation@homelab" git branch -M main echo "🔗 Configuring Gitea SSH remote..." git remote add origin "$REPO_URL" echo "📚 Setting up Claude Code agents..." mkdir -p ".claude/agents" # Copy agents from homelab-agents if available if [[ -d "$AGENTS_SOURCE" ]]; then cp "$AGENTS_SOURCE"/*.md ".claude/agents/" 2>/dev/null || true AGENT_COUNT=$(find ".claude/agents" -name "*.md" | wc -l) if [[ $AGENT_COUNT -gt 0 ]]; then echo "✅ Copied $AGENT_COUNT agent(s) to .claude/agents/" fi else echo "⚠️ Note: ~/.homelab-agents not found, agents not copied" echo " You can manually copy agents later or run bootstrap-agents.sh" fi echo "" echo "✅ Project initialized successfully!" echo "" echo "📋 Project Details:" echo " Name: $PROJECT_NAME" echo " Directory: $(pwd)" echo " Remote: $REPO_URL" echo " Branch: main" echo " Agents: .claude/agents/" echo "" echo "🚀 Next steps:" echo " 1. Start working in this directory" echo " 2. Create files and make changes" echo " 3. When done, use the summary agent: .claude/agents/sysadmin-session-closer.md" echo " 4. Agent will automatically commit and push to Gitea (via SSH)"