#!/bin/bash # # Create new Drupal installation # + database # + database user # D="\e[0;31m" G="\e[0;32m" B="\e[0;34m" W="\e[0;97m" BOLDRED="\e[1;31m" BOLDGRN="\e[1;32m" BOLDBLU="\e[1;34m" BOLDWHT="\e[1;97m" E="\e[00m" DBUSER="root" DBPASS="1234" NAME=$1 SITES="/var/www/sites" DRUSH_DIR="${SITES}/${NAME}/vendor/drush/drush" function ok() { echo -e "${BOLDGRN} [ OK ]${E}" } function fail() { echo -e "${BOLDRED} [FAIL]${E}" echo exit } echo echo -ne " 💧 Create new drupal in dir ${W}$NAME${E} ..." COMPOSER_ALLOW_SUPERUSER=1 composer --no-interaction create-project drupal/recommended-project $NAME # CMD="composer --no-interaction create-project drupal/recommended-project $NAME" # sudo su -l apache -s /bin/bash -c "$CMD" # sudo su -l apache -s /bin/bash -c "cd $PWD; $CMD" # composer --no-interaction create-project drupal/recommended-project:9.5.10 $NAME > /dev/null 2>&1 #CMD="composer --no-interaction create-project drupal/recommended-project:9 $NAME > /dev/null 2>&1" #CMD="composer create-project drupal/recommended-project:9 $NAME" if [ $? = 0 ]; then ok; else fail; fi echo -ne " 🐬 Create database ${W}$NAME${E} ..." mysql -uroot -p1234 -e "CREATE DATABASE $NAME" if [ $? = 0 ]; then ok; else fail; fi echo -ne " 🐬 Create database user ${W}$NAME${E} with password '1234' ..." mysql -uroot -p1234 -e "CREATE USER $NAME@localhost IDENTIFIED BY \"1234\"" if [ $? = 0 ]; then ok; else fail; fi echo -ne " 🐬 Grand user ${W}${NAME}${E} permissions to database ${W}${NAME}${E} ..." mysql -uroot -p1234 -e "GRANT ALL ON $NAME.* TO $NAME@localhost" if [ $? = 0 ]; then ok; else fail; fi echo -ne " 🐬 Flush privilages ..." mysql -uroot -p1234 -e "FLUSH PRIVILEGES" if [ $? = 0 ]; then ok; else fail; fi cd $NAME/web # echo -e " 🍒 Drupal settings.php" # cp sites/default/default.settings.php sites/default/settings.php # cat >> sites/default/settings.php < '$NAME', # 'username' => '$NAME', # 'password' => '1234', # 'prefix' => '', # 'host' => 'localhost', # 'port' => '3306', # 'namespace' => 'Drupal\\\\mysql\\\\Driver\\\\Database\\\\mysql', # 'driver' => 'mysql', # 'autoload' => 'core/modules/mysql/src/Driver/Database/mysql/', # ); # EOL # if [ $? = 0 ]; then ok; else fail; fi mkdir sites/default/files echo -ne " 🐷 Change files owner to user ${W}apache${E}" chown apache:apache ${SITES}/${NAME}/web -R if [ $? = 0 ]; then ok; else fail; fi find . -type d -exec chmod 755 {} \; find . -type f -exec chmod 644 {} \; #echo -ne " 🍒 link html to ${W}$NAME${E}" #unlink /var/www/html #ln -s /var/www/sites/$NAME/web /var/www/html #if [ $? = 0 ]; then ok; else fail; fi echo ls -l --color=auto /var/www/site[1234567890] echo echo -en "Enter directory to link the new site (0-9): " read -n 1 answer if [[ "$answer" =~ ^([0123456789])$ ]]; then /var/www/sites/site${answer} ${NAME}/web fi # echo -ne " 🌈 Restart httpd " # systemctl restart httpd # if [ $? = 0 ]; then ok; else fail; fi # # echo -ne " 🌈 Restart php " # systemctl restart php-fpm # if [ $? = 0 ]; then ok; else fail; fi # # echo -ne " 🌈 Restart mysql " # systemctl restart mysql # if [ $? = 0 ]; then ok; else fail; fi echo -e "Finish the installation..." echo echo -e "${W}Database${E}: ${NAME}" echo -e "${W}Username${E}: ${NAME}" echo -e "${W}Password${E}: 1234" echo read -p "...and press [ENTER] to continue installing extra modules" echo cd ${SITES}/${NAME} function add_drush() { COMPOSER_ALLOW_SUPERUSER=1 composer require 'drush/drush' --no-interaction } echo -e "${W}Drush${E}" echo -e " 📦 drush" echo -en "Enable modules? (y/n): " read -n 1 answer [ $answer = "y" ] && add_drush echo function add_aliases() { COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/pathauto' --no-interaction ${DRUSH_DIR}/drush en pathauto -y } echo -e "${W}URL Aliases${E}" echo -e " 📦 pathauto" echo -en "Enable modules? (y/n): " read -n 1 answer [ $answer = "y" ] && add_aliases echo function add_rest() { COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/restui' --no-interaction COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/rest_views' --no-interaction COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/rest_export_nested' --no-interaction ${DRUSH_DIR}/drush en serialization -y ${DRUSH_DIR}/drush en rest -y ${DRUSH_DIR}/drush en restui -y ${DRUSH_DIR}/drush en rest_views -y ${DRUSH_DIR}/drush en rest_export_nested -y } echo -e "${W}Rest API Server${E}" echo -e " 📦 serialization" echo -e " 📦 rest" echo -e " 📦 restui" echo -e " 📦 restviews" echo -e " 📦 rest_export_nested" echo -en "Enable modules? (y/n): " read -n 1 answer [ $answer = "y" ] && add_rest echo function add_import() { COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/feeds' --no-interaction COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/feeds_tamper' --no-interaction COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/delete_all' --no-interaction ${DRUSH_DIR}/drush en feeds -y ${DRUSH_DIR}/drush en feeds_tamper -y ${DRUSH_DIR}/drush en delete_all -y } echo -e "${W}Import Data${E}" echo -e " 📦 feeds" echo -e " 📦 feeds_tamper" echo -e " 📦 delete_all" echo -en "Enable modules? (y/n): " read -n 1 answer [ $answer = "y" ] && add_import echo function add_devel() { COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/devel' --no-interaction ${DRUSH_DIR}/drush cr ${DRUSH_DIR}/drush en devel_generate -y } echo -e "${W}Import Data${E}" echo -en "Enable modules? (y/n): " read -n 1 answer [ $answer = "y" ] && add_devel echo # composer require 'drupal/rpb:^1.0@beta' #composer require 'drupal/decoupled_rest_views:^1.0@alpha' #composer require 'drupal/entity_rest_extra:^2.1' #composer require 'drupal/rest_entity_recursive:^2.0@RC' # Devel # composer require 'drupal/devel' # rm -rf vendor/autoload.php vendor/autoload_runtime.php vendor/composer # composer install # drush cr # drush en devel_generate