From ea06fb48d7a28dd1e8d48811869997dffc120ff4 Mon Sep 17 00:00:00 2001 From: Nick Yeoman Date: Sat, 20 May 2023 02:01:52 -0700 Subject: [PATCH] added new project script --- README.md | 8 +++++-- bin/installJoomla.bash | 0 bin/new_project.sh | 49 ++++++++++++++++++++++++++++++++++++++++++ env.sample | 7 +++++- 4 files changed, 61 insertions(+), 3 deletions(-) delete mode 100644 bin/installJoomla.bash create mode 100644 bin/new_project.sh diff --git a/README.md b/README.md index 1b927dc..a74ed15 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,11 @@ Joomla CMS. +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. mv env.sample .env -1. vi .env +1. cd projectName +1. Setup your .env file ```mv env.sample .env``` then edit with your favorite editor. +1. bash bin + 1. sudo docker-compose up -d \ No newline at end of file diff --git a/bin/installJoomla.bash b/bin/installJoomla.bash deleted file mode 100644 index e69de29..0000000 diff --git a/bin/new_project.sh b/bin/new_project.sh new file mode 100644 index 0000000..56e4821 --- /dev/null +++ b/bin/new_project.sh @@ -0,0 +1,49 @@ +#!/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 \ No newline at end of file diff --git a/env.sample b/env.sample index 1cc440c..bebcec4 100644 --- a/env.sample +++ b/env.sample @@ -5,4 +5,9 @@ NETWORKNAME=admin_web MYSQL_ROOT_PASSWORD=REPLACEME MYSQL_USER=REPLACEME MYSQL_PASSWORD=REPLACEME -MYSQL_DATABASE=REPLACEME \ No newline at end of file +MYSQL_DATABASE=REPLACEME + +# GITEA +GITEA_API_URL= +ACCESS_TOKEN= +