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