#!/bin/bash PROJECTNAME=$(pwd) # Verify the .env file exists if [ ! -f ".env" ]; then echo "Error: The .env file does not exist." exit 1 fi # Load environment variables from .env file set -o allexport source .env set +o allexport # Verify the required environment variables are set if [ -z "$GITEA_API_URL" ] || [ -z "$ACCESS_TOKEN" ]; then echo "Error: Please make sure GITEA_API_URL and ACCESS_TOKEN are set in the .env file." exit 1 fi # Create the repository using Gitea API RESPONSE=$(curl -sSL -H "Authorization: token $ACCESS_TOKEN" -H "Content-Type: application/json" -X POST -d "{\"name\":\"$PROJECTNAME\"}" "$GITEA_API_URL/api/v1/user/repos") # Check the API response and handle errors STATUS=$(echo "$RESPONSE" | jq -r '.message') if [ "$STATUS" != "null" ]; then echo "Error: Failed to create $PROJECTNAME repository. $STATUS" exit 1 fi echo "Repository '$PROJECTNAME' created successfully on Gitea." # Remove existing Git repository information rm -rf .git # Initialize a new Git repository git init # Add new remote repository git remote add origin "$GITEA_API_URL/$PROJECTNAME.git" # Confirm remote configuration git remote -v # Commit existing changes git add . git commit -m "Initial commit of new project $PROJECTNAME" git push -u origin master