|
| 1 | +#!/bin/bash |
| 2 | +set -eo pipefail |
| 3 | + |
| 4 | +# Change default umask and add user to web group so we can share write permission on web files |
| 5 | +sed -i 's/^#umask\s*022/umask 002/' ~/.profile |
| 6 | +echo "umask 002" >> ~/.zshrc |
| 7 | +echo "umask 002" >> ~/.bashrc |
| 8 | + |
| 9 | +sudo sh -c "cat >> /etc/apache2/sites-available/000-default.conf" <<EOF |
| 10 | +<Directory /var/www/html> |
| 11 | + AllowOverride All |
| 12 | +</Directory> |
| 13 | +EOF |
| 14 | + |
| 15 | +# This is how the example codespace changes the docroot. If it's good enough for them, it's good enough for me. |
| 16 | +sudo chmod a+x "$(pwd)" && sudo rm -rf /var/www/html && sudo ln -s "$(pwd)/web" /var/www/html |
| 17 | + |
| 18 | +# Setup database |
| 19 | +sudo service mariadb start |
| 20 | +sudo mysql -u$MYSQL_USER -e "SET PASSWORD=PASSWORD('$MYSQL_PASSWORD')" |
| 21 | +cat <<EOF > ~/.my.cnf |
| 22 | +[client] |
| 23 | +user="$MYSQL_USER" |
| 24 | +password="$MYSQL_PASSWORD" |
| 25 | +EOF |
| 26 | +mysqladmin create $MYSQL_DATABASE |
| 27 | + |
| 28 | +# and cache |
| 29 | +sudo service redis-server start |
| 30 | + |
| 31 | +# translate mysql env vars to our template vars |
| 32 | +export DB_HOST="$MYSQL_HOST" DB_PORT="$MYSQL_TCP_PORT" DB_USER="$MYSQL_USER" DB_PASSWORD="$MYSQL_PASSWORD" DB_NAME="$MYSQL_DATABASE" |
| 33 | + |
| 34 | +# Setup our Drupal app |
| 35 | +composer dev-initialize-local |
| 36 | +cat >> web/sites/default/settings.local.php <<EOF |
| 37 | +\$settings['trusted_host_patterns'] = []; |
| 38 | +
|
| 39 | +# make drupal play nice with codespace proxy |
| 40 | +\$settings['reverse_proxy'] = TRUE; |
| 41 | +\$settings['reverse_proxy_addresses'] = array(\$_SERVER['REMOTE_ADDR']); |
| 42 | +EOF |
| 43 | + |
| 44 | +composer install |
| 45 | +composer compile-theme |
| 46 | + |
| 47 | +# Set file permissions so both httpd and user can write to files |
| 48 | +chgrp www-data web/sites/default/files |
| 49 | +chmod g+s web/sites/default/files |
| 50 | + |
| 51 | +# Setup VS Code |
| 52 | +mkdir -p .vscode |
| 53 | +cp /usr/local/etc/uceap-dev/vscode-launch.json .vscode/launch.json |
0 commit comments