#!/bin/bash # Create Gitea repository via API and push code set -e GITEA_URL="192.168.68.53:3000" GITEA_API="http://${GITEA_URL}/api/v1" TOKEN="77d13be9a7dbae402cb21c08d9231047a645e050" # Get username and repo name if [ -z "$1" ] || [ -z "$2" ]; then echo "Usage: $0 " echo "" echo "Example: $0 kyle ha-kiosk-dashboard" exit 1 fi USERNAME="$1" REPO_NAME="$2" REPO_URL="http://${TOKEN}@${GITEA_URL}/${USERNAME}/${REPO_NAME}.git" cd /home/kyle/scripts echo "Gitea Repository Setup" echo "=====================" echo "Username: ${USERNAME}" echo "Repository: ${REPO_NAME}" echo "" # Check if git is installed if ! command -v git &> /dev/null; then echo "Installing git..." sudo apt-get update sudo apt-get install -y git fi # Check if curl is installed if ! command -v curl &> /dev/null; then echo "Installing curl..." sudo apt-get install -y curl fi # Check if repository exists via API echo "Checking if repository exists..." REPO_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" \ -H "Authorization: token ${TOKEN}" \ "${GITEA_API}/repos/${USERNAME}/${REPO_NAME}") if [ "$REPO_EXISTS" = "200" ]; then echo "✓ Repository already exists" elif [ "$REPO_EXISTS" = "404" ]; then echo "Repository doesn't exist, creating via API..." # Create repository via API RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \ -H "Authorization: token ${TOKEN}" \ -H "Content-Type: application/json" \ -d "{ \"name\": \"${REPO_NAME}\", \"description\": \"Home Assistant Kiosk Dashboard Setup\", \"private\": false, \"auto_init\": false }" \ "${GITEA_API}/user/repos") HTTP_CODE=$(echo "$RESPONSE" | tail -n1) BODY=$(echo "$RESPONSE" | sed '$d') if [ "$HTTP_CODE" = "201" ]; then echo "✓ Repository created successfully!" elif [ "$HTTP_CODE" = "409" ]; then echo "Repository already exists (409 conflict)" else echo "✗ Failed to create repository" echo "HTTP Code: ${HTTP_CODE}" echo "Response: ${BODY}" exit 1 fi else echo "✗ Unexpected response: ${REPO_EXISTS}" exit 1 fi # Initialize git if needed if [ ! -d .git ]; then echo "Initializing git repository..." git init git config user.name "kyle" git config user.email "kyle@localhost" git branch -M main fi # Create .gitignore if needed if [ ! -f .gitignore ]; then cat > .gitignore << 'EOF' # Logs *.log /tmp/ # Backup files *.backup *~ # Python cache __pycache__/ *.pyc *.pyo # OS files .DS_Store Thumbs.db EOF fi # Configure credential helper git config credential.helper "store --file=/home/kyle/scripts/.git-credentials" || true # Add all files echo "Adding files..." git add -A # Commit if there are changes if ! git diff --staged --quiet; then echo "Committing changes..." git commit -m "Home Assistant kiosk dashboard setup - Dashboard YAML configurations with card-mod - Browser Mod automation for auto-scrolling - Display rotation and sleep disable scripts - Home Assistant API query scripts - Dashboard launcher scripts - Setup guides and documentation" else echo "No changes to commit" fi # Remove existing remote if it exists git remote remove origin 2>/dev/null || true # Add remote with token authentication echo "Adding remote repository..." git remote add origin "${REPO_URL}" # Push to repository echo "Pushing to Gitea..." echo "Repository: http://${GITEA_URL}/${USERNAME}/${REPO_NAME}" echo "" git push -u origin main echo "" echo "✓ Successfully pushed to Gitea!" echo "Repository URL: http://${GITEA_URL}/${USERNAME}/${REPO_NAME}"