|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Exit immediately if a command exits with a non-zero status. |
| 4 | +set -e |
| 5 | + |
| 6 | +echo "--- Starting Joomla Core Post-Creation Setup ---" |
| 7 | + |
| 8 | +# Configuration variables |
| 9 | +DB_NAME="test_joomla" |
| 10 | +DB_USER="joomla_ut" |
| 11 | +DB_PASS="joomla_ut" |
| 12 | +ADMIN_USER="ci-admin" |
| 13 | +ADMIN_REAL_NAME="jane doe" |
| 14 | +ADMIN_PASS="joomla-17082005" |
| 15 | + |
| 16 | +JOOMLA_ROOT="/workspaces/joomla-cms" |
| 17 | + |
| 18 | +# Allow git commands to run safely in the container |
| 19 | +git config --global --add safe.directory $JOOMLA_ROOT |
| 20 | + |
| 21 | +# --- 1. Wait for MariaDB Service --- |
| 22 | +echo "--> Waiting for MariaDB to become available..." |
| 23 | +while ! mysqladmin ping -h"mysql" --silent; do |
| 24 | + sleep 1 |
| 25 | +done |
| 26 | +echo "✅ MariaDB is ready." |
| 27 | + |
| 28 | +# --- 2. Install Core Dependencies --- |
| 29 | +echo "--> Installing Composer and NPM dependencies..." |
| 30 | +composer install |
| 31 | +npm install |
| 32 | +echo "✅ Dependencies installed." |
| 33 | + |
| 34 | +# --- 3. Install Joomla from Repository Source --- |
| 35 | +echo "--> Installing Joomla using the local repository source..." |
| 36 | +rm -f configuration.php |
| 37 | +php installation/joomla.php install \ |
| 38 | + --site-name="Joomla CMS Test" \ |
| 39 | + --admin-user="$ADMIN_REAL_NAME" \ |
| 40 | + --admin-username="$ADMIN_USER" \ |
| 41 | + --admin-password="$ADMIN_PASS" \ |
| 42 | + --admin-email="$ADMIN_EMAIL" \ |
| 43 | + --db-type="mysqli" \ |
| 44 | + --db-host="mysql" \ |
| 45 | + --db-name="$DB_NAME" \ |
| 46 | + --db-user="$DB_USER" \ |
| 47 | + --db-pass="$DB_PASS" \ |
| 48 | + --db-prefix="jos_" \ |
| 49 | + --db-encryption="0" \ |
| 50 | + --public-folder="" |
| 51 | +echo "✅ Joomla installed." |
| 52 | + |
| 53 | +# --- 4. Configure Joomla for Development --- |
| 54 | +echo "--> Applying development settings..." |
| 55 | +# Enable debug mode and maximum error reporting for easier troubleshooting. |
| 56 | +php cli/joomla.php config:set error_reporting=maximum |
| 57 | +echo "✅ Development settings applied." |
| 58 | + |
| 59 | +# --- 5. Install and Configure phpMyAdmin --- |
| 60 | +PMA_ROOT="${JOOMLA_ROOT}/phpmyadmin" |
| 61 | +echo "--> Downloading phpMyAdmin into $PMA_ROOT..." |
| 62 | +PMA_VERSION=5.2.2 |
| 63 | +mkdir -p $PMA_ROOT |
| 64 | +curl -o /tmp/phpmyadmin.tar.gz https://files.phpmyadmin.net/phpMyAdmin/${PMA_VERSION}/phpMyAdmin-${PMA_VERSION}-all-languages.tar.gz |
| 65 | +tar xf /tmp/phpmyadmin.tar.gz --strip-components=1 -C $PMA_ROOT |
| 66 | +rm /tmp/phpmyadmin.tar.gz |
| 67 | +cp $PMA_ROOT/config.sample.inc.php $PMA_ROOT/config.inc.php |
| 68 | +sed -i "/\['AllowNoPassword'\] = false/a \$cfg['Servers'][\$i]['host'] = 'mysql';" $PMA_ROOT/config.inc.php |
| 69 | + |
| 70 | +# --- 6. Apply Codespaces Host Fix --- |
| 71 | +# This ensures Joomla generates correct URLs when accessed through the forwarded port. |
| 72 | +echo "--> Applying Codespaces URL fix..." |
| 73 | +cat > "${JOOMLA_ROOT}/fix.php" << 'EOF' |
| 74 | +<?php |
| 75 | +// Fix for incorrect host when running behind the Codespaces reverse proxy. |
| 76 | +if (isset($_SERVER['HTTP_HOST']) && str_contains($_SERVER['HTTP_HOST'], 'localhost')) { |
| 77 | + if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
| 78 | + $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST']; |
| 79 | + $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_X_FORWARDED_HOST']; |
| 80 | + } |
| 81 | +} |
| 82 | +EOF |
| 83 | + |
| 84 | +# Include fix in both entry points |
| 85 | +sed -i '2i require_once __DIR__ . "/fix.php";' $JOOMLA_ROOT/index.php |
| 86 | +sed -i '2i require_once __DIR__ . "/../fix.php";' $JOOMLA_ROOT/administrator/index.php |
| 87 | + |
| 88 | +echo "--> Ignoring local changes..." |
| 89 | +# For TRACKED files, tell Git to stop watching them for changes |
| 90 | +git update-index --assume-unchanged "index.php" |
| 91 | +git update-index --assume-unchanged "administrator/index.php" |
| 92 | +git update-index --assume-unchanged "package-lock.json" |
| 93 | +git update-index --assume-unchanged "tests/System/integration/install/Installation.cy.js" |
| 94 | +git update-index --assume-unchanged "tests/System/support/commands/config.mjs" |
| 95 | + |
| 96 | +# For NEW UNTRACKED files, add them to the local exclude file |
| 97 | +echo "cypress.config.js" >> ".git/info/exclude" |
| 98 | +echo "fix.php" >> ".git/info/exclude" |
| 99 | +echo "phpmyadmin" >> ".git/info/exclude" |
| 100 | +echo "codespace-details.txt" >> ".git/info/exclude" |
| 101 | + |
| 102 | +# --- 7. Finalize Permissions and Testing Tools --- |
| 103 | +echo "--> Setting up file permissions and Cypress..." |
| 104 | +sed -i \ |
| 105 | + -e "/\/\/ If exists, delete PHP configuration file to force a new installation/d" \ |
| 106 | + -e "/cy.task('deleteRelativePath', 'configuration.php');/d" \ |
| 107 | + -e "/cy.installJoomla(config);/d" \ |
| 108 | + tests/System/integration/install/Installation.cy.js |
| 109 | +sed -i "s/return cy.task('writeRelativeFile', { path: 'configuration.php', content });/return cy.task('writeRelativeFile', { path: 'configuration.php', content, mode: 0o775 });/" tests/System/support/commands/config.mjs |
| 110 | + |
| 111 | +# Ensure Cypress is executable and owned by the web server user |
| 112 | +chmod +x ./node_modules/.bin/cypress |
| 113 | +cp cypress.config.dist.mjs cypress.config.js |
| 114 | +npx cypress install |
| 115 | +sed -i -e "s|baseUrl:.*|baseUrl: 'https://localhost',|" -e "s/db_host: 'localhost'/db_host: 'mysql'/g" -e "s/db_user: 'root'/db_user: 'joomla_ut'/g" -e "s/db_password: ''/db_password: 'joomla_ut'/g" cypress.config.js |
| 116 | + |
| 117 | +# Restart Apache to apply all changes |
| 118 | +echo '<Directory /workspaces/joomla-cms> |
| 119 | + AllowOverride All |
| 120 | + Require all granted |
| 121 | +</Directory>' | sudo tee -a /etc/apache2/apache2.conf |
| 122 | +service apache2 restart |
| 123 | + |
| 124 | +# Set the group to www-data and enforce group permissions |
| 125 | +echo "--> Applying final group ownership and permissions..." |
| 126 | +chgrp -R www-data $JOOMLA_ROOT |
| 127 | +chmod -R g+rws $JOOMLA_ROOT |
| 128 | + |
| 129 | +echo "✅ Environment finalized." |
| 130 | + |
| 131 | +# --- 8. Display Setup Details --- |
| 132 | +# Save the details to a file for easy reference. |
| 133 | +DETAILS_FILE="${JOOMLA_ROOT}/codespace-details.txt" |
| 134 | +{ |
| 135 | + echo "" |
| 136 | + echo "---" |
| 137 | + echo "🚀 Joomla Core development environment is ready! 🚀" |
| 138 | + echo "" |
| 139 | + echo "This information has been saved to codespace-details.txt" |
| 140 | + echo "" |
| 141 | + echo "Joomla Admin Login:" |
| 142 | + echo " URL: Open the 'Ports' tab, find the 'Web Server' (443), and click the Globe icon. Then add /administrator" |
| 143 | + echo " Username: $ADMIN_USER" |
| 144 | + echo " Password: $ADMIN_PASS" |
| 145 | + echo "" |
| 146 | + echo "phpMyAdmin Login:" |
| 147 | + echo " URL: Open the 'Web Server' port and add /phpmyadmin" |
| 148 | + echo " Username: $DB_USER" |
| 149 | + echo " Password: $DB_PASS" |
| 150 | + echo "" |
| 151 | + echo "Cypress E2E Testing:" |
| 152 | + echo " Run interactive tests: npx cypress open" |
| 153 | + echo " Run headless tests: npx cypress run" |
| 154 | + echo "" |
| 155 | + echo "Xdebug for PHP Debugging:" |
| 156 | + echo " Xdebug is pre-configured on port 9003. Use the 'Run and Debug' panel in VS Code and select 'Listen for Xdebug'." |
| 157 | + echo "---" |
| 158 | +} | tee "$DETAILS_FILE" |
0 commit comments