#!/usr/bin/env bash set -euo pipefail ROOT_DIR="${1:-/var/www/atomcms/app}" SERVER_NAME="${2:-_}" PHP_VERSION="8.5" echo "Preparing system packages" sudo apt-get update -y sudo apt-get install -y software-properties-common curl gnupg2 ca-certificates lsb-release echo "Adding PHP repository" sudo add-apt-repository -y ppa:ondrej/php sudo apt-get update -y echo "Installing PHP ${PHP_VERSION} and extensions" sudo apt-get install -y "php${PHP_VERSION}-fpm" "php${PHP_VERSION}-cli" "php${PHP_VERSION}-curl" "php${PHP_VERSION}-mbstring" "php${PHP_VERSION}-gd" "php${PHP_VERSION}-intl" "php${PHP_VERSION}-mysql" "php${PHP_VERSION}-bcmath" "php${PHP_VERSION}-zip" echo "Installing Nginx" sudo apt-get install -y nginx echo "Installing Composer and Yarn" sudo apt-get install -y composer nodejs npm sudo npm install -g yarn echo "Ensuring application directory exists: ${ROOT_DIR}" if [ ! -d "${ROOT_DIR}" ]; then echo "Directory ${ROOT_DIR} does not exist. Clone the repository into this path and rerun." exit 1 fi cd "${ROOT_DIR}" if [ ! -f ".env" ]; then cp .env.example .env || true fi echo "Installing PHP dependencies" composer install --no-interaction --prefer-dist --optimize-autoloader echo "Generating app key" php artisan key:generate || true echo "Installing JS dependencies" yarn install --silent echo "Building assets (Atom theme)" yarn run build:atom echo "Setting permissions" sudo chown -R www-data:www-data storage bootstrap/cache sudo chmod -R 775 storage bootstrap/cache NGINX_CONF="/etc/nginx/sites-available/atomcms.conf" echo "Writing Nginx server block to ${NGINX_CONF}" sudo tee "${NGINX_CONF}" >/dev/null < " else echo "Installing Certbot..." sudo apt-get install -y certbot python3-certbot-nginx echo "Running Certbot for ${SERVER_NAME}..." # Running non-interactively where possible, but certbot often requires email/tos interaction on first run. # We assume the user is running this interactively. sudo certbot --nginx -d "${SERVER_NAME}" echo "SSL setup complete!" fi fi