-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-site.sh
More file actions
executable file
·92 lines (75 loc) · 2.71 KB
/
create-site.sh
File metadata and controls
executable file
·92 lines (75 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# ----------------------------------------------------------------------------
# Joomla Docker CLI - Create Site Script
# Author: Siddiqur
# Description: Interactive script to create new Joomla sites on unique ports.
# ----------------------------------------------------------------------------
set -e
SITE_NAME=$1
ADMIN_USERNAME=$2
ADMIN_EMAIL=$3
ADMIN_PASSWORD=$4
# Interactive Mode: Prompt for missing arguments
if [[ -z "$SITE_NAME" ]]; then
read -p "Enter Site Name: " SITE_NAME
fi
if [[ -z "$SITE_NAME" ]]; then
echo "Site Name is Required"
exit 1;
fi
if [[ -z "$ADMIN_USERNAME" ]]; then
read -p "Enter Admin Username (default: dev): " input_user
ADMIN_USERNAME=${input_user:-dev}
fi
if [[ -z "$ADMIN_EMAIL" ]]; then
read -p "Enter Admin Email (default: dev@mail.com): " input_email
ADMIN_EMAIL=${input_email:-dev@mail.com}
fi
if [[ -z "$ADMIN_PASSWORD" ]]; then
# Generate random password if not provided
ADMIN_PASSWORD=$(tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 15 )
echo "Generated Password: $ADMIN_PASSWORD"
elif [[ ${#ADMIN_PASSWORD} -lt 12 ]]; then
echo "Password must be longer than 12 characters"
exit 1;
fi
# Port Allocation Logic: Find first available port starting from 8080
BASE_PORT=8080
PORT=$BASE_PORT
echo "Allocating port..."
while true; do
# Check if this PORT is used in any docker-compose file in ./sites
# We look for the pattern "- PORT:80" specifically.
if grep -r "\- $PORT:80" ./sites >/dev/null 2>&1; then
PORT=$((PORT+1))
else
echo "Found available port: $PORT"
break
fi
done
# create a folder from the site name
if [ ! -d ./sites/$SITE_NAME ]; then
mkdir -p ./sites/$SITE_NAME/
fi
# copy the template to compose file inside the site folder if it doesn't exist
if [ ! -f ./sites/$SITE_NAME/compose.yml ]; then
cp ./template.yml ./sites/$SITE_NAME/compose.yml
fi
# replace template.yml variable value with bash variable value
# Using sed -i '' for macOS compatibility (BSD sed)
sed -i '' "s/SITENAME/$SITE_NAME/g" ./sites/$SITE_NAME/compose.yml
sed -i '' "s/JOOMLA_USERNAME/$ADMIN_USERNAME/g" ./sites/$SITE_NAME/compose.yml
sed -i '' "s/JOOMLA_PASSWORD/$ADMIN_PASSWORD/g" ./sites/$SITE_NAME/compose.yml
sed -i '' "s/JOOMLA_MAIL/$ADMIN_EMAIL/g" ./sites/$SITE_NAME/compose.yml
sed -i '' "s/JOOMLA_PORT/$PORT/g" ./sites/$SITE_NAME/compose.yml
# run docker compose up to run the services
cd ./sites/$SITE_NAME
docker compose up -d
SITE_URL="http://localhost:$PORT"
echo "Preparing your website. Please wait...."
sleep 10
echo "Your website is ready 🎉"
echo "Site url: $SITE_URL"
echo "Your site username: $ADMIN_USERNAME"
echo "Your site email : $ADMIN_EMAIL"
echo "Your site password: $ADMIN_PASSWORD"