#$/bin/bash # # needs # # 1. database dump # 2. settings.php # # 1. clone drupal files from git # 2. install drupal # 3. create database # 4. create database user # RED="\e[0;31m" GRN="\e[0;32m" BLU="\e[0;34m" WHT="\e[0;97m" BOLDRED="\e[1;31m" BOLDGRN="\e[1;32m" BOLDBLU="\e[1;34m" BOLDWHT="\e[1;97m" END="\e[00m" BITBUCKET_USER='stevaidis' BITBUCKET_PASS='ATBBTztz2mBYTYyy88WhGZUGNQmS712ED6FC' REPO="bitbucket.org/dotsoft-sa/$1.git" NAME=$2 DBUSER="root" DBPASS="1234" # ./clone.sh https://stevaidis@bitbucket.org/dotsoft-sa/goint-backend.git function ok() { echo -e "${BOLDGRN}[ OK ]${END}" } function fail() { echo -e "${BOLDRED}[FAIL]${EMD}" exit } echo if [ ! -f $NAME.sql ]; then echo -e "\n 😿 Database dump file ${BOLDBLU}$NAME.sql${END} does not exist here \n" exit fi if [ ! -f $NAME.settings.php ]; then echo -e "\n 😿 Settings file ${BOLDBLU}$NAME.settings.php${END} does not exist here \n" exit fi git ls-remote --quiet https://${BITBUCKET_USER}:${BITBUCKET_PASS}@${REPO} > /dev/null if [ $? -ne 0 ]; then echo -e "\n 😿 Cant access this repository in bitbucket \n" exit fi echo -ne " 🍄 Clone repo to dir: $NAME ..." #git clone --quiet https://${BITBUCKET_USER}:${BITBUCKET_PASS}@${REPO} ${NAME} > /dev/null git clone https://${BITBUCKET_USER}:${BITBUCKET_PASS}@${REPO} ${NAME} if [ $? = 0 ]; then ok; else fail; fi echo "`date +'%d/%m/%Y %H:%M:%S'` Fresh clone" > $NAME.copy.log cd $NAME cp ../$NAME.settings.php sites/default/settings.php #echo -ne " 🍒 Switch to new branch $NAME ..." #git checkout --quiet -b $2 > /dev/null #if [ $? = 0 ]; then ok; else fail; fi echo -ne " 🐬 Create database user $NAME with password '${DBPASS}' ..." mysql -u${DBUSER} -p${DBPASS} -e "CREATE USER $NAME@localhost IDENTIFIED BY \"${DBPASS}\"" if [ $? = 0 ]; then ok; else fail; fi echo -ne " 🐬 Create database $NAME ..." mysql -u${DBUSER} -p${DBPASS} -e "CREATE DATABASE $NAME" if [ $? = 0 ]; then ok; else fail; fi echo -ne " 🐬 Grand user ${NAME} permissions database ${NAME} ..." mysql -u${DBUSER} -p${DBPASS} -e "GRANT ALL ON $NAME.* TO $NAME@localhost" if [ $? = 0 ]; then ok; else fail; fi echo -ne " 🐬 Flush privilages ..." mysql -u${DBUSER} -p${DBPASS} -e "FLUSH PRIVILEGES" if [ $? = 0 ]; then ok; else fail; fi echo -ne " 🐬 Import $NAME.sql ..." mysql -u${DBUSER} -p${DBPASS} $NAME < ../$NAME.sql if [ $? = 0 ]; then ok; else fail; fi echo -ne " 🧰 Composer install ... " COMPOSER_ALLOW_SUPERUSER=1 composer install > ../$NAME.composer.log 2>&1 if [ $? = 0 ]; then ok; else fail; fi echo -ne " 🐷 Change files owner to user ${BOLDWHT}apache${END}" chown apache:apache * -R if [ $? = 0 ]; then ok; else fail; fi echo -e " 🚀 Ready to go!" echo