From 6ffd91151e3484ed185f3ecbfb48327d35f56864 Mon Sep 17 00:00:00 2001 From: Nick Yeoman Date: Sat, 20 May 2023 13:37:56 -0700 Subject: [PATCH] trying to get installer working --- README.md | 6 ++- bin/docker_up.sh | 21 +++++++++- bin/inc_new_project/git_setup.sh | 1 + bin/inc_new_project/remote_git_setup.sh | 4 +- bin/new_project.sh | 5 +++ bin/setup_joomla_installer.sh | 51 +++++++++++++++++++++++++ env.sample | 8 +++- 7 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 bin/setup_joomla_installer.sh diff --git a/README.md b/README.md index 66fb954..d4fbb83 100644 --- a/README.md +++ b/README.md @@ -7,5 +7,7 @@ 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/new_project.sh -1. bash bin/docker_up.sh \ No newline at end of file +1. Prepare your project for git ```bash bin/new_project.sh``` +1. Run the containers to initialize ```sudo bash bin/docker_up.sh``` +1. Prepare the installer ```bash bin/setup_joomla_installer.sh``` + diff --git a/bin/docker_up.sh b/bin/docker_up.sh index 6725369..6a4a9f2 100644 --- a/bin/docker_up.sh +++ b/bin/docker_up.sh @@ -1,4 +1,23 @@ #!/bin/bash +if [ "$EUID" -ne 0 ]; then + echo -e "\033[0;31mThis script must be run as root.\033[0m" + exit 1 +fi + +# Load environment variables from .env file +set -o allexport +source .env +set +o allexport + +PROJECTNAME=$(basename "$(pwd)") + +if [ "$DEBUG" = "true" ]; then + docker ps +fi + rm -f html/index.html -sudo docker-compose up -d + +docker-compose up -d + +docker-compose ps \ No newline at end of file diff --git a/bin/inc_new_project/git_setup.sh b/bin/inc_new_project/git_setup.sh index 3923048..99b4559 100644 --- a/bin/inc_new_project/git_setup.sh +++ b/bin/inc_new_project/git_setup.sh @@ -12,6 +12,7 @@ echo "" > README.md echo "Created a fresh repo for your ${PROJECTNAME} project." >> README.md # Initialize a new Git repository +echo -e "\n\e[32mSetup Git Locally\e[0m\n"; git init git add . git commit -m "Initial commit of new project $PROJECTNAME" diff --git a/bin/inc_new_project/remote_git_setup.sh b/bin/inc_new_project/remote_git_setup.sh index be7b544..a7c5d3d 100644 --- a/bin/inc_new_project/remote_git_setup.sh +++ b/bin/inc_new_project/remote_git_setup.sh @@ -2,6 +2,8 @@ PROJECTNAME=$(basename "$(pwd)") +echo -e "\n\e[32mSetup Git Remotely\e[0m\n"; + if [ "$DEBUG" = "true" ]; then # Debugging echo "DEBUGGING" @@ -40,8 +42,6 @@ if [ "$DEBUG" = "true" ]; then echo "$SSH_URL" fi -echo "Repository '$PROJECTNAME' created successfully on Gitea." - # Add new remote repository git remote add origin "$SSH_URL" git remote -v diff --git a/bin/new_project.sh b/bin/new_project.sh index 2e54409..8ec346a 100644 --- a/bin/new_project.sh +++ b/bin/new_project.sh @@ -17,7 +17,12 @@ set +o allexport # Run Git setup bash bin/inc_new_project/git_setup.sh +if [ "$GITEA_API_URL" = "REPLACEME" ]; then + SETGITEA=false +fi + # Run remote Git setup if [ "$SETGITEA" = "true" ]; then bash bin/inc_new_project/remote_git_setup.sh fi +echo -e "\e[32mAll Done\e[0m"; \ No newline at end of file diff --git a/bin/setup_joomla_installer.sh b/bin/setup_joomla_installer.sh new file mode 100644 index 0000000..9c4dc37 --- /dev/null +++ b/bin/setup_joomla_installer.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +PROJECTNAME=$(basename "$(pwd)") + +# Are you root? +if [ "$EUID" -ne 0 ]; then + echo -e "\033[0;31mThis script must be run as root.\033[0m" + exit 1 +fi + +################################################################## +# ENV file +################################################################## +# 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 + +################################################################## +# create json file +################################################################## + +DB_PREFIX=$(echo $RANDOM | md5sum | awk '{print substr($1, 1, 3)}')_ + +docker-compose exec -u www-data joomla sh -c "echo '{ + \"language\":\"en-GB\", + \"site_name\":\"$PROJECTNAME\", + \"admin_email\":\"$EMAIL\", + \"admin_user\":\"$JOOMLA_USER\", + \"admin_password\":\"$JOOMLA_PASSWORD\", + \"db_type\":\"mysql\", + \"db_host\":\"mariadb\", + \"db_user\":\"$MYSQL_USER\", + \"db_pass\":\"$MYSQL_PASSWORD\", + \"db_name\":\"$MYSQL_DATABASE\", + \"db_prefix\":\"$DB_PREFIX\", + \"db_old\":\"remove\", + \"helpurl\":\"https://joomla.org\" +}' > config.json" + +################################################################## +# run the installer +################################################################## + +docker-compose exec -u www-data joomla php cli/joomla.php core:install --file=config.json \ No newline at end of file diff --git a/env.sample b/env.sample index 367e949..f7f24f8 100644 --- a/env.sample +++ b/env.sample @@ -11,6 +11,10 @@ MYSQL_PASSWORD=REPLACEME MYSQL_DATABASE=REPLACEME # GITEA -GITEA_API_URL= -ACCESS_TOKEN= +GITEA_API_URL=REPLACEME +ACCESS_TOKEN=REPLACEME +# Joomla +EMAIL=noreply@example.com +JOOMLA_USER=admin +JOOMLA_PASSWORD=REPLACEME \ No newline at end of file