diff --git a/README.md b/README.md index a74ed15..c37dfea 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,5 @@ Make sure the projectName is set correctly, it's very important. 1. Clone me ```git clone git@git.nickyeoman.com:nick/joomla.git projectName``` 1. cd projectName 1. Setup your .env file ```mv env.sample .env``` then edit with your favorite editor. -1. bash bin - +1. bash bin/new_project.sh 1. sudo docker-compose up -d \ No newline at end of file diff --git a/bin/new_project.sh b/bin/new_project.sh index 56e4821..3b20e69 100644 --- a/bin/new_project.sh +++ b/bin/new_project.sh @@ -1,6 +1,7 @@ #!/bin/bash -PROJECTNAME=$(pwd) +PROJECTNAME=$(basename "$(pwd)") +SETGITEA=true # Verify the .env file exists if [ ! -f ".env" ]; then @@ -13,37 +14,10 @@ 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 +# Run Git setup +bash bin/new_project/git_setup.sh + +# Run remote Git setup +if [ "$SETGITEA" = "true" ]; then + bash bin/new_project/remote_git_setup.sh 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 \ No newline at end of file diff --git a/bin/new_project/git_setup.sh b/bin/new_project/git_setup.sh new file mode 100644 index 0000000..3923048 --- /dev/null +++ b/bin/new_project/git_setup.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +PROJECTNAME=$(basename "$(pwd)") + +# Remove existing Git repository information +rm -rf .git + +rm README.md +touch README.md +echo "# ${PROJECTNAME}" > README.md +echo "" > README.md +echo "Created a fresh repo for your ${PROJECTNAME} project." >> README.md + +# Initialize a new Git repository +git init +git add . +git commit -m "Initial commit of new project $PROJECTNAME" diff --git a/bin/new_project/remote_git_setup.sh b/bin/new_project/remote_git_setup.sh new file mode 100644 index 0000000..be7b544 --- /dev/null +++ b/bin/new_project/remote_git_setup.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +PROJECTNAME=$(basename "$(pwd)") + +if [ "$DEBUG" = "true" ]; then + # Debugging + echo "DEBUGGING" + echo "GITEA API url: $GITEA_API_URL" + echo "Access token: $ACCESS_TOKEN" + echo "Project name: $PROJECTNAME"; +fi + +DESC="Repo auto created by Joomla remote git script creator for $PROJECTNAME" + +# Create the repository using Gitea API +RESPONSE=$(curl -s -X POST \ + -H "Authorization: token $ACCESS_TOKEN" \ + -H "Content-Type: application/json" \ + -d "{\"name\":\"$PROJECTNAME\",\"private\": true,\"description\": \"$DESC\"}" \ + $GITEA_API_URL/user/repos) + +if [ "$DEBUG" = "true" ]; then + echo "The RESPONSE:" + echo "$RESPONSE" +fi + +if [ -z "$RESPONSE" ] || [ "$(echo "$RESPONSE" | jq -r '.id')" = "null" ]; then + echo "Error: Failed to create $PROJECTNAME repository." + exit 1 +fi + +SSH_URL=$(echo "$RESPONSE" | jq -r '.ssh_url') +if [ "$SSH_URL" = "null" ]; then + echo "Error: Failed to retrieve SSH URL for $PROJECTNAME repository." + exit 1 +fi + +if [ "$DEBUG" = "true" ]; then + echo "SSH URL:" + echo "$SSH_URL" +fi + +echo "Repository '$PROJECTNAME' created successfully on Gitea." + +# Add new remote repository +git remote add origin "$SSH_URL" +git remote -v + +# Commit existing changes +git push -u origin master \ No newline at end of file diff --git a/env.sample b/env.sample index bebcec4..367e949 100644 --- a/env.sample +++ b/env.sample @@ -1,3 +1,6 @@ +# Run Scripts +DEBUG=false + # Docker NETWORKNAME=admin_web diff --git a/html/index.html b/html/index.html new file mode 100644 index 0000000..fef99e4 --- /dev/null +++ b/html/index.html @@ -0,0 +1 @@ + \ No newline at end of file