Skip to content

Instantly share code, notes, and snippets.

@kcristiano
Created November 6, 2017 20:17
Show Gist options
  • Save kcristiano/0d0bf49f271874fc98e695269cc5b419 to your computer and use it in GitHub Desktop.
Save kcristiano/0d0bf49f271874fc98e695269cc5b419 to your computer and use it in GitHub Desktop.
new site creation - Debian Jessie
#!/bin/bash
projectdir=/home
homedir=/home
echo -n "Enter user name: "
read username
echo -n "Enter the CiviCRM version you need (eg 4.7.26) and press [ENTER]: "
read civiver
echo -n "Enter the WP version you need (eg 4.8) and press [ENTER]: "
read wpver
webdir=public_html
weburl=$username.example.org
sitename=$username.example.org
dbname=$username
dbuser=$username
adminuser=tadpole
adminemail=webmaster@example.org
sec=https
branch=stable
wwwuser=www-data
dbpass=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
adminpwd=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)
useradd -m $username
chsh -s /bin/bash $username
echo $homedir/$username
echo "Creating Directories at $homedir/$username";
mkdir -p $homedir/$username/$webdir
mkdir -p $homedir/$username/log
mkdir -p $homedir/$username/conf
mkdir -p $homedir/$username/.ssh
mkdir -p $homedir/$username/.wp-cli/commands/civicrm
mkdir -p $homedir/$username/tadupdates
cp /root/keys/authorized_keys $homedir/$username/.ssh
chown -R $username:$username $homedir/$username/
vhost="
<VirtualHost *:80>
ServerName $weburl
Redirect permanent / https://$weburl
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/example.org.crt
SSLCertificateKeyFile /etc/apache2/ssl/example.org.key
SSLCertificateChainFile /etc/apache2/ssl/example.org.bundle
ServerAdmin $adminemail
ServerName $weburl
Header always add Strict-Transport-Security \"max-age=15768000\"
DocumentRoot $homedir/$username/$webdir/
DirectoryIndex index.html index.php
# Log file locations
LogLevel warn
ErrorLog $homedir/$username/log/error.log
CustomLog $homedir/$username/log/access.log combined
<Directory />
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<IfModule mod_fastcgi.c>
AddType application/x-httpd-fastphp5 .php
Action application/x-httpd-fastphp5 /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi_$weburl
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi_$weburl -socket /var/run/php5-fpm_$weburl.sock -pass-header Authorization
</IfModule>
<IfModule mpm_itk_module>
AssignUserId $username $username
</IfModule>
<IfModule suexec_module>
SuexecUserGroup $username $username
</IfModule>
</VirtualHost>"
printf "$vhost" > /tmp/$weburl.conf
echo "Trying to add $weburl.conf";
if [ -f /etc/apache2/sites-available/$weburl.conf ]
then
echo "The site seems to exist. Please re-run the script with a different sitename."
exit 1
else
sudo cp /tmp/$weburl.conf /etc/apache2/sites-available/
echo "$sitename Created successfully.";
fi
sudo a2ensite $weburl.conf
sudo service apache2 reload
cd $homedir/$username/$webdir
mysql -e "CREATE DATABASE $dbname"
mysql -e "GRANT ALL PRIVILEGES ON $dbname.* TO $dbuser@localhost IDENTIFIED BY '$dbpass'"
chown -R $username:$username $homedir/$username/
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir core download --version=$wpver
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir core config --dbname=$dbname --dbuser=$dbuser --dbpass=$dbpass
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir core install --url="$sec://$weburl" --admin_user="$adminuser" --admin_password="$adminpwd" --admin_email="$adminemail" --title="$title"
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir rewrite structure "/%postname%/"
wget -q -P $projectdir/$username/tadupdates/ https://download.civicrm.org/civicrm-$civiver-wordpress.zip
git clone https://develop.tadpole.cc/civicrm-plugins/civicrm-wpcli.git $projectdir/$username/tadupdates/cvwpcli
git clone https://github.com/mecachisenros/caldera-forms-civicrm.git $projectdir/$username/$webdir/wp-content/plugins/caldera-forms-civicrm
git clone https://github.com/christianwach/civicrm-event-organiser.git $projectdir/$username/$webdir/wp-content/plugins/civicrm-event-organiser
git clone https://develop.tadpole.cc/civicrm-plugins/tc-cms-override.git $projectdir/$username/$webdir/wp-content/plugins/tc-cms-override
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir option set timezone_string America/New_York
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install iwp-client
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install restricted-site-access
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install nav-menu-roles
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install tinymce-advanced
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install better-wp-security
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install caldera-forms
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install all-in-one-seo-pack
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install civicrm-admin-utilities
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install civicrm-wp-member-sync
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install civicrm-wp-profile-sync
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install jetpack
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install members
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install jetpack-module-control
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install stop-emails
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install user-switching
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin install event-organiser
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir civicrm install --dbhost=localhost --dbname=$dbname --dbpass=$dbpass --dbuser=$dbuser --site_url=$weburl --zipfile=$homedir/$username/tadupdates/civicrm-$civiver-wordpress.zip --require=$projectdir/$username/tadupdates/cvwpcli/civicrm.php --ssl=on
extdir=$homedir/$username/$webdir/wp-content/uploads/civicrm/ext
git clone https://develop.tadpole.cc/extensions/cc.tadpole.csshelper.git $extdir/cc.tadpole.csshelper
git clone https://github.com/eileenmcnaughton/nz.co.fuzion.extendedreport.git $extdir/nz.co.fuzion.extendedreport
git clone https://github.com/cividesk/com.cividesk.email.sparkpost.git $extdir/cividesk.email.sparkpost
git clone https://github.com/progressivetech/net.ourpowerbase.sumfields.git $extdir/net.ourpowerbase.sumfields
git clone https://github.com/mlutfy/ca.bidon.reporterror.git $extdir/ca.bidon.reporterror
git clone https://develop.tadpole.cc/extensions/org.civicrm.module.cividiscount.git $extdir/civicrm.module.cividiscount
git clone https://github.com/aghstrategies/com.aghstrategies.directorylinks.git $extdir/com.aghstrategies.directorylinks
sudo -u $username -i -- wp --path=$projectdir/$username/$webdir plugin activate civicrm-admin-utilities
chown -R $username:$username $homedir/$username/
echo -e "\n Site created at $sec://$weburl \n"
echo -e "DB $dbname \n"
echo -e "DBUser $dbuser \n"
echo -e "DB Password $dbpass \n"
echo -e "Admin Password $adminpwd \n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment