2024-01-30 21:34:03 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
name=''
|
|
|
|
http_port='80'
|
|
|
|
https_port='443'
|
|
|
|
root_path="$(pwd)"
|
|
|
|
verbose='false'
|
|
|
|
|
2024-10-02 18:55:22 +00:00
|
|
|
while getopts 'n:p:s:r:a:vh' flag; do
|
2024-01-30 21:34:03 +00:00
|
|
|
case "${flag}" in
|
|
|
|
n) name="${OPTARG}" ;;
|
|
|
|
p) http_port="${OPTARG}" ;;
|
|
|
|
s) https_port="${OPTARG}" ;;
|
|
|
|
r) root_path="${OPTARG}" ;;
|
2024-10-02 18:55:22 +00:00
|
|
|
a) phpver="${OPTARG}" ;;
|
2024-01-30 21:34:03 +00:00
|
|
|
v) verbose='true' ;;
|
|
|
|
h) echo "Variables"
|
|
|
|
echo "-n = Name of Container, Required"
|
|
|
|
echo "-p = Non-https Port Override, default 80"
|
|
|
|
echo "-s = Https Port Override, default 443"
|
|
|
|
echo "-r = Root Path for files and database, defaults to current working path"
|
2024-10-02 18:55:22 +00:00
|
|
|
echo "-a = PHP App Version, Default to 8.3"
|
2024-01-30 21:34:03 +00:00
|
|
|
echo "-v = Enable Verbose Mode"
|
|
|
|
exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
#Check if Docker is installed
|
|
|
|
echo "Checking if Docker is Installed..."
|
|
|
|
check_docker=$(command -v docker)
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "Docker must be installed to run this application"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "Docker looks to be installed"
|
|
|
|
if [ -z "$name" ]; then
|
|
|
|
echo "Name not set, please set it with -n"
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-10-02 20:21:49 +00:00
|
|
|
|
|
|
|
if [ -z "$phpver" ]; then
|
|
|
|
phpver=83;
|
|
|
|
fi
|
|
|
|
|
2024-01-30 21:34:03 +00:00
|
|
|
echo "Building Docker Image..."
|
|
|
|
user=$(whoami)
|
|
|
|
uid=$(id -u)
|
2024-10-14 19:15:11 +00:00
|
|
|
if [ ! -d "$root_path/user" ]; then
|
|
|
|
mkdir -p "$root_path/user";
|
2024-10-15 02:30:51 +00:00
|
|
|
mkdir -p "$root_path/user/logs/{apache,system}";
|
2024-01-30 21:34:03 +00:00
|
|
|
fi
|
2024-10-02 20:21:49 +00:00
|
|
|
$check_docker volume create "$name-mysql"
|
2024-10-15 02:30:51 +00:00
|
|
|
$check_docker run --pull=always -d -p "$http_port":80 -p "$https_port":443 -e PHPVER=$phpver -e environment=DEV --mount type=bind,source="$root_path"/user,target=/home/"$user" --mount type=bind,source="$(pwd)"/user/logs/apache,target=/etc/httpd/logs --mount type=bind,source="$(pwd)"/user/logs/system,target=/var/log -v"$name-mysql":/var/lib/mysql -e uid="$uid" -e user="$user" -e domain="$name-local.dev" --name "$name" repo.anhonesthost.net/cloud-hosting-platform/cac:latest
|
2024-01-30 21:34:03 +00:00
|
|
|
echo "Creating management scripts in root directory..."
|
|
|
|
echo "#!/usr/bin/env bash" > "$root_path/instance_start"
|
|
|
|
echo "docker start $name" >> "$root_path/instance_start"
|
|
|
|
echo "#!/usr/bin/env bash" > "$root_path/instance_stop"
|
|
|
|
echo "docker stop $name" >> "$root_path/instance_stop"
|
|
|
|
echo "#!/usr/bin/env bash" > "$root_path/instance_logs"
|
|
|
|
echo "docker exec $name bash -c 'tail -f /etc/httpd/logs/*'" >> "$root_path/instance_logs"
|
|
|
|
echo "#!/usr/bin/env bash" > "$root_path/instance_db_info"
|
|
|
|
echo "docker exec $name cat /var/lib/mysql/creds" >> "$root_path/instance_db_info"
|
|
|
|
chmod +x $root_path/instance_*
|
2024-10-02 20:21:49 +00:00
|
|
|
echo "Waiting 160 seconds for setup to finish"
|
|
|
|
sleep 160;
|
2024-01-30 21:34:03 +00:00
|
|
|
echo "Installing WordPress..."
|
2024-01-31 00:40:42 +00:00
|
|
|
wpdbuser=$(docker exec $name cat /var/lib/mysql/creds |grep User| awk -F ": " {'print $2'})
|
|
|
|
wpdbpass=$(docker exec $name cat /var/lib/mysql/creds |grep Password| awk -F ": " {'print $2'})
|
|
|
|
wpdb=$(docker exec $name cat /var/lib/mysql/creds |grep Database| awk -F ": " {'print $2'})
|
|
|
|
docker exec $name bash -c "cd /home/$(whoami)/public_html; wp core download; wp config create --dbname=$wpdb --dbuser=$wpdbuser --dbpass=$wpdbpass ; chown -R $(whoami):$(whoami) /home/$(whoami)/public_html;"
|
2024-01-30 21:34:03 +00:00
|
|
|
echo "Local Development Instance Created, to stop run ./instance_stop from within the base directory"
|
|
|
|
echo "MySQL DB Credentials"
|
|
|
|
docker exec $name cat /var/lib/mysql/creds
|
|
|
|
exit 0
|