Created
April 22, 2019 16:55
-
-
Save gbeezus/cf7e86f1fab0a1ded5ed64d01e279f1b to your computer and use it in GitHub Desktop.
Drupal Installation Shell Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
drush=/usr/local/bin/drush | |
#check if drush exists before running rest of script | |
type $drush >/dev/null 2>&1 || { echo >&2 "I require drush but it's not installed. Aborting."; exit 1; } | |
#define default variables | |
profile_d=standard | |
acctname_d=Admin | |
acctmail_d="[email protected]" | |
sitemail_d=$acctmail_d | |
sitename_d="New Site" | |
drupalfile=drupal-8.3.3.tar.gz | |
drupalurl=https://ftp.drupal.org/files/projects/$drupalfile | |
#get site nickname and use for mysql and vhost | |
while [[ -z $sitenickname ]] | |
do | |
echo "Please enter nickname that's lowercase with letters, numbers, & underscore no more than 10 characters" | |
read -p "Site nickname: " sitenickname | |
if [[ -z $sitenickname ]]; then | |
echo "Whoops, need the new site's nickname" | |
fi | |
if [ -f /etc/httpd/vhost.d/${sitenickname}.conf ]; then | |
echo "Oh no! Your nickname is already taken. Try another one." | |
sitenickname="" | |
fi | |
done | |
dbname=${sitenickname}_drupal | |
dbuser=$dbname | |
dbpass="`apg -a 1 -n 1 -m 15 -M NCL`" | |
#get domain name | |
while [[ -z $domainname ]] | |
do | |
read -p "Domain name (e.g. example.com): " domainname | |
if [[ -z $domainname ]]; then | |
echo "Whoops, need the new site's domain name" | |
fi | |
done | |
#get MySQL root user password | |
while [[ -z $rootpass ]] | |
do | |
read -sp "MySQL Root user password: " rootpass | |
if [[ -z $rootpass ]]; then | |
echo "Hey, I need the MySQL root user's password" | |
else | |
echo -e "\r" | |
fi | |
done | |
read -p "Drupal profile ($profile_d): " profile | |
profile=${profile:-$profile_d} | |
while [[ -z $acctpass ]] | |
do | |
read -sp "Account password: " acctpass | |
if [[ -z $acctpass ]]; then | |
echo "Whoops, need account password" | |
else | |
echo -e "\r" | |
fi | |
done | |
read -p "Site name ($sitename_d): " sitename | |
sitename=${sitename:-$sitename_d} | |
#create vhost directory | |
mkdir /var/www/vhosts/$domainname | |
mkdir /var/www/vhosts/$domainname/public_html | |
#uncomment to download from drupal | |
#curl -o /var/www/vhosts/$domainname/public_html/$drupalfile $drupalurl | |
#tar -zxf /var/www/vhosts/$domainname/public_html/$drupalfile --strip-components=1 -C /var/www/vhosts/$domainname/public_html/ | |
#rm /var/www/vhosts/$domainname/public_html/$drupalfile | |
#comment out when downloading from drupal | |
chown -R [SHELL USER]:apache /var/www/vhosts/$domainname/public_html | |
cd /var/www/vhosts/$domainname/public_html | |
su -c 'git clone [GIT REPOSITORY FOR BASE TEMPLATE] .' [SHELL USER] | |
su -c 'git remote rm origin' [SHELL USER] | |
rm -rf .git | |
cd ~ | |
mkdir /var/www/vhosts/$domainname/public_html/sites/default/files | |
chown -R [SHELL USER]:apache /var/www/vhosts/$domainname/public_html | |
find /var/www/vhosts/$domainname/public_html -type d -exec chmod u=rwx,go=rx '{}' \; | |
find /var/www/vhosts/$domainname/public_html -type f -exec chmod u=rw,go=r '{}' \; | |
find /var/www/vhosts/$domainname/public_html/sites -type d -name files -exec chmod ug=rwx,o=rx '{}' \; | |
echo -e "New vhost directory created at /var/www/vhosts/${domainname}/public_html.\nDrupal Downloaded and extracted.\nPermissions set." | |
#configure vhost | |
cat > /etc/httpd/vhost.d/${sitenickname}.conf <<- EOF | |
<VirtualHost *:80> | |
DocumentRoot /var/www/vhosts/${domainname}/public_html | |
ServerName ${domainname} | |
ServerAlias ${sitenickname}.company.com | |
<Directory /> | |
Options Indexes FollowSymLinks | |
AllowOverride All | |
</Directory> | |
ErrorLog /var/www/vhosts/${domainname}/error.log | |
CustomLog /var/www/vhosts/${domainname}/requests.log common | |
</VirtualHost> | |
EOF | |
echo "Vhost configuration saved at /etc/httpd/vhost.d/${sitenickname}.conf" | |
#create mysql database | |
mysql -u root -p$rootpass -e "create database ${dbname}; GRANT ALL PRIVILEGES ON ${dbname}.* TO ${dbuser}@localhost IDENTIFIED BY '${dbpass}'" | |
echo "New database $dbname. New user $dbuser granted all privileges on $dbname" | |
cd /var/www/vhosts/$domainname/public_html | |
su -c 'find . -type f -print0 | xargs -0 sed -i "s/new_theme/$0/g"' [SHELL USER] -- ${sitenickname} | |
su -c 'mv ./themes/custom/new_theme ./themes/custom/$0' [SHELL USER] -- ${sitenickname} | |
su -c 'mv ./modules/custom/new_theme_custom_functions ./modules/custom/$0_custom_functions' [SHELL USER] -- ${sitenickname} | |
find /var/www/vhosts/$domainname/public_html -type f -name '*new_theme*' | while read FILE ; do newfile="$(echo ${FILE} |sed -e 's/new_theme/'${sitenickname}'/g')" ; mv "${FILE}" "${newfile}" ; done | |
su -c '$0 site-install $1 --db-url=mysql://$2:$3@localhost/$4 --account-mail="$5" --account-name=$6 --account-pass="$7" --site-mail="$8" --site-name="$9" install_configure_form.update_status_module="array(FALSE,FALSE)" install_configure_form.site_default_country=US' [SHELL USER] -- $drush $profile $dbname $dbpass $dbuser $acctmail_d $acctname_d $acctpass $sitemail_d "$sitename" | |
chown -R [SHELL USER]:apache /var/www/vhosts/$domainname/public_html | |
su -c '$0 en [ORG]_default_content' [SHELL USER] -- $drush | |
su -c '$0 config-set system.site page.front /node/1' [SHELL USER] -- $drush | |
cd ~ | |
#update files permissions | |
#for d in /var/www/vhosts/$domainname/public_html/sites/*/files | |
#do | |
# find $d -type d -exec chmod ug=rwx,o=rx '{}' \; | |
# find $d -type f -exec chmod ug=rw,o=r '{}' \; | |
#done | |
apachectl restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment