├── README.md ├── see-option-on-all-sites.sh ├── see-all-sites-with-gravity-forms.sh ├── backup ├── db.sh ├── support.sh ├── webmail.sh ├── dev.sh ├── web1.sh ├── web2.sh ├── check.sh └── force-backup.sh ├── create-pages-in-bulk.sh ├── update-all.sh ├── wp-cli-install.sh ├── firewall-wp-admin.conf ├── .bashrc ├── wp-install-windows.cmd └── wp-install.sh /README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /see-option-on-all-sites.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Foreach site show the site option blogname 4 | 5 | for url in $( wp site list --field=url --url=http://site.com | sort -u ) 6 | do 7 | echo $url 8 | wp option get blogname 9 | done 10 | 11 | -------------------------------------------------------------------------------- /see-all-sites-with-gravity-forms.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Loop through all the sites and show the blog number and 4 | # and then the count of how many gravity forms are on the site 5 | 6 | for blog_id in $(wp site list --field=blog_id --url=http://www.site.com | sort -u ) 7 | do 8 | echo $blog_id 9 | wp db query "select count(id) from wp_${blog_id}_rg_form" 10 | done 11 | -------------------------------------------------------------------------------- /backup/db.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This is to backup the database server. 4 | 5 | array=( 6 | "/etc" 7 | "/home" 8 | "/root" 9 | ) 10 | 11 | for i in "${array[@]}" 12 | do 13 | filename="/home/backup/db.webhostonbarter.com/""${i##*/}"".tgz" 14 | tar zcfP - $i | ssh -i /home/backup/.ssh/id_rsa backup@backup.webhostonbarter.com "cat > $filename" 15 | done 16 | -------------------------------------------------------------------------------- /backup/support.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This backups the support server 4 | 5 | array=( 6 | "/etc" 7 | "/home" 8 | "/root" 9 | "/usr/local/nagios" 10 | "/var/lib/gitolite3" 11 | "/var/www/html" 12 | ) 13 | 14 | for i in "${array[@]}" 15 | do 16 | filename="/home/backup/support.webhostonbarter.com/""${i##*/}"".tgz" 17 | tar zcfP - $i | ssh -i /home/backup/.ssh/id_rsa backup@backup.webhostonbarter.com "cat > $filename" 18 | done 19 | -------------------------------------------------------------------------------- /backup/webmail.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This backups the web sites in /var/www/, email and other folders 4 | 5 | array=( 6 | "/etc" 7 | "/home" 8 | "/var/vmail" 9 | "/var/www/" 10 | "/root" 11 | ) 12 | 13 | for i in "${array[@]}" 14 | do 15 | filename="/home/backup/webmail.webhostonbarter.com/""${i##*/}"".tgz" 16 | tar zcfP - $i | ssh -i /home/backup/.ssh/id_rsa backup@backup.webhostonbarter.com "cat > $filename" 17 | done 18 | -------------------------------------------------------------------------------- /backup/dev.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This is to backup the dev server 4 | 5 | array=( 6 | "/etc" 7 | "/home" 8 | "/root" 9 | ) 10 | 11 | for i in $( find /var/www/html -maxdepth 1 -type d | grep -v '/var/www/html$' ) 12 | do 13 | array=("${array[@]}" $i) 14 | done 15 | 16 | for i in "${array[@]}" 17 | do 18 | filename="/home/backup/dev.webhostonbarter.com/""${i##*/}"".tgz" 19 | tar zcfP - $i | ssh -i /home/backup/.ssh/id_rsa backup@backup.webhostonbarter.com "cat > $filename" 20 | done 21 | -------------------------------------------------------------------------------- /backup/web1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This backups the web sites in /var/www/html and extra folders 4 | 5 | array=( 6 | "/etc" 7 | "/home" 8 | "/root" 9 | ) 10 | 11 | for i in $( find /var/www/html -maxdepth 1 -type d | grep -v '/var/www/html$' ) 12 | do 13 | array=("${array[@]}" $i) 14 | done 15 | 16 | for i in "${array[@]}" 17 | do 18 | filename="/home/backup/web1.webhostonbarter.com/""${i##*/}"".tgz" 19 | tar zcfP - $i | ssh -i /home/backup/.ssh/id_rsa backup@backup.webhostonbarter.com "cat > $filename" 20 | done 21 | -------------------------------------------------------------------------------- /backup/web2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This backups the web sites in /var/www/html and extra folders 4 | 5 | array=( 6 | "/etc" 7 | "/home" 8 | "/root" 9 | ) 10 | 11 | for i in $( find /var/www/html -maxdepth 1 -type d | grep -v '/var/www/html$' ) 12 | do 13 | array=("${array[@]}" $i) 14 | done 15 | 16 | for i in "${array[@]}" 17 | do 18 | filename="/home/backup/web2.webhostonbarter.com/""${i##*/}"".tgz" 19 | tar zcfP - $i | ssh -i /home/backup/.ssh/id_rsa backup@backup.webhostonbarter.com "cat > $filename" 20 | done 21 | -------------------------------------------------------------------------------- /create-pages-in-bulk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # First admin user for post authorship 4 | userID=1 5 | 6 | pages=( 'Home' 'About' 'Contact Us' ) 7 | 8 | for page in "${pages[@]}"; do 9 | wp post create --post_type=page --post_title="$page" --post_status=publish --post_author=$userID --porcelain --quiet 10 | 11 | echo "wp post create $page" 12 | done 13 | 14 | wp menu create "Menu" 15 | 16 | export IFS=" " 17 | 18 | for pageID in $( wp post list --order="ASC" --orderby="ID" --post_type=page --post_status=publish --posts_per_page=-1 --field=ID --format=ids ); do 19 | wp menu item add-post menu $pageID 20 | done 21 | 22 | wp menu location assign menu primary 23 | -------------------------------------------------------------------------------- /backup/check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This is run to verify the backups are done which gets emailed to me 4 | 5 | array=( 6 | "/home/backup/db.webhostonbarter.com" 7 | "/home/backup/dev.webhostonbarter.com" 8 | "/home/backup/support.webhostonbarter.com" 9 | "/home/backup/web1.webhostonbarter.com" 10 | "/home/backup/web2.webhostonbarter.com" 11 | "/home/backup/webmail.webhostonbarter.com" 12 | ) 13 | 14 | df -h | grep -v 'tmpfs' 15 | 16 | echo "" 17 | echo "" 18 | echo "" 19 | 20 | for i in "${array[@]}" 21 | do 22 | ls $i -lAhrS | awk '{print $5 " " $6 " " $7 " " $8 " " $9}' | grep -v '\.$' 23 | du -h $i 24 | echo "" 25 | echo "" 26 | echo "" 27 | done 28 | -------------------------------------------------------------------------------- /update-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # changing ownership so that we can update all files 4 | chown -R jpurpleman:jpurpleman /var/www/html 5 | 6 | root="/var/www/html" 7 | 8 | # Changing directory into where all the sites are setup 9 | cd $root 10 | 11 | # Loop through all the sites 12 | for site in *; 13 | do 14 | 15 | path="$root/$site" 16 | 17 | if [[ -d $path ]]; then 18 | 19 | # Go into the site folder 20 | cd "$root/$site" 21 | 22 | pwd 23 | 24 | # Update WordPress core 25 | wp core update --allow-root 26 | 27 | # Update WordPress db after core update 28 | wp core update-db --allow-root 29 | 30 | echo "" 31 | 32 | fi; 33 | done 34 | 35 | # Change ownership back to apache after update so people can use WordPress admin 36 | chown -R apache:apache /var/www/html 37 | -------------------------------------------------------------------------------- /backup/force-backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This is to force the backup to run when not running on the crontab 4 | # https://saltstack.com/ 5 | 6 | echo "db" 7 | salt "db.webhostonbarter.com" cmd.run "/root/scripts/backup/db.sh" 8 | 9 | echo "" 10 | echo "dev" 11 | salt "dev.webhostonbarter.com" cmd.run "/root/scripts/backup/dev.sh" 12 | 13 | echo "" 14 | echo "support" 15 | salt "support.webhostonbarter.com" cmd.run "/root/scripts/backup/support.sh" 16 | 17 | echo "" 18 | echo "webmail" 19 | salt "webmail.webhostonbarter.com" cmd.run "/root/scripts/backup/webmail.sh" 20 | 21 | echo "" 22 | echo "web1" 23 | salt "web1.webhostonbarter.com" cmd.run "/root/scripts/backup/web1.sh" 24 | 25 | echo "" 26 | echo "Checking backup..." 27 | salt "backup.webhostonbarter.com" cmd.run "/root/scripts/backup/check.sh | mail -s 'Backup Results' email@domain.com" 28 | -------------------------------------------------------------------------------- /wp-cli-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Define the servers by host name or ip address 4 | servers=( 'web1.example.com' 'web2.example.com' ) 5 | 6 | # Download WP-CLI locally 7 | curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar 8 | 9 | # Loop throuh the servers 10 | for server in "${servers[@]}"; do 11 | 12 | echo $server 13 | 14 | # Send wp-cli over to the server with a user on the box 15 | scp ./wp-cli.phar user@$server: 16 | 17 | #Send a command to run on the box - make wp-cli executable 18 | ssh user@$server "chmod +x wp-cli.phar" 19 | 20 | #Send a command to run on the box - Move the phar file to a good location and file name 21 | ssh user@$server "sudo mv wp-cli.phar /usr/local/bin/wp" 22 | 23 | #Send a command to run on the box - Test wp-cli 24 | ssh user@$server "/usr/local/bin/wp --info" 25 | done 26 | 27 | # delete the file locally 28 | rm ./wp-cli.phar 29 | -------------------------------------------------------------------------------- /firewall-wp-admin.conf: -------------------------------------------------------------------------------- 1 | # Block access to wp-login.php to said ips 2 | location ~ ^/(wp-login\.php){ 3 | 4 | allow XXX.XXX.XXX.XXX; # Specific IP 5 | allow XXX.XXX.XXX.0/24; # Network range of IPs 6 | allow 127.0.0.1; # The machine itself for cronjobs 7 | deny all; # Block the rest - sends a 403 Forbidden 8 | 9 | include /etc/nginx/php.conf; 10 | } 11 | 12 | # For the folder of /wp-admin 13 | location /wp-admin { 14 | 15 | # Allow access to wp-admin/admin-ajax.php 16 | location ~ ^/(wp-admin/admin-ajax\.php) { 17 | include /etc/nginx/php.conf; 18 | } 19 | 20 | # Block access to wp-admin/*php to said ips 21 | location ~* /wp-admin/.*\.php$ { 22 | 23 | allow XXX.XXX.XXX.XXX; # Specific IP 24 | allow XXX.XXX.XXX.0/24; # Network range of IPs 25 | allow 127.0.0.1; # The machine itself for cronjobs 26 | deny all; # Block the rest - sends a 403 Forbidden 27 | 28 | include /etc/nginx/php.conf; 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /.bashrc: -------------------------------------------------------------------------------- 1 | # .bashrc 2 | 3 | # Source global definitions 4 | if [ -f /etc/bashrc ]; then 5 | . /etc/bashrc 6 | fi 7 | 8 | # User specific aliases and functions 9 | 10 | alias wordpress-salt='wget https://api.wordpress.org/secret-key/1.1/salt/ -qO-' 11 | 12 | alias wordpress-update-all='wp core update && wp core update-db && wp plugin update --all && wp theme update --all' 13 | 14 | alias wordpress-remove-default-widgets='wp widget delete search-2 && wp widget delete recent-posts-2 && wp widget delete recent-comments-2 && wp widget delete archives-2 && wp widget delete categories-2 && wp widget delete meta-2' 15 | 16 | alias wordpress-delete-sample-page='wp post delete $( wp post list --post_type=page --posts_per_page=1 --post_status=publish --pagename="sample-page" --field=ID --format=ids )' 17 | 18 | function git-wp-commit-object() { 19 | 20 | # Get the current directory 21 | startdir=${PWD##*/} 22 | 23 | # Check to see if we're in a plugin or theme folder 24 | if [[ ! -f ../../../wp-config.php ]]; then 25 | echo "Can't find the wp-config.php file. Are you in a plugin or theme directory?" 26 | echo "" 27 | echo "Currently in: $startdir" 28 | echo "" 29 | echo "Exiting..." 30 | else 31 | 32 | # We're in a plugin or theme folder, find out which one, plugin or theme 33 | cd .. 34 | wpcontent_folder=${PWD##*/} 35 | cd $startdir 36 | 37 | # Convert "plugins" to plugin or "themes" to theme or in other words remove the last character 38 | object="${wpcontent_folder%?}" 39 | 40 | # Get details about the wordpress object we want to commit 41 | # Get the title of the plugin or theme we're committing 42 | title=$(wp ${object} get ${startdir} --field=title) 43 | 44 | # Get the version of the plugin or theme we're committing 45 | version=$(wp ${object} get ${startdir} --field=version) 46 | 47 | # Check to see if it's in the repo already or not 48 | git ls-files . --error-unmatch > /dev/null 2>&1; 49 | 50 | # Create parts of the commit message conditionally 51 | if [ $? == 0 ]; then 52 | action="Updating" 53 | direction="to" 54 | else 55 | action="Adding" 56 | direction="at" 57 | fi 58 | 59 | # Add all files to git that have been added or modified 60 | git add . 61 | 62 | # Add all files to git that have been deleted or moved 63 | git add . -u 64 | 65 | # Git commit! with appropriate message 66 | git commit -m "$action $object: $title $direction version $version" 67 | 68 | # Print that message 69 | echo "$action $object: $title $direction version $version" 70 | 71 | fi 72 | } 73 | -------------------------------------------------------------------------------- /wp-install-windows.cmd: -------------------------------------------------------------------------------- 1 | :: Written for EQ WordPress Advanced: Theme Development 2 | :: By Jonathan Perlman 3 | :: jperlman@dawsoncollege.qc.ca 4 | :: Feb. 2, 2016 5 | 6 | :: Variables for modification 7 | 8 | :: Used in the folder name of the WordPress install 9 | SET SHORT_PROJECT_NAME="wordpress" 10 | 11 | :: Use of " has to to be = \" 12 | SET SITE_TITLE="EQ WordPress Advanced: Theme Development" 13 | 14 | :: Information for the "5 - minute install" 15 | :: Admin login for designer / developer in the WordPress Dashboard 16 | SET WPUSER="developer" 17 | SET WPPASSWORD="wordpress" 18 | SET WPEMAIL="developer@email.com" 19 | 20 | :: Information for the wp-config.php. Modify per project 21 | SET DBNAME="wp_project" 22 | SET DBUSER="wp_project" 23 | SET DBPASS="wp_project" 24 | 25 | :: Web root of local web server 26 | SET ROOT=C:\wamp\www\ 27 | 28 | :: Modification after this point is at your own risk! 29 | 30 | ::------------------------------------------------------------------------------- 31 | 32 | :: MySql database stuff 33 | mysql -u root -e "DROP DATABASE IF EXISTS %DBNAME%;" 34 | mysql -u root -e "CREATE DATABASE IF NOT EXISTS %DBNAME%;" 35 | mysql -u root -e "GRANT ALL ON %DBNAME%.* TO %DBUSER%@localhost IDENTIFIED BY '%DBPASS%';" 36 | mysql -u root -e "FLUSH PRIVILEGES;" 37 | 38 | :: Changing to directory of installation 39 | cd %ROOT% 40 | 41 | :: Delete the install folder 42 | echo Y | del /Q /S %SHORT_PROJECT_NAME% 43 | 44 | :: Create the install folder 45 | mkdir %SHORT_PROJECT_NAME% 46 | 47 | :: Change directory into the install folder 48 | cd %SHORT_PROJECT_NAME% 49 | 50 | :: Downloading the latest version of WordPress Core 51 | call wp core download --version="4.4.2" 52 | 53 | :: Creating wp-config.php 54 | call wp core config --dbname="%DBNAME%" --dbuser="%DBUSER%" --dbpass="%DBPASS%" 55 | 56 | :: Doing "5 - Minute install" 57 | call wp core install --url="http://localhost/%SHORT_PROJECT_NAME%" --title=%SITE_TITLE% --admin_user="%WPUSER%" --admin_password="%WPPASSWORD%" --admin_email="%WPEMAIL%" 58 | 59 | :: Creating child theme for students to use 60 | call wp scaffold child-theme twentysixteen-child --parent_theme="twentysixteen" --theme_name="EQ WP Advanced Twenty Sixteen Theme" --author="Jonathan Perlman" --author_uri="http://www.dawsoncollege.qc.ca" --theme_uri="http://www.dawsoncollege.qc.ca" --activate 61 | 62 | :: Updating plugins 63 | call wp plugin update --all 64 | 65 | :: Updating themes 66 | call wp theme update --all 67 | 68 | :: set pretty urls 69 | :: we set pretty urls here to give it some time to complete before flushing the permalinks later 70 | :: unfortunatly call does not work on this command so we have to open and run in a seperate cmd window 71 | start cmd /c wp rewrite structure /%%year%%/%%monthnum%%/%%day%%/%%postname%%/ --hard 72 | 73 | :: unfortunatly call does not work on this command so we have to open and run in a seperate cmd window 74 | start cmd /c wp rewrite flush --hard 75 | 76 | :: Launch the default browser and bring up the home page of the new site 77 | start http://localhost/%SHORT_PROJECT_NAME% 78 | 79 | :: Hold the screen open and not close when done 80 | :: In the event of errors, remove the :: on the next two lines 81 | :: echo Press ENTER to execute the command 82 | :: pause > nul -------------------------------------------------------------------------------- /wp-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Author: Jonathan Perlman < jperlman@dawsoncollege.qc.ca > 4 | 5 | function display_help { 6 | echo "WordPress automatic installer" 7 | echo "" 8 | echo "Usage :" 9 | echo " wp-install.sh [action]" 10 | echo " wp-install.sh [action] [start] [end]" 11 | echo "" 12 | echo "Actions :" 13 | echo "-h --help Display this help" 14 | echo "-i --install Install wordpress" 15 | echo "-u --uninstall Uninstall wordpress" 16 | echo "" 17 | echo "start The starting number (optional)" 18 | echo "end The ending number (optional)" 19 | echo "" 20 | } 21 | 22 | # This is where all your new sites will reside 23 | BASEPATH="/var/www/html" 24 | 25 | # Super user password for mysql 26 | mysqlrootpassword="" 27 | 28 | 29 | # We need at least one argument 30 | if [ $# -lt 1 ]; then 31 | display_help 32 | exit 1 33 | fi 34 | 35 | # Check what action we need to perform 36 | case "$1" in 37 | '-i' | '--install') 38 | action='install' 39 | ;; 40 | '-u' | '--uninstall' ) 41 | action='uninstall' 42 | ;; 43 | '-h' | '--help' ) 44 | display_help 45 | exit 46 | ;; 47 | *) 48 | display_help 49 | exit 1 50 | ;; 51 | esac 52 | 53 | #################################################################################### 54 | 55 | # If the user only input in action argument 56 | if [ ! -n "$2" ]; then 57 | 58 | # Ask user what starting site number desired 59 | start=$(whiptail --inputbox "What number do you want to start from?" 8 58 --title "WordPress Installer" 3>&1 1>&2 2>&3) 60 | if [ ! -n "$start" ]; then 61 | echo "User cancelled" 62 | exit 1 63 | fi 64 | else 65 | # Else we have the number from the command line 66 | start=$2 67 | fi 68 | 69 | 70 | # If the user only input in action argument and the starting site number 71 | if [ ! -n "$3" ]; then 72 | 73 | # Ask user the ending number 74 | end=$(whiptail --inputbox "What number do you want to end to?" 8 58 --title "WordPress Installer" 3>&1 1>&2 2>&3) 75 | if [ ! -n "$end" ]; then 76 | echo "User cancelled" 77 | exit 1 78 | fi 79 | else 80 | # Else we have the number from the command line 81 | end=$3 82 | fi 83 | 84 | # Sanity check are we going forwards in numbers? 85 | if [ "$start" -gt "$end" ]; then 86 | whiptail --title "WordPress Installer" --msgbox "I can't count backward, please set an ending number greater than the starting one" 8 70 87 | exit 1 88 | fi 89 | 90 | #################################################################################### 91 | 92 | # Confirm what the user wants is correct 93 | whiptail --yesno "Are you sure you want to $action wordpress in folders $start to $end ?" 10 70 --title "WordPress Installer" 94 | exitstatus=$? 95 | 96 | if [ $exitstatus != 0 ]; then 97 | echo "User cancelled." 98 | fi 99 | 100 | #################################################################################### 101 | 102 | range=$((end-start+1)) 103 | cnt=0 104 | 105 | # If we're going to remove sites 106 | if [ "$action" == "uninstall" ]; then 107 | { 108 | # Loop through the sequence number and ... 109 | for i in $(seq $start $end) 110 | do 111 | 112 | # Do mysql stuff to drop the db, revoke all and remove the user 113 | mysql -h "localhost" "--user=root" "--password=$mysqlrootpassword" -e "DROP DATABASE IF EXISTS wp_$i;" 114 | mysql -h "localhost" "--user=root" "--password=$mysqlrootpassword" -e "REVOKE ALL ON wp_$i.* FROM wp_$i@localhost;" 115 | mysql -h "localhost" "--user=root" "--password=$mysqlrootpassword" -e "DROP USER wp_$i@localhost;" 116 | 117 | # Create the specific install path for site 118 | INSTALL_PATH="$BASEPATH/wp$i" 119 | 120 | # If the site exists 121 | if [[ -d "$INSTALL_PATH" ]]; then 122 | 123 | # Destroy the file system folder of the site 124 | rm -dfr $INSTALL_PATH 125 | fi 126 | 127 | # Calc percentage done and send back to whiptail 128 | percent=$(( 100*(++cnt)/range )) 129 | echo $percent 130 | 131 | done 132 | }|whiptail --title "WordPress Uninstall folders $start to $end" --gauge "Please wait" 5 50 0 133 | exit 134 | else 135 | # Loop throuh all proposed sites and make sure we don't overwrite any folder 136 | for i in $(seq $start $end) 137 | do 138 | # Create the specific install path for site 139 | INSTALL_PATH="$BASEPATH/wp$i" 140 | 141 | # If the site exists 142 | if [[ -d "$INSTALL_PATH" ]]; then 143 | 144 | # Alert and stop now! 145 | whiptail --title "WordPress Installer" --msgbox "Directory $INSTALL_PATH already exist. Aborting" 8 70 146 | exit 1 147 | fi 148 | done 149 | 150 | rm -rf /root/wp-pass.log 151 | PASS="/root/wp-pass.log" 152 | 153 | echo "Dawson College WordPress Site Information" >> $PASS 154 | echo "-----------------------------------------" >> $PASS 155 | echo "" >> $PASS 156 | echo "" >> $PASS 157 | echo "" >> $PASS 158 | 159 | rm -rf /root/wp-install.log 160 | 161 | LOG="/root/wp-install.log" 162 | { 163 | for i in $(seq $start $end) 164 | do 165 | # Foreach new site create a random secure password 166 | wp_pass=`head -c 500 /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1` 167 | 168 | # Mysql stuff, drop db if exists, create database, grant privileges and flush privileges 169 | mysql -h "localhost" "--user=root" "--password=$mysqlrootpassword" -e "DROP DATABASE IF EXISTS wp_$i;" 170 | mysql -h "localhost" "--user=root" "--password=$mysqlrootpassword" -e "CREATE DATABASE IF NOT EXISTS wp_$i;" 171 | mysql -h "localhost" "--user=root" "--password=$mysqlrootpassword" -e "GRANT ALL ON wp_$i.* TO wp_$i@localhost IDENTIFIED BY '$wp_pass';" 172 | mysql -h "localhost" "--user=root" "--password=$mysqlrootpassword" -e "FLUSH PRIVILEGES;" 173 | 174 | #################################################################################### 175 | 176 | # Set the install path variable 177 | INSTALL_PATH="$BASEPATH/wp$i" 178 | if [[ -d "$INSTALL_PATH" ]]; then 179 | 180 | # Delete the install path if it exist. It shouldn't but you never know 181 | rm -dfr $INSTALL_PATH 182 | fi 183 | 184 | # Create the directory of the install path 185 | mkdir $INSTALL_PATH 186 | 187 | # Go into the install path 188 | cd $INSTALL_PATH 189 | 190 | #################################################################################### 191 | 192 | # download the WordPress core files 193 | wp core download --quiet 194 | 195 | # create the wp-config file with our standard setup 196 | wp core config --dbname=wp_$i --dbuser=wp_$i --dbpass=$wp_pass --quiet 197 | 198 | # parse the current directory name 199 | currentdirectory=${PWD##*/} 200 | 201 | # generate random 8 character password 202 | user_password=`head -c 500 /dev/urandom | tr -dc '0-9' | fold -w 8 | head -n 1` 203 | 204 | # create database, and install WordPress 205 | wp core install \ 206 | --url="http://wpcourse.dawsoncollege.qc.ca/$currentdirectory" \ 207 | --title="Student $i WordPress Website" \ 208 | --admin_user="student$i" \ 209 | --admin_password="Daw$user_password" \ 210 | --admin_email="student$i@dawsoncollege.qc.ca" --quiet 211 | 212 | #################################################################################### 213 | 214 | # Dump out information to a text file for the teacher 215 | echo "student$i Daw$user_password _________________________________" >> $PASS 216 | echo "" >> $PASS 217 | echo "" >> $PASS 218 | echo "" >> $PASS 219 | echo "" >> $PASS 220 | 221 | 222 | # Dump out information for the specific student 223 | echo "Dawson College WordPress Site Information" >> $LOG 224 | echo "-----------------------------------------" >> $LOG 225 | echo "" >> $LOG 226 | 227 | echo "You have been given a WordPress site." >> $LOG 228 | echo "" >> $LOG 229 | echo "To access the public website please use the following:" >> $LOG 230 | echo "" >> $LOG 231 | echo "http://wpcourse.dawsoncollege.qc.ca/$currentdirectory" >> $LOG 232 | echo "" >> $LOG 233 | echo "To access the admin login of the website please use the following:" >> $LOG 234 | echo "" >> $LOG 235 | echo "https://wpcourse.dawsoncollege.qc.ca/$currentdirectory/wp-admin" >> $LOG 236 | echo "" >> $LOG 237 | echo "Please use this username and password to login." >> $LOG 238 | echo "" >> $LOG 239 | echo "" >> $LOG 240 | echo "student$i" >> $LOG 241 | echo "Daw$user_password" >> $LOG 242 | echo "" >> $LOG 243 | echo "" >> $LOG 244 | echo "This account is not tied to any other services at Dawson College." >> $LOG 245 | echo "" >> $LOG 246 | echo "When working outside the college, you will be required to enter your" >> $LOG 247 | echo "username and password before getting to the public side of your site." >> $LOG 248 | echo "This is done to ensure the security of your site." >> $LOG 249 | echo "" >> $LOG 250 | echo "The following plugins listed here will cause your site to crash on our" >> $LOG 251 | echo "server. DO NOT install them. When using web hosting outside Dawson " >> $LOG 252 | echo "College, you may install them but be aware that they make changes to a" >> $LOG 253 | echo "file called .htaccess which might have unintended side effects." >> $LOG 254 | echo "Information about .htaccess can be found here:" >> $LOG 255 | echo "https://codex.wordpress.org/htaccess" >> $LOG 256 | echo "" >> $LOG 257 | echo "WP Super Cache" >> $LOG 258 | echo "WP File Cache" >> $LOG 259 | echo "WP Rocket" >> $LOG 260 | echo "W3 Total Cache" >> $LOG 261 | echo "VersionPress" >> $LOG 262 | echo "BulletProof Security" >> $LOG 263 | echo "iThemes Security (formerly Better WP Security)" >> $LOG 264 | echo "" >> $LOG 265 | echo "For technical support with your WordPress site, please contact your teacher." >> $LOG 266 | 267 | for line in {1..15}; do echo "" >> $LOG; done 268 | 269 | #################################################################################### 270 | 271 | # discourage search engines 272 | wp option update blog_public 0 --quiet 273 | 274 | # delete sample page, and create homepage 275 | wp post delete $(wp post list --post_type=page --posts_per_page=1 --post_status=publish --pagename="sample-page" --field=ID --format=ids) --quiet 276 | wp post create --post_type=page --post_title=Home --post_status=publish --post_author=1 --quiet 277 | 278 | # set homepage as front page 279 | wp option update show_on_front 'page' --quiet 280 | 281 | # set pretty urls 282 | wp rewrite structure '/%postname%/' --hard --quiet 283 | wp rewrite flush --hard --quiet --quiet 284 | 285 | # delete akismet and hello dolly 286 | wp plugin delete akismet --quiet 287 | wp plugin delete hello --quiet 288 | 289 | # create a navigation bar 290 | wp menu create "Main Navigation" --quiet 291 | 292 | # disable file edit in wordpress config 293 | sed -i "s/table_prefix = 'wp_';/table_prefix = 'wp_';\ndefine( 'DISALLOW_FILE_EDIT', true );/" $INSTALL_PATH/wp-config.php 294 | 295 | #################################################################################### 296 | 297 | # create .htaccess file 298 | FN="$INSTALL_PATH/.htaccess" 299 | 300 | echo "# BEGIN WordPress" > $FN 301 | echo "" >> $FN 302 | echo "RewriteEngine On" >> $FN 303 | echo "RewriteBase /wp$i/" >> $FN 304 | echo "RewriteRule ^index\.php$ - [L]" >> $FN 305 | echo "RewriteCond %{REQUEST_FILENAME} !-f" >> $FN 306 | echo "RewriteCond %{REQUEST_FILENAME} !-d" >> $FN 307 | echo "RewriteRule . /wp$i/index.php [L]" >> $FN 308 | echo "" >> $FN 309 | echo "# END WordPress" >> $FN 310 | echo "# BEGIN password protect based on IP" >> $FN 311 | echo "" >> $FN 312 | echo "AuthType Basic" >> $FN 313 | echo 'AuthName "External Access"' >> $FN 314 | echo "AuthUserFile $INSTALL_PATH/.htpasswd" >> $FN 315 | echo "Require valid-user" >> $FN 316 | echo "Order Deny,Allow" >> $FN 317 | echo "Deny from all" >> $FN 318 | echo "Allow from 198.168.48.0/255.255.255.0" >> $FN 319 | echo "Allow from 10.0.0.0/255.0.0.0" >> $FN 320 | echo "Satisfy Any" >> $FN 321 | echo "" >> $FN 322 | echo "# END password protect based on IP" >> $FN 323 | 324 | # create the .htpasswd file 325 | htpasswd -b -c $INSTALL_PATH/.htpasswd "student$i" Daw$user_password > /dev/null 2>&1 326 | 327 | # change ownership of the folder to apache 328 | chown -R apache.apache $INSTALL_PATH 329 | 330 | # changing file permissions 331 | find $INSTALL_PATH -type f -exec chmod 664 {} \; 332 | find $INSTALL_PATH -type d -exec chmod 775 {} \; 333 | 334 | # Calculate and send percent done to whiptail 335 | percent=$(( 100*(++cnt)/range )) 336 | echo $percent 337 | done 338 | }|whiptail --title "WordPress Install folders $start to $end" --gauge "Please wait" 5 50 0 339 | fi 340 | 341 | #################################################################################### 342 | 343 | # Convert text file of info for teacher to pdf 344 | enscript -B -f Courier12 --margins=26:18:18:18 -p wp-pass.ps wp-pass.log 345 | ps2pdf wp-pass.ps wp-pass.pdf 346 | 347 | # Deleteing intermediate files 348 | rm -rf wp-pass.log 349 | rm -rf wp-pass.ps 350 | 351 | # Send to my home directory 352 | mv wp-pass.pdf /home/jperlman 353 | chown jperlman:jperlman wp-pass.pdf 354 | 355 | #################################################################################### 356 | 357 | # Convert many student one page documents into one pdf 358 | enscript -B -f Courier12 --margins=26:18:18:18 -p wp-install.ps wp-install.log 359 | ps2pdf wp-install.ps wp-install.pdf 360 | 361 | # Deleteing intermediate files 362 | rm wp-install.ps 363 | rm wp-install.log 364 | 365 | # Send to my home directory 366 | mv wp-install.pdf /home/jperlman 367 | chown jperlman:jperlman wp-install.pdf 368 | 369 | #################################################################################### 370 | 371 | exit 372 | --------------------------------------------------------------------------------