├── pushinitialsitetotrash ├── pushprojecttotrash ├── README.md ├── pullpush-example.conf ├── pushdeploytolive ├── pulllivecopyfromlive ├── vhost_drupal.template ├── pullpush_functions ├── pushdeploytodatadump ├── pulldevfromlivecopy ├── pulldevfromdatadump ├── pulldeployfrombeta ├── pullinitialsitefromsource ├── pulllivecopyfromdatadump ├── pushdevtobeta ├── pushinitialsitetobeta ├── pulldevfrombeta └── pushlivecopydataintodeploy /pushinitialsitetotrash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "This script is not ready yet!" 4 | exit 5 | -------------------------------------------------------------------------------- /pushprojecttotrash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "This script is not ready yet!" 4 | 5 | exit 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | pullpush 2 | ======== 3 | 4 | Configuration and scripts to manage web applications on a development server. For further information please refer to https://github.com/SSVC/pullpush/wiki 5 | -------------------------------------------------------------------------------- /pullpush-example.conf: -------------------------------------------------------------------------------- 1 | # Configuration file for Pullpush 2 | 3 | SERVER_FQDN= 4 | SERVER_TYPE= 5 | SERVER_ADMIN_EMAIL= 6 | -------------------------------------------------------------------------------- /pushdeploytolive: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "This script will use the live server FTP/SSH login to push the deploy site all the way to the live server. After uploading, the live server needs to load the DB dump and make the site available." 4 | -------------------------------------------------------------------------------- /pulllivecopyfromlive: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "This script will pull down the site files from the live server and create a new copy of the livecopy site." 4 | echo "Before it is run the live site admins need to put the live site into read-only mode and create a database dump file." 5 | -------------------------------------------------------------------------------- /vhost_drupal.template: -------------------------------------------------------------------------------- 1 | 2 | 3 | ServerName vhostname.serverfqdn 4 | ServerAlias *.vhostname.serverfqdn 5 | ServerAdmin serveradminemail 6 | 7 | DocumentRoot documentroot 8 | 9 | 10 | AllowOverride all 11 | Order allow,deny 12 | Allow from all 13 | 14 | 15 | # Possible values include: debug, info, notice, warn, error, crit, 16 | # alert, emerg. 17 | LogLevel warn 18 | 19 | # Make all scripts run as the specified user if Apache ITK is being used. 20 | 21 | AssignUserId username username 22 | 23 | 24 | # Limit PHP scripts to accessing only certain direectories. 25 | # NB - This can be worked around with shell_exec etc but is a level of protection. 26 | php_admin_value open_basedir documentroot/:/usr/share/php/:/tmp 27 | 28 | 29 | -------------------------------------------------------------------------------- /pullpush_functions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=================================================================================== 3 | # 4 | # FILE: pullpush_functions 5 | # 6 | # DESCRIPTION: This file will contain functions used by the Pullpush scripts. 7 | # 8 | # AUTHOR: Kevin Bailey, kbailey@freewayprojects.com 9 | # COMPANY: Freeway Projects Limited 10 | #=================================================================================== 11 | 12 | # Check the Pullpush configuration file exists. 13 | __load_configuration_file () { 14 | 15 | if [ -e /etc/pullpush/pullpush.conf ] 16 | then 17 | source /etc/pullpush/pullpush.conf 18 | return 0 19 | else 20 | echo "ERROR - Pullpush configuration file not found." 21 | return 1 22 | fi 23 | } 24 | 25 | # Create a standard MySQL database and a user account which is set with all privileges 26 | # to the database. 27 | __create_mysql_database_and_user_account () { 28 | 29 | DATABASE_NAME=${1} 30 | DATABASE_USER=${2} 31 | DATABASE_PASSWORD=${3} 32 | 33 | case "${PROJECT_TYPE}" in 34 | 35 | drupal6|drupal7) 36 | 37 | mysqladmin create ${DATABASE_NAME} 38 | mysql --execute="GRANT ALL ON ${DATABASE_NAME}.* TO '${DATABASE_USER}'@'localhost' IDENTIFIED BY '${DATABASE_PASSWORD}';" ${DATABASE_NAME} 39 | ;; 40 | 41 | *) 42 | echo "Error - Invalid project type." 43 | exit -1 44 | esac 45 | } 46 | 47 | # Set up an Apache vhost with configuration from template files. 48 | __set_up_vhost () { 49 | 50 | VHOST_NAME=${1} 51 | DOC_ROOT=${2} 52 | ASSIGN_USER_ID=${3} 53 | 54 | case "${SERVER_TYPE}" in 55 | 56 | debian|ubuntu) 57 | 58 | # First we need to copy the relevant vhost template file. 59 | case ${PROJECT_TYPE} in 60 | drupal6|drupal7) 61 | sudo cp /usr/local/share/pullpush/vhost_drupal.template /etc/apache2/sites-available/${VHOST_NAME} 62 | ;; 63 | *) 64 | echo "Error - Invalid project type." 65 | exit -1 66 | esac 67 | 68 | # Edit the configuration file. There may be a better way to do this. 69 | sudo sed -i "s|documentroot|${DOC_ROOT}|g" /etc/apache2/sites-available/${VHOST_NAME} 70 | sudo sed -i "s/username/${ASSIGN_USER_ID}/g" /etc/apache2/sites-available/${VHOST_NAME} 71 | sudo sed -i "s/vhostname/${VHOST_NAME}/g" /etc/apache2/sites-available/${VHOST_NAME} 72 | sudo sed -i "s/serverfqdn/${SERVER_FQDN}/g" /etc/apache2/sites-available/${VHOST_NAME} 73 | sudo sed -i "s/serveradminemail/${SERVER_ADMIN_EMAIL}/g" /etc/apache2/sites-available/${VHOST_NAME} 74 | 75 | sudo a2ensite ${VHOST_NAME} 76 | sudo apache2ctl restart 77 | ;; 78 | 79 | *) 80 | echo "Error - Invalid server type." 81 | exit -1 82 | esac 83 | 84 | } 85 | 86 | __check_beta_files_into_svn () { 87 | 88 | # The only file changes this should pick up are the new data files which are in sites/default/files. First we are 89 | # going to output the changes to files/ and / and make sure they match. If they don't match then there are non-data 90 | # files/directories which have been changed in the Drupal part of the site which needs to be looked into 91 | 92 | # NB - The output from the status commands needs to be sorted as lines are not always output in the same order. 93 | echo "Checking the status of the files..." 94 | beta_svn_status_of_whole_site=$(svn -u status /home/beta/projects/${PROJECT_NAME}/web | sort) 95 | beta_svn_status_of_files_directory=$(svn -u status /home/beta/projects/${PROJECT_NAME}/web/sites/default/files | sort) 96 | 97 | echo "beta_svn_status_of_whole_site: ${beta_svn_status_of_whole_site}" 98 | echo "beta_svn_status_of_files_directory: ${beta_svn_status_of_files_directory}" 99 | 100 | if [ "$beta_svn_status_of_whole_site" != "$beta_svn_status_of_files_directory" ] 101 | then 102 | echo "The beta site files has files which have been modified which are not in the files/ directory - this needs to be looked into as only data files should be updated on the beta site." 103 | exit 1 104 | fi 105 | 106 | # Now checking that the revision number of beta's local svn copy matches the repository. If they don't match then the repository must have been 107 | # updated by another process. We would need to see where that update come from and what (if any) database changes were made. 108 | # file changes to SVN. 109 | beta_local_revision=$(svn info /home/beta/projects/${PROJECT_NAME}/web | grep '^Revision:' | sed s/^Revision:[[:space:]]*// ) 110 | 111 | # Trying to get revision without authentication details. 112 | ####remote_revision=$(svn --username kevinb --password xxxxxxxx info http://svn.chalfont.ssvc.com/Technology/Websites/radio-v2 | grep '^Revision:' | awk '{print $2}') 113 | remote_revision=$(svn info http://localhost/svn/${PROJECT_NAME} | grep '^Revision:' | awk '{print $2}') 114 | 115 | echo "beta_local_revision: ${beta_local_revision}" 116 | echo "remote_revision: ${remote_revision}" 117 | 118 | if [ "$beta_local_revision" != "$remote_revision" ] 119 | then 120 | echo "The revision number of the local copy does not match the remote respository version - this needs to be looked into - someone/some process has updated the repository which needs to be checked - also, check for any database changes?" 121 | exit 1 122 | fi 123 | 124 | # We've finished the checks - now lets commit the changes to beta files/ to the repository. We will first svn add/delete 125 | # files as necessary. 126 | 127 | # NB - We could run the 'svn status' on just the files directory - but this should not be necessary as the previous checks are supposed to 128 | # check that only file/dirs in files/ have changed. We'll leave the 'svn status' to pick up all changes because at least the site will 129 | # be an exact copy of beta and the output on the command line will show all file changes. 130 | 131 | echo "Adding all new files to svn control list..." 132 | ###sudo -u beta -i "svn status /home/beta/projects/${PROJECT_NAME}/web | grep \"^?\" | sed s/^?// | sed s/[[:space:]]*// | xargs -i svn add \"{}\"" 133 | sudo -u beta -i sh -c "svn status /home/beta/projects/${PROJECT_NAME}/web | grep \"^?\" | sed s/^?// | sed s/[[:space:]]*// | xargs -i svn add \"{}\"" 134 | 135 | echo "If files have been deleted then SVN needs to mark them for deletion..." 136 | ###sudo -u beta -i "svn status /home/beta/projects/${PROJECT_NAME}/web | grep \"^\!\" | sed s/^\!// | sed s/[[:space:]]*// | xargs -i svn delete \"{}\"" 137 | sudo -u beta -i sh -c "svn status /home/beta/projects/${PROJECT_NAME}/web | grep \"^\!\" | sed s/^\!// | sed s/[[:space:]]*// | xargs -i svn delete \"{}\"" 138 | 139 | echo "Committing and deleting the files which have changed in the beta files/ directory..." 140 | ### sudo -u beta -i "svn commit -m \"${DATE_TIME} - Committing added/changed/deleted data files from beta into repository.\" /home/beta/projects/${PROJECT_NAME}/web " 141 | sudo -u beta -i sh -c "svn commit -m \"${DATE_TIME} - Committing added/changed/deleted data files from beta into repository.\" /home/beta/projects/${PROJECT_NAME}/web " 142 | 143 | # Now we will run an update - the reason for this is so the revision number of beta local and 144 | # the repository will match and can therefore be tested before running the next commit from beta. 145 | # I.e. After running this update the revision numbers match. When running the next test before 146 | # committing the beta files/ changes we can check the revision numbers and if they don't match then 147 | # the repository must have been updated by another process. This would then need to be investigated. 148 | 149 | # With SVN the local revision number is not updated after a commit - this is need by Pullpush as 150 | # checks are carried out later. 151 | echo "SVN update the local beta copy to get the revision number to match the repository revision..." 152 | ##ssh beta@localhost "svn update ${BETA_DOCUMENT_ROOT}" 153 | ###sudo -u beta -i "svn update /home/beta/projects/${PROJECT_NAME}/web" 154 | sudo -u beta -i sh -c "svn update /home/beta/projects/${PROJECT_NAME}/web" 155 | 156 | # Here we will get the latest revision number and save a copy of the database dump file with that 157 | # revision number so it can be matched up to the code in the repository. 158 | echo "Creating a database copy with the matching revision number - this will NOT be checked into the code repository but saved under the beta user account..." 159 | 160 | mkdir -p /home/${USER}/backups/beta_sites 161 | mysqldump betapr${PROJECT_NAME} > /home/${USER}/backups/beta_sites/${PROJECT_NAME}_for_svn.sql 162 | 163 | new_beta_revision=$(svn info /home/beta/projects/${PROJECT_NAME}/web | grep '^Revision:' | sed s/^Revision:[[:space:]]*// ) 164 | ###sudo -u beta -i "mkdir -p /home/beta/backups" 165 | sudo -u beta -i sh -c "mkdir -p /home/beta/backups" 166 | ###sudo -u beta -i "cp /home/${USER}/backups/beta_sites/${PROJECT_NAME}_for_svn.sql /home/beta/backups/${PROJECT_NAME}_r${new_beta_revision}.sql" 167 | sudo -u beta -i sh -c "cp /home/${USER}/backups/beta_sites/${PROJECT_NAME}_for_svn.sql /home/beta/backups/${PROJECT_NAME}_r${new_beta_revision}.sql" 168 | } 169 | -------------------------------------------------------------------------------- /pushdeploytodatadump: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=================================================================================== 3 | # 4 | # FILE: pushdeploytodatadump 5 | # 6 | # USAGE: pushdeploytodatadump -p [project type] 7 | # 8 | # DESCRIPTION: This will push a copy of the deploy site into data dump files. 9 | # 10 | # OPTIONS: see function ’usage’ below 11 | # NOTES: --- 12 | # AUTHOR: Kevin Bailey, kbailey@freewayprojects.com 13 | # COMPANY: Freeway Projects Limited 14 | #=================================================================================== 15 | 16 | # Make sure only one Pullpush script is running at any one time. 17 | touch /var/lock/pullpush 18 | chmod --quiet 666 /var/lock/pullpush 19 | exec 9>/var/lock/pullpush 20 | if ! flock -n 9 ; then 21 | echo "Another Pullpush script is currently running - try again later."; 22 | exit 1 23 | fi 24 | 25 | # ------------------------------------------------------------------------------------------------- 26 | # Set up global variables. 27 | # 28 | # We are going to explicitly set the script name variable. Obviously the script name is available 29 | # as $0 - but this is not consistent and may or may not contain the path. Also, this means we can 30 | # use the bash debugger without needing to handle the fact that $0 would contain something like 31 | # 'bashdb'. 32 | # ------------------------------------------------------------------------------------------------- 33 | SCRIPT_NAME=pushdeploytodatadump 34 | DATE_TIME=$(date +%Y%m%d-%H%M%S) 35 | 36 | # ------------------------------------------------------------------------------------------------- 37 | # Set up the user to be able to run sudo commands - this will be revoked at the end of the script. 38 | # ------------------------------------------------------------------------------------------------- 39 | sudo -v 40 | 41 | # ------------------------------------------------------------------------------------------------- 42 | # Log all output from the script. 43 | # 44 | # As we are going to be carrying out multiple steps and it is important we can see all the output 45 | # to be able to diagnose problems. 46 | # ------------------------------------------------------------------------------------------------- 47 | 48 | # Create a place for the log files. 49 | sudo mkdir -p /var/log/pullpush 50 | sudo chmod 777 /var/log/pullpush 51 | 52 | # Create a pipe... 53 | tmppipe=$(mktemp -u) 54 | mkfifo ${tmppipe} 55 | 56 | # ...then start a tee process which takes as its input the pipe - and output to the logfile (and 57 | # standard output) and then push the tee process into the background (subshell). 58 | tee < ${tmppipe} /var/log/pullpush/${DATE_TIME}_${USER}_${SCRIPT_NAME}.log & 59 | 60 | # Redirect both standard output and standard error to the pipe just created - these outputs 61 | # will then be directed via the pipe to standard output (the current shell) and the log file. 62 | exec &> ${tmppipe} 63 | 64 | # This sets up the pipe to be removed - it will only be fully dropped when no process is using it. 65 | rm ${tmppipe} 66 | 67 | # ------------------------------------------------------------------------------------------------- 68 | # Import Pullpush functions. 69 | # ------------------------------------------------------------------------------------------------- 70 | source /usr/local/share/pullpush/pullpush_functions 71 | 72 | # ------------------------------------------------------------------------------------------------- 73 | # Local functions 74 | # 75 | # Here we will define all the functions used by this script. 76 | # ------------------------------------------------------------------------------------------------- 77 | 78 | # Output a usage message - used when the parameters input are not correct. 79 | usage () { 80 | echo "Usage: $SCRIPT_NAME -p [project name]" 81 | } 82 | 83 | # ------------------------------------------------------------------------------------------------- 84 | # Testing parameters 85 | # ------------------------------------------------------------------------------------------------- 86 | while getopts ":p:" opt; do 87 | case $opt in 88 | p) 89 | PROJECT_NAME=$OPTARG 90 | ;; 91 | \?) 92 | echo "Invalid option: -$OPTARG" >&2 93 | usage 94 | exit 1 95 | ;; 96 | :) 97 | echo "Option -$OPTARG requires an argument." >&2 98 | usage 99 | exit 1 100 | ;; 101 | esac 102 | done 103 | 104 | # Check the parameter has had a value assigned. 105 | if [ -z $PROJECT_NAME ] 106 | then 107 | echo "The project name needs to be set." 108 | usage 109 | exit 1 110 | fi 111 | 112 | # Check the project exists. 113 | if [ ! -e /home/beta/projects/${PROJECT_NAME}/web ] 114 | then 115 | echo "The project does not appear to exist." 116 | usage 117 | exit 1 118 | fi 119 | 120 | # Load the project settings file or display an error if it does not exist. 121 | if [ -e /etc/pullpush/projects/${PROJECT_NAME}.conf ] 122 | then 123 | source /etc/pullpush/projects/${PROJECT_NAME}.conf 124 | else 125 | echo "ERROR - The project settings file /etc/pullpush/projects/${PROJECT_NAME}.conf not found." 126 | exit 1 127 | fi 128 | 129 | # Load the configuration file and check it was loaded OK. 130 | __load_configuration_file 131 | 132 | if [ $? -ne 0 ] 133 | then 134 | echo "Configuration file was not loaded." 135 | fi 136 | 137 | echo "All tests completed OK." 138 | echo "Project name: ${PROJECT_NAME}" 139 | 140 | # ------------------------------------------------------------------------------------------------- 141 | # The plan. 142 | # 143 | # Put site into maintenance mode. 144 | # Clear caches on deploy site. 145 | # Dump out DB. 146 | # ------------------------------------------------------------------------------------------------- 147 | 148 | # ------------------------------------------------------------------------------------------------- 149 | echo 150 | echo `date` 151 | echo "Putting the site into maintenance mode..." 152 | # ------------------------------------------------------------------------------------------------- 153 | case "${PROJECT_TYPE}" in 154 | 155 | drupal7) 156 | 157 | echo "Setting the deploy site to maintenance mode..." 158 | drush -r /home/beta/projects/${PROJECT_NAME}/web vset maintenance_mode 1 --yes 159 | ;; 160 | 161 | drupal6) 162 | 163 | echo "Setting the deploy site to maintenance mode..." 164 | drush -r /home/beta/projects/${PROJECT_NAME}/web vset site_offline 1 --yes 165 | ;; 166 | 167 | *) 168 | echo "Error - Invalid project type." 169 | exit 1 170 | esac 171 | 172 | # ------------------------------------------------------------------------------------------------- 173 | echo 174 | echo `date` 175 | echo "Clearing out the caches on the site to trim the database and files/ before making the data dump..." 176 | # ------------------------------------------------------------------------------------------------- 177 | 178 | # Bear in mind here that we may need to chmod the /files directory to 777 if we are not using Apache-ITK. 179 | # Clear out the caches on the deploy site. 180 | case "${PROJECT_TYPE}" in 181 | 182 | drupal7|drupal6) 183 | 184 | echo "Setting the deploy site to maintenance mode..." 185 | sudo -u deploy -i sh -c "drush --root=/home/deploy/projects/${PROJECT_NAME}/web cache-clear all" 186 | ;; 187 | 188 | *) 189 | echo "Error - Invalid project type." 190 | exit 1 191 | esac 192 | 193 | # ------------------------------------------------------------------------------------------------- 194 | echo 195 | echo `date` 196 | echo "Dumping out the database to a file..." 197 | # ------------------------------------------------------------------------------------------------- 198 | sudo -u deploy -i sh -c "mkdir -p /home/deploy/projects/${PROJECT_NAME}/deploy_dumps" 199 | ###sudo -u deploy -i sh -c "mkdir -p /home/deploy/projects/${PROJECT_NAME}/db" 200 | sudo -u deploy -i sh -c "mysqldump deploypr${PROJECT_NAME} > /home/deploy/projects/${PROJECT_NAME}/deploy_dumps/database_dump.sql" 201 | 202 | # ------------------------------------------------------------------------------------------------- 203 | echo 204 | echo `date` 205 | echo "Creating a tar file of all the files in the site..." 206 | # ------------------------------------------------------------------------------------------------- 207 | 208 | # The -C switch will 'cd' into the directory - this means we can create an archive which only 209 | # contains a single directory and therefore there will be a strip-components value of 1 needed. 210 | sudo -u deploy -i sh -c "mkdir -p /home/deploy/projects/${PROJECT_NAME}/deploy_dumps" 211 | sudo -u deploy -i sh -c "rm /home/deploy/projects/${PROJECT_NAME}/deploy_dumps/site_files.tar" 212 | sudo -u deploy -i sh -c "rm /home/deploy/projects/${PROJECT_NAME}/deploy_dumps/site_files.tar.gz" 213 | sudo -u deploy -i sh -c "tar --create --file=/home/deploy/projects/${PROJECT_NAME}/deploy_dumps/site_files.tar -C /home/deploy/projects/${PROJECT_NAME}/ web" 214 | sudo -u deploy -i sh -c "gzip -f /home/deploy/projects/${PROJECT_NAME}/deploy_dumps/site_files.tar" 215 | 216 | # ------------------------------------------------------------------------------------------------- 217 | echo 218 | echo `date` 219 | echo "Finished..." 220 | # ------------------------------------------------------------------------------------------------- 221 | 222 | exit 0 223 | -------------------------------------------------------------------------------- /pulldevfromlivecopy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=================================================================================== 3 | # 4 | # FILE: pulldevfromlivecopy 5 | # 6 | # USAGE: pulldevfromlivecopy -p [project type] 7 | # 8 | # DESCRIPTION: This will overwrite a dev site with a copy from a data dump. 9 | # 10 | # OPTIONS: see function ’usage’ below 11 | # NOTES: --- 12 | # AUTHOR: Kevin Bailey, kbailey@freewayprojects.com 13 | # COMPANY: Freeway Projects Limited 14 | #=================================================================================== 15 | 16 | # Make sure only one Pullpush script is running at any one time. 17 | touch /var/lock/pullpush 18 | chmod --quiet 666 /var/lock/pullpush 19 | exec 9>/var/lock/pullpush 20 | if ! flock -n 9 ; then 21 | echo "Another Pullpush script is currently running - try again later."; 22 | exit 1 23 | fi 24 | 25 | # ------------------------------------------------------------------------------------------------- 26 | # Set up global variables. 27 | # 28 | # We are going to explicitly set the script name variable. Obviously the script name is available 29 | # as $0 - but this is not consistent and may or may not contain the path. Also, this means we can 30 | # use the bash debugger without needing to handle the fact that $0 would contain something like 31 | # 'bashdb'. 32 | # ------------------------------------------------------------------------------------------------- 33 | SCRIPT_NAME=pulldevfromlivecopy 34 | DATE_TIME=$(date +%Y%m%d-%H%M%S) 35 | 36 | # ------------------------------------------------------------------------------------------------- 37 | # Set up the user to be able to run sudo commands - this will be revoked at the end of the script. 38 | # ------------------------------------------------------------------------------------------------- 39 | sudo -v 40 | 41 | # ------------------------------------------------------------------------------------------------- 42 | # Log all output from the script. 43 | # 44 | # As we are going to be carrying out multiple steps and it is important we can see all the output 45 | # to be able to diagnose problems. 46 | # ------------------------------------------------------------------------------------------------- 47 | 48 | # Create a place for the log files. 49 | sudo mkdir -p /var/log/pullpush 50 | sudo chmod 777 /var/log/pullpush 51 | 52 | # Create a pipe... 53 | tmppipe=$(mktemp -u) 54 | mkfifo ${tmppipe} 55 | 56 | # ...then start a tee process which takes as its input the pipe - and output to the logfile (and 57 | # standard output) and then push the tee process into the background (subshell). 58 | tee < ${tmppipe} /var/log/pullpush/${DATE_TIME}_${USER}_${SCRIPT_NAME}.log & 59 | 60 | # Redirect both standard output and standard error to the pipe just created - these outputs 61 | # will then be directed via the pipe to standard output (the current shell) and the log file. 62 | exec &> ${tmppipe} 63 | 64 | # This sets up the pipe to be removed - it will only be fully dropped when no process is using it. 65 | rm ${tmppipe} 66 | 67 | # ------------------------------------------------------------------------------------------------- 68 | # Import Pullpush functions. 69 | # ------------------------------------------------------------------------------------------------- 70 | source /usr/local/share/pullpush/pullpush_functions 71 | 72 | # ------------------------------------------------------------------------------------------------- 73 | # Local functions 74 | # 75 | # Here we will define all the functions used by this script. 76 | # ------------------------------------------------------------------------------------------------- 77 | 78 | # Output a usage message - used when the parameters input are not correct. 79 | usage () { 80 | echo "Usage: $SCRIPT_NAME -p [project name]" 81 | } 82 | 83 | # ------------------------------------------------------------------------------------------------- 84 | # Testing parameters 85 | # ------------------------------------------------------------------------------------------------- 86 | while getopts ":p:" opt; do 87 | case $opt in 88 | p) 89 | PROJECT_NAME=$OPTARG 90 | ;; 91 | \?) 92 | echo "Invalid option: -$OPTARG" >&2 93 | usage 94 | exit 1 95 | ;; 96 | :) 97 | echo "Option -$OPTARG requires an argument." >&2 98 | usage 99 | exit 1 100 | ;; 101 | esac 102 | done 103 | 104 | # Check the parameter has had a value assigned. 105 | if [ -z $PROJECT_NAME ] 106 | then 107 | echo "ERROR - The project name needs to be set." 108 | usage 109 | exit 1 110 | fi 111 | 112 | # Check dev copy of the project exists. 113 | if [ ! -e /home/${USER}/projects/${PROJECT_NAME}/web ] 114 | then 115 | echo "ERROR - You do not appear to have a dev copy of the project." 116 | usage 117 | exit 1 118 | fi 119 | 120 | # Check the livecopy site exists. 121 | if [ ! -e /home/livecopy/projects/${PROJECT_NAME}/web ] 122 | then 123 | echo "ERROR - The livecopy site does not exist." 124 | usage 125 | exit 1 126 | fi 127 | 128 | # Load the project settings file or display an error if it does not exist. 129 | if [ -e /etc/pullpush/projects/${PROJECT_NAME}.conf ] 130 | then 131 | source /etc/pullpush/projects/${PROJECT_NAME}.conf 132 | else 133 | echo "ERROR - The project settings file /etc/pullpush/projects/${PROJECT_NAME}.conf not found." 134 | exit 1 135 | fi 136 | 137 | # Load the configuration file and check it was loaded OK. 138 | __load_configuration_file 139 | 140 | if [ $? -ne 0 ] 141 | then 142 | echo "Configuration file was not loaded." 143 | fi 144 | 145 | echo "All tests completed OK." 146 | echo "Project name: ${PROJECT_NAME}" 147 | 148 | # ------------------------------------------------------------------------------------------------- 149 | # The plan. 150 | # 151 | # Before this script is run the livecopy site should be in place. 152 | # 153 | # Steps which are part of the plan. 154 | ## Check that the project exists and a dev copy exists. 155 | ## Check the livecopy site exists. 156 | ## Clear out the livecopy caches. 157 | ## Make a copy of the settings file. 158 | ## Copy the files from the livecopy site over the dev files using rsync. 159 | ## Copy back in the settings file. 160 | ## Dump out the livecopy database. 161 | ## Load the dev database from the livecopy db dump. 162 | # ------------------------------------------------------------------------------------------------- 163 | 164 | # Clear out livecopy caches. This should not be needed but is defensively put in here in case the 165 | # livecopy has been manually set up. 166 | #case "${PROJECT_TYPE}" in 167 | 168 | # drupal7|drupal6) 169 | # sudo -u livecopy -i sh -c "drush --root=/home/livecopy/projects/${PROJECT_NAME}/web cache-clear all" 170 | # ;; 171 | 172 | # *) 173 | # echo "Error - Invalid project type." 174 | # exit 1 175 | #esac 176 | 177 | # Make a copy of the settings file. 178 | case "${PROJECT_TYPE}" in 179 | 180 | drupal7|drupal6) 181 | 182 | chmod 777 /home/${USER}/settings.php.dev.livecopyload.${PROJECT_NAME} 183 | cp /home/${USER}/projects/${PROJECT_NAME}/web/sites/default/settings.php /home/${USER}/settings.php.dev.livecopyload.${PROJECT_NAME} 184 | ;; 185 | *) 186 | echo "Error - Invalid project type." 187 | exit -1 188 | esac 189 | 190 | 191 | ##rsync -vrlpgo --exclude=.svn/ --checksum --delete /home/${USER}/extracted_dump_files/${PROJECT_NAME}/ /home/${USER}/projects/${PROJECT_NAME} 192 | rsync -vrlpgo --exclude=.svn/ --checksum --delete /home/livecopy/projects/${PROJECT_NAME}/web/ /home/${USER}/projects/${PROJECT_NAME}/web 193 | 194 | # Copy the settings file back. 195 | case "${PROJECT_TYPE}" in 196 | 197 | drupal7|drupal6) 198 | 199 | sudo chmod 777 /home/${USER}/projects/${PROJECT_NAME}/web/sites/default 200 | rm /home/${USER}/projects/${PROJECT_NAME}/web/sites/default/settings.php 201 | 202 | cp /home/${USER}/settings.php.dev.livecopyload.${PROJECT_NAME} /home/${USER}/projects/${PROJECT_NAME}/web/sites/default/settings.php 203 | ;; 204 | *) 205 | echo "Error - Invalid project type." 206 | exit -1 207 | esac 208 | 209 | # ------------------------------------------------------------------------------------------------- 210 | echo 211 | echo `date` 212 | echo "Dumping out the database to a file..." 213 | # ------------------------------------------------------------------------------------------------- 214 | mkdir -p /home/${USER}/projects/${PROJECT_NAME}/livecopy_dumps 215 | mysqldump livecopypr${PROJECT_NAME} > /home/${USER}/projects/${PROJECT_NAME}/livecopy_dumps/database_dump.sql 216 | 217 | # ------------------------------------------------------------------------------------------------- 218 | echo 219 | echo `date` 220 | echo "Load database over top of existing database..." 221 | # ------------------------------------------------------------------------------------------------- 222 | mysqladmin --force drop ${USER}pr${PROJECT_NAME} 223 | mysqladmin create ${USER}pr${PROJECT_NAME} 224 | 225 | mysql ${USER}pr${PROJECT_NAME} < /home/${USER}/projects/${PROJECT_NAME}/livecopy_dumps/database_dump.sql 226 | 227 | # ------------------------------------------------------------------------------------------------- 228 | echo 229 | echo `date` 230 | echo "Finished..." 231 | # ------------------------------------------------------------------------------------------------- 232 | exit 0 233 | -------------------------------------------------------------------------------- /pulldevfromdatadump: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=================================================================================== 3 | # 4 | # FILE: pulldevfromdatadump 5 | # 6 | # USAGE: pulldevfromdatadump -p [project type] 7 | # 8 | # DESCRIPTION: This will overwrite a dev site with a copy from a data dump. 9 | # 10 | # OPTIONS: see function ’usage’ below 11 | # NOTES: --- 12 | # AUTHOR: Kevin Bailey, kbailey@freewayprojects.com 13 | # COMPANY: Freeway Projects Limited 14 | #=================================================================================== 15 | 16 | # Make sure only one Pullpush script is running at any one time. 17 | touch /var/lock/pullpush 18 | chmod --quiet 666 /var/lock/pullpush 19 | exec 9>/var/lock/pullpush 20 | if ! flock -n 9 ; then 21 | echo "Another Pullpush script is currently running - try again later."; 22 | exit 1 23 | fi 24 | 25 | # ------------------------------------------------------------------------------------------------- 26 | # Set up global variables. 27 | # 28 | # We are going to explicitly set the script name variable. Obviously the script name is available 29 | # as $0 - but this is not consistent and may or may not contain the path. Also, this means we can 30 | # use the bash debugger without needing to handle the fact that $0 would contain something like 31 | # 'bashdb'. 32 | # ------------------------------------------------------------------------------------------------- 33 | SCRIPT_NAME=pulldevfromdatadump 34 | DATE_TIME=$(date +%Y%m%d-%H%M%S) 35 | 36 | # ------------------------------------------------------------------------------------------------- 37 | # Set up the user to be able to run sudo commands - this will be revoked at the end of the script. 38 | # ------------------------------------------------------------------------------------------------- 39 | sudo -v 40 | 41 | # ------------------------------------------------------------------------------------------------- 42 | # Log all output from the script. 43 | # 44 | # As we are going to be carrying out multiple steps and it is important we can see all the output 45 | # to be able to diagnose problems. 46 | # ------------------------------------------------------------------------------------------------- 47 | 48 | # Create a place for the log files. 49 | sudo mkdir -p /var/log/pullpush 50 | sudo chmod 777 /var/log/pullpush 51 | 52 | # Create a pipe... 53 | tmppipe=$(mktemp -u) 54 | mkfifo ${tmppipe} 55 | 56 | # ...then start a tee process which takes as its input the pipe - and output to the logfile (and 57 | # standard output) and then push the tee process into the background (subshell). 58 | tee < ${tmppipe} /var/log/pullpush/${DATE_TIME}_${USER}_${SCRIPT_NAME}.log & 59 | 60 | # Redirect both standard output and standard error to the pipe just created - these outputs 61 | # will then be directed via the pipe to standard output (the current shell) and the log file. 62 | exec &> ${tmppipe} 63 | 64 | # This sets up the pipe to be removed - it will only be fully dropped when no process is using it. 65 | rm ${tmppipe} 66 | 67 | # ------------------------------------------------------------------------------------------------- 68 | # Import Pullpush functions. 69 | # ------------------------------------------------------------------------------------------------- 70 | source /usr/local/share/pullpush/pullpush_functions 71 | 72 | # ------------------------------------------------------------------------------------------------- 73 | # Local functions 74 | # 75 | # Here we will define all the functions used by this script. 76 | # ------------------------------------------------------------------------------------------------- 77 | 78 | # Output a usage message - used when the parameters input are not correct. 79 | usage () { 80 | echo "Usage: $SCRIPT_NAME -p [project name]" 81 | } 82 | 83 | # ------------------------------------------------------------------------------------------------- 84 | # Testing parameters 85 | # ------------------------------------------------------------------------------------------------- 86 | while getopts ":p:" opt; do 87 | case $opt in 88 | p) 89 | PROJECT_NAME=$OPTARG 90 | ;; 91 | \?) 92 | echo "Invalid option: -$OPTARG" >&2 93 | usage 94 | exit 1 95 | ;; 96 | :) 97 | echo "Option -$OPTARG requires an argument." >&2 98 | usage 99 | exit 1 100 | ;; 101 | esac 102 | done 103 | 104 | # Check the parameter has had a value assigned. 105 | if [ -z $PROJECT_NAME ] 106 | then 107 | echo "ERROR - The project name needs to be set." 108 | usage 109 | exit 1 110 | fi 111 | 112 | # Check dev copy of the project exists. 113 | if [ ! -e /home/${USER}/projects/${PROJECT_NAME}/web ] 114 | then 115 | echo "ERROR - You do not appear to have a dev copy of the project." 116 | usage 117 | exit 1 118 | fi 119 | 120 | # Check the data dump file exists. 121 | if [ ! -e /home/livecopy/projects/${PROJECT_NAME}/live_dumps/database_dump.sql ] 122 | then 123 | echo "ERROR - The data dump file is missing." 124 | echo "The script is expecting to be able to read the file /home/livecopy/projects/${PROJECT_NAME}/live_dumps/database_dump.sql." 125 | usage 126 | exit 1 127 | fi 128 | 129 | # Load the project settings file or display an error if it does not exist. 130 | if [ -e /etc/pullpush/projects/${PROJECT_NAME}.conf ] 131 | then 132 | source /etc/pullpush/projects/${PROJECT_NAME}.conf 133 | else 134 | echo "ERROR - The project settings file /etc/pullpush/projects/${PROJECT_NAME}.conf not found." 135 | exit 1 136 | fi 137 | 138 | # Load the configuration file and check it was loaded OK. 139 | __load_configuration_file 140 | 141 | if [ $? -ne 0 ] 142 | then 143 | echo "Configuration file was not loaded." 144 | fi 145 | 146 | echo "All tests completed OK." 147 | echo "Project name: ${PROJECT_NAME}" 148 | 149 | # ------------------------------------------------------------------------------------------------- 150 | # The plan. 151 | # 152 | # Before this script is run the live copy should have been transmitted to the dev server from the 153 | # live server. This should have: 154 | ## Synchronised the site files in the document root from the live server to the dev server. 155 | ## Dumped out the database to a dump file which is transferred over to the dev server. 156 | # 157 | # Steps which are part of the plan. 158 | ## Check that the project exists and a dev copy exists. 159 | ## Make a copy of the settings file. 160 | ## Copy the files from the livecopy site over the dev files using rsync. 161 | ## Copy back in the settings file. 162 | ## Dump out the database. 163 | ## Load the database from the db dump. 164 | # ------------------------------------------------------------------------------------------------- 165 | 166 | # Make a copy of the settings file. 167 | case "${PROJECT_TYPE}" in 168 | 169 | drupal7|drupal6) 170 | 171 | chmod 777 /home/${USER}/settings.php.dev.datadumpload.${PROJECT_NAME} 172 | cp /home/${USER}/projects/${PROJECT_NAME}/web/sites/default/settings.php /home/${USER}/settings.php.dev.datadumpload.${PROJECT_NAME} 173 | ;; 174 | *) 175 | echo "Error - Invalid project type." 176 | exit -1 177 | esac 178 | 179 | 180 | ##rsync -vrlpgo --exclude=.svn/ --checksum --delete /home/${USER}/extracted_dump_files/${PROJECT_NAME}/ /home/${USER}/projects/${PROJECT_NAME} 181 | rsync -vrlpgo --exclude=.svn/ --checksum --delete /home/livecopy/projects/${PROJECT_NAME}/web/ /home/${USER}/projects/${PROJECT_NAME}/web 182 | 183 | # Copy the settings file back. 184 | case "${PROJECT_TYPE}" in 185 | 186 | drupal7|drupal6) 187 | 188 | sudo chmod 777 /home/${USER}/projects/${PROJECT_NAME}/web/sites/default 189 | rm /home/${USER}/projects/${PROJECT_NAME}/web/sites/default/settings.php 190 | 191 | cp /home/${USER}/settings.php.dev.datadumpload.${PROJECT_NAME} /home/${USER}/projects/${PROJECT_NAME}/web/sites/default/settings.php 192 | ;; 193 | *) 194 | echo "Error - Invalid project type." 195 | exit -1 196 | esac 197 | 198 | # ------------------------------------------------------------------------------------------------- 199 | echo 200 | echo `date` 201 | echo "Dumping out the database to a file..." 202 | # ------------------------------------------------------------------------------------------------- 203 | sudo -u livecopy -i sh -c "mkdir -p /home/livecopy/projects/${PROJECT_NAME}/livecopy_dumps" 204 | ###sudo -u deploy -i sh -c "mkdir -p /home/deploy/projects/${PROJECT_NAME}/db" 205 | sudo -u livecopy -i sh -c "mysqldump livecopypr${PROJECT_NAME} > /home/livecopy/projects/${PROJECT_NAME}/livecopy_dumps/database_dump.sql" 206 | 207 | # ------------------------------------------------------------------------------------------------- 208 | echo 209 | echo `date` 210 | echo "Load database over top of existing database..." 211 | # ------------------------------------------------------------------------------------------------- 212 | mysqladmin --force drop ${USER}pr${PROJECT_NAME} 213 | mysqladmin create ${USER}pr${PROJECT_NAME} 214 | 215 | mysql ${USER}pr${PROJECT_NAME} < /home/livecopy/projects/${PROJECT_NAME}/livecopy_dumps/database_dump.sql 216 | 217 | # ------------------------------------------------------------------------------------------------- 218 | echo 219 | echo `date` 220 | echo "Finished..." 221 | # ------------------------------------------------------------------------------------------------- 222 | exit 0 223 | -------------------------------------------------------------------------------- /pulldeployfrombeta: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=================================================================================== 3 | # 4 | # FILE: pulldeployfrombeta 5 | # 6 | # USAGE: pulldeployfrombeta -p [project type] 7 | # 8 | # DESCRIPTION: This will pull a copy of a beta site and create a new deploy site. 9 | # 10 | # OPTIONS: see function ’usage’ below 11 | # NOTES: --- 12 | # AUTHOR: Kevin Bailey, kbailey@freewayprojects.com 13 | # COMPANY: Freeway Projects Limited 14 | #=================================================================================== 15 | 16 | # Make sure only one Pullpush script is running at any one time. 17 | touch /var/lock/pullpush 18 | chmod --quiet 666 /var/lock/pullpush 19 | exec 9>/var/lock/pullpush 20 | if ! flock -n 9 ; then 21 | echo "Another Pullpush script is currently running - try again later."; 22 | exit 1 23 | fi 24 | 25 | # ------------------------------------------------------------------------------------------------- 26 | # Set up global variables. 27 | # 28 | # We are going to explicitly set the script name variable. Obviously the script name is available 29 | # as $0 - but this is not consistent and may or may not contain the path. Also, this means we can 30 | # use the bash debugger without needing to handle the fact that $0 would contain something like 31 | # 'bashdb'. 32 | # ------------------------------------------------------------------------------------------------- 33 | SCRIPT_NAME=pulldeployfrombeta 34 | DATE_TIME=$(date +%Y%m%d-%H%M%S) 35 | 36 | # ------------------------------------------------------------------------------------------------- 37 | # Set up the user to be able to run sudo commands - this will be revoked at the end of the script. 38 | # ------------------------------------------------------------------------------------------------- 39 | sudo -v 40 | 41 | # ------------------------------------------------------------------------------------------------- 42 | # Log all output from the script. 43 | # 44 | # As we are going to be carrying out multiple steps and it is important we can see all the output 45 | # to be able to diagnose problems. 46 | # ------------------------------------------------------------------------------------------------- 47 | 48 | # Create a place for the log files. 49 | sudo mkdir -p /var/log/pullpush 50 | sudo chmod 777 /var/log/pullpush 51 | 52 | # Create a pipe... 53 | tmppipe=$(mktemp -u) 54 | mkfifo ${tmppipe} 55 | 56 | # ...then start a tee process which takes as its input the pipe - and output to the logfile (and 57 | # standard output) and then push the tee process into the background (subshell). 58 | tee < ${tmppipe} /var/log/pullpush/${DATE_TIME}_${USER}_${SCRIPT_NAME}.log & 59 | 60 | # Redirect both standard output and standard error to the pipe just created - these outputs 61 | # will then be directed via the pipe to standard output (the current shell) and the log file. 62 | exec &> ${tmppipe} 63 | 64 | # This sets up the pipe to be removed - it will only be fully dropped when no process is using it. 65 | rm ${tmppipe} 66 | 67 | # ------------------------------------------------------------------------------------------------- 68 | # Import Pullpush functions. 69 | # ------------------------------------------------------------------------------------------------- 70 | source /usr/local/share/pullpush/pullpush_functions 71 | 72 | # ------------------------------------------------------------------------------------------------- 73 | # Local functions 74 | # 75 | # Here we will define all the functions used by this script. 76 | # ------------------------------------------------------------------------------------------------- 77 | 78 | # Output a usage message - used when the parameters input are not correct. 79 | usage () { 80 | echo "Usage: $SCRIPT_NAME -p [project name]" 81 | } 82 | 83 | # ------------------------------------------------------------------------------------------------- 84 | # Testing parameters 85 | # ------------------------------------------------------------------------------------------------- 86 | while getopts ":p:" opt; do 87 | case $opt in 88 | p) 89 | PROJECT_NAME=$OPTARG 90 | ;; 91 | \?) 92 | echo "Invalid option: -$OPTARG" >&2 93 | usage 94 | exit 1 95 | ;; 96 | :) 97 | echo "Option -$OPTARG requires an argument." >&2 98 | usage 99 | exit 1 100 | ;; 101 | esac 102 | done 103 | 104 | # Check the parameter has had a value assigned. 105 | if [ -z $PROJECT_NAME ] 106 | then 107 | echo "The project name needs to be set." 108 | usage 109 | exit 1 110 | fi 111 | 112 | # Check the project exists. 113 | if [ ! -e /home/beta/projects/${PROJECT_NAME}/web ] 114 | then 115 | echo "The project does not appear to exist." 116 | usage 117 | exit 1 118 | fi 119 | 120 | # Load the project settings file or display an error if it does not exist. 121 | if [ -e /etc/pullpush/projects/${PROJECT_NAME}.conf ] 122 | then 123 | source /etc/pullpush/projects/${PROJECT_NAME}.conf 124 | else 125 | echo "ERROR - The project settings file /etc/pullpush/projects/${PROJECT_NAME}.conf not found." 126 | exit 1 127 | fi 128 | 129 | # Load the configuration file and check it was loaded OK. 130 | __load_configuration_file 131 | 132 | if [ $? -ne 0 ] 133 | then 134 | echo "Configuration file was not loaded." 135 | fi 136 | 137 | echo "All tests completed OK." 138 | echo "Project name: ${PROJECT_NAME}" 139 | 140 | # ------------------------------------------------------------------------------------------------- 141 | # The plan. 142 | # 143 | # If necessary create the vhost and the DB. 144 | # Clear the beta caches. 145 | # Backup the beta DB. 146 | # Load the DB from the backup. 147 | # Check beta files into SVN. 148 | # Export files from SVN to deploy. 149 | # Update/create settings.php 150 | # ------------------------------------------------------------------------------------------------- 151 | 152 | # Set up the database and database user. 153 | DATABASE_NAME=deploypr${PROJECT_NAME} 154 | DATABASE_USER=deploypr${PROJECT_NAME} 155 | DATABASE_PASSWORD=`cat /dev/urandom | base64 | tr -d '[:punct:]' | tr -d '[:digit:]' | tr -d '[:upper:]' | cut -c1-10 | head -1` 156 | 157 | # If necessary create the database - if not then update the user. 158 | if [ ! -e /home/deploy/projects/${PROJECT_NAME}/web ] 159 | then 160 | 161 | # Set up the vhost. 162 | __set_up_vhost deploy-pr-${PROJECT_NAME} /home/deploy/projects/${PROJECT_NAME}/web deploy 163 | 164 | 165 | echo "Creating database..." 166 | __create_mysql_database_and_user_account ${DATABASE_NAME} ${DATABASE_USER} ${DATABASE_PASSWORD} 167 | else 168 | 169 | # Here we are going to update the privileges so we have the password in this script and we can add it to the settings file. 170 | # Also, it is a good idea to refresh the password to prevent connecting to the wrong database. 171 | echo "Updating database user..." 172 | mysql --execute="GRANT ALL ON ${DATABASE_NAME}.* TO '${DATABASE_USER}'@'localhost' IDENTIFIED BY '${DATABASE_PASSWORD}';" ${DATABASE_NAME} 173 | 174 | fi 175 | 176 | # Clear the beta caches. 177 | case "${PROJECT_TYPE}" in 178 | 179 | drupal7|drupal6) 180 | drush --root=/home/beta/projects/${PROJECT_NAME}/web cache-clear all 181 | ;; 182 | 183 | *) 184 | echo "Error - Invalid project type." 185 | exit 1 186 | esac 187 | 188 | echo "Backing up the beta DB..." 189 | mkdir -p /home/${USER}/backups/beta_sites 190 | mysqldump betapr${PROJECT_NAME} > /home/${USER}/backups/beta_sites/${PROJECT_NAME}.sql 191 | 192 | echo "Loading the DB from the backup..." 193 | mysql deploypr${PROJECT_NAME} < /home/${USER}/backups/beta_sites/${PROJECT_NAME}.sql 194 | 195 | echo "Putting the current beta files into SVN..." 196 | # This is necessary as site editors may have added content via the admin interface and this will have 197 | # included new files. 198 | __check_beta_files_into_svn 199 | 200 | # Export files from SVN. First we will need to delete all the existing files as export only exports 201 | # files and does not delete files which are in the destination but not in the repository. 202 | 203 | echo "Deleting any pre-existing deploy site files..." 204 | ###sudo -u deploy -i "rm -rf /home/deploy/projects/${PROJECT_NAME}/web" 205 | sudo -u deploy -i sh -c "rm -rf /home/deploy/projects/${PROJECT_NAME}/web" 206 | 207 | echo "Exporting the deploy site files..." 208 | ##sudo -u deploy -i "svn --force export http://localhost/svn/${PROJECT_NAME} /home/deploy/projects/${PROJECT_NAME}/web" 209 | ###sudo -u deploy -i "svn export http://localhost/svn/${PROJECT_NAME} /home/deploy/projects/${PROJECT_NAME}/web" 210 | sudo -u deploy -i sh -c "svn export http://localhost/svn/${PROJECT_NAME} /home/deploy/projects/${PROJECT_NAME}/web" 211 | 212 | echo "Creating and updating the settings file..." 213 | case "${PROJECT_TYPE}" in 214 | 215 | drupal7) 216 | 217 | # We will copy the file before changing it as changing it in place gets complicated when trying to escape the sudo command. 218 | cp /home/deploy/projects/${PROJECT_NAME}/web/sites/default/default.settings.php /home/${USER}/settings.php.deploypr${PROJECT_NAME} 219 | cat <> /home/${USER}/settings.php.deploypr${PROJECT_NAME} 220 | 221 | \$databases = array ( 222 | 'default' => 223 | array ( 224 | 'default' => 225 | array ( 226 | 'database' => '${DATABASE_NAME}', 227 | 'username' => '${DATABASE_USER}', 228 | 'password' => '${DATABASE_PASSWORD}', 229 | 'host' => 'localhost', 230 | 'port' => '', 231 | 'driver' => 'mysql', 232 | 'prefix' => '${DATABASE_PREFIX}', 233 | ), 234 | ), 235 | ); 236 | 237 | EOFSETTINGS 238 | 239 | sudo -u deploy -i sh -c "cp /home/${USER}/settings.php.deploypr${PROJECT_NAME} /home/deploy/projects/${PROJECT_NAME}/web/sites/default/settings.php" 240 | rm /home/${USER}/settings.php.deploypr${PROJECT_NAME} 241 | ;; 242 | 243 | drupal6) 244 | 245 | # We will copy the file before changing it as changing it in place gets complicated when trying to excape the sudo command. 246 | cp /home/deploy/projects/${PROJECT_NAME}/web/sites/default/default.settings.php /home/${USER}/settings.php.deploypr${PROJECT_NAME} 247 | echo "\$db_url = 'mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@localhost/${DATABASE_NAME}';" >> /home/${USER}/settings.php.deploypr${PROJECT_NAME} 248 | sudo -u deploy -i sh -c "cp /home/${USER}/settings.php.deploypr${PROJECT_NAME} /home/deploy/projects/${PROJECT_NAME}/web/sites/default/settings.php" 249 | rm /home/${USER}/settings.php.deploypr${PROJECT_NAME} 250 | ;; 251 | 252 | *) 253 | echo "Error - Invalid project type." 254 | exit -1 255 | esac 256 | 257 | # ------------------------------------------------------------------------------------------------- 258 | echo 259 | echo `date` 260 | echo "Finished - the deploy copy of the site is at http://deploy-pr-${PROJECT_NAME}.${SERVER_FQDN}..." 261 | # ------------------------------------------------------------------------------------------------- 262 | 263 | exit 0 264 | -------------------------------------------------------------------------------- /pullinitialsitefromsource: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=================================================================================== 3 | # 4 | # FILE: pullinitialsitefromsource 5 | # 6 | # USAGE: pullinitialsitefromsource -t [project type] -i [initial site name (1 to 6 alphanumeric characters)] 7 | # 8 | # DESCRIPTION: This will create an initial site which will be a vanilla copy from a 9 | # framework. It will achieve this by pulling down any source code needed from 10 | # repositories and creating any required databases. 11 | # 12 | # OPTIONS: see function ’usage’ below 13 | # NOTES: --- 14 | # AUTHOR: Kevin Bailey, kbailey@freewayprojects.com 15 | # COMPANY: Freeway Projects Limited 16 | #=================================================================================== 17 | 18 | # Make sure only one Pullpush script is running at any one time. 19 | touch /var/lock/pullpush 20 | chmod --quiet 666 /var/lock/pullpush 21 | exec 9>/var/lock/pullpush 22 | if ! flock -n 9 ; then 23 | echo "Another Pullpush script is currently running - try again later."; 24 | exit 1 25 | fi 26 | 27 | # ------------------------------------------------------------------------------------------------- 28 | # Set up global variables. 29 | # 30 | # We are going to explicitly set the script name variable. Obviously the script name is available 31 | # as $0 - but this is not consistent and may or may not contain the path. Also, this means we can 32 | # use the bash debugger without needing to handle the fact that $0 would contain something like 33 | # 'bashdb'. 34 | # ------------------------------------------------------------------------------------------------- 35 | SCRIPT_NAME=pullinitialsitefromsource 36 | DATE_TIME=$(date +%Y%m%d-%H%M%S) 37 | 38 | # ------------------------------------------------------------------------------------------------- 39 | # Set up the user to be able to run sudo commands - this will be revoked at the end of the script. 40 | # ------------------------------------------------------------------------------------------------- 41 | sudo -v 42 | 43 | # ------------------------------------------------------------------------------------------------- 44 | # Log all output from the script. 45 | # 46 | # As we are going to be carrying out multiple steps and it is important we can see all the output 47 | # to be able to diagnose problems. 48 | # ------------------------------------------------------------------------------------------------- 49 | 50 | # Create a place for the log files. 51 | sudo mkdir -p /var/log/pullpush 52 | sudo chmod 777 /var/log/pullpush 53 | 54 | # Create a pipe... 55 | tmppipe=$(mktemp -u) 56 | mkfifo ${tmppipe} 57 | 58 | # ...then start a tee process which takes as its input the pipe - and output to the logfile (and 59 | # standard output) and then push the tee process into the background (subshell). 60 | tee < ${tmppipe} /var/log/pullpush/${DATE_TIME}_${USER}_${SCRIPT_NAME}.log & 61 | 62 | # Redirect both standard output and standard error to the pipe just created - these outputs 63 | # will then be directed via the pipe to standard output (the current shell) and the log file. 64 | exec &> ${tmppipe} 65 | 66 | # This sets up the pipe to be removed - it will only be fully dropped when no process is using it. 67 | rm ${tmppipe} 68 | 69 | # ------------------------------------------------------------------------------------------------- 70 | # Import Pullpush functions. 71 | # ------------------------------------------------------------------------------------------------- 72 | source /usr/local/share/pullpush/pullpush_functions 73 | 74 | # ------------------------------------------------------------------------------------------------- 75 | # Local functions 76 | # 77 | # Here we will define all the functions used by this script. 78 | # ------------------------------------------------------------------------------------------------- 79 | 80 | # Output a usage message - used when the parameters input are not correct. 81 | usage () { 82 | echo "Usage: $SCRIPT_NAME -t [project type] -i [initial site name (1 to 6 alphanumeric characters)]" 83 | } 84 | 85 | # ------------------------------------------------------------------------------------------------- 86 | # Testing parameters 87 | # ------------------------------------------------------------------------------------------------- 88 | while getopts ":t:i:" opt; do 89 | case $opt in 90 | t) 91 | PROJECT_TYPE=$OPTARG 92 | ;; 93 | i) 94 | INITIAL_SITE_NAME=$OPTARG 95 | ;; 96 | \?) 97 | echo "Invalid option: -$OPTARG" >&2 98 | usage 99 | exit 1 100 | ;; 101 | :) 102 | echo "Option -$OPTARG requires an argument." >&2 103 | usage 104 | exit 1 105 | ;; 106 | esac 107 | done 108 | 109 | # Check both parameters have had values assigned. 110 | if [ -z $PROJECT_TYPE ] || [ -z $INITIAL_SITE_NAME ] 111 | then 112 | echo "The project type and the initial site name need to be set." 113 | usage 114 | exit 1 115 | fi 116 | 117 | # Check that the project type is valid. 118 | if [ $PROJECT_TYPE != "drupal7" ] && [ $PROJECT_TYPE != "drupal6" ] 119 | then 120 | echo "The currently supported project types are 'drupal7' and drupal6." 121 | exit 1 122 | fi 123 | 124 | # Check that the initial site name is valid. 125 | if [ ${#INITIAL_SITE_NAME} -gt 6 ]; then 126 | echo "The initial site name should be no longer than 6 characters." 127 | usage 128 | exit 1 129 | fi 130 | 131 | # Check that only alphanumeric characters are used for the initial site name. 132 | compressed="$(echo ${INITIAL_SITE_NAME} | sed -e 's/[^[:alnum:]]//g')" 133 | if [ "$compressed" != "${INITIAL_SITE_NAME}" ] ; then 134 | echo "The initial site should only contain alphanumeric characters." 135 | usage 136 | exit 1 137 | fi 138 | 139 | if [ -e /home/${USER}/initial_sites/${INITIAL_SITE_NAME} ] 140 | then 141 | echo "The initial site name has been used already. Either remove the site or choose a name which has not been used already." 142 | usage 143 | exit 1 144 | fi 145 | 146 | # Load the configuration file and check it was loaded OK. 147 | __load_configuration_file 148 | if [ $? -ne 0 ] 149 | then 150 | echo "Configuration file was not loaded." 151 | fi 152 | 153 | echo "All tests completed OK." 154 | 155 | echo "Project type: ${PROJECT_TYPE}" 156 | echo "Initial site name: ${INITIAL_SITE_NAME}" 157 | 158 | # ------------------------------------------------------------------------------------------------- 159 | echo 160 | echo `date` 161 | echo "Creating the database and database user..." 162 | # ------------------------------------------------------------------------------------------------- 163 | DATABASE_NAME=${USER}is${INITIAL_SITE_NAME} 164 | DATABASE_USER=${USER}is${INITIAL_SITE_NAME} 165 | PASSWORD=`cat /dev/urandom | base64 | tr -d '[:punct:]' | tr -d '[:digit:]' | tr -d '[:upper:]' | cut -c1-10 | head -1` 166 | 167 | __create_mysql_database_and_user_account ${USER}is${INITIAL_SITE_NAME} ${USER}is${INITIAL_SITE_NAME} ${PASSWORD} 168 | 169 | # ------------------------------------------------------------------------------------------------- 170 | echo 171 | echo `date` 172 | echo "Downloading site files..." 173 | # ------------------------------------------------------------------------------------------------- 174 | case "${PROJECT_TYPE}" in 175 | 176 | drupal7) 177 | echo 178 | echo `date` 179 | echo "Downloading a drupal7 site..." 180 | mkdir -p ~/initial_sites/${INITIAL_SITE_NAME} 181 | drush dl drupal-7 --drupal-project-rename=web --destination=/home/${USER}/initial_sites/${INITIAL_SITE_NAME} 182 | ;; 183 | 184 | drupal6) 185 | echo 186 | echo `date` 187 | echo "Downloading a drupal6 site..." 188 | mkdir -p ~/initial_sites/${INITIAL_SITE_NAME} 189 | drush dl drupal-6 --drupal-project-rename=web --destination=/home/${USER}/initial_sites/${INITIAL_SITE_NAME} 190 | ;; 191 | 192 | *) 193 | echo "Error - Invalid project type." 194 | exit -1 195 | esac 196 | 197 | # ------------------------------------------------------------------------------------------------- 198 | echo 199 | echo `date` 200 | echo "Set up the vhost for the site..." 201 | # ------------------------------------------------------------------------------------------------- 202 | 203 | __set_up_vhost ${USER}-is-${INITIAL_SITE_NAME} /home/${USER}/initial_sites/${INITIAL_SITE_NAME}/web ${USER} 204 | 205 | # ------------------------------------------------------------------------------------------------- 206 | echo 207 | echo `date` 208 | echo "Carry out a site install on the new site based on the database just created..." 209 | # ------------------------------------------------------------------------------------------------- 210 | case "${PROJECT_TYPE}" in 211 | 212 | drupal7|drupal6) 213 | echo 214 | echo `date` 215 | echo "Carrying out a site install on the Drupal 7 site..." 216 | 217 | drush site-install --db-url=mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@localhost/${DATABASE_NAME} --yes --root=/home/${USER}/initial_sites/${INITIAL_SITE_NAME}/web 218 | 219 | # Now we've allowed the user to set up the Drupal site we're going to reduce the user 220 | # down to only the rights which they need to run Drupal. We do this by revoking all 221 | # rights and then only allowing the required rights. 222 | mysql --execute="REVOKE ALL PRIVILEGES, GRANT OPTION FROM '${DATABASE_USER}'@'localhost' IDENTIFIED BY '${DATABASE_PASSWORD}';" ${DATABASE_NAME} 223 | mysql --execute="GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON ${DATABASE_NAME}.* TO '${DATABASE_USER}'@'localhost' IDENTIFIED BY '${DATABASE_PASSWORD}';" ${DATABASE_NAME} 224 | 225 | if [ "${WEB_SERVER_TYPE}" = "apache2prefork" ] 226 | then 227 | echo 228 | echo `date` 229 | echo "Add the www-data user to the developers group so that the web server can write to the files/ directory..." 230 | sudo adduser --quiet www-data ${USER} 231 | 232 | echo 233 | echo `date` 234 | echo "Setting permissions for the files/ directory so the web server can write to it..." 235 | sudo chmod -R 775 /home/${USER}/initial_sites/${INITIAL_SITE_NAME}/web/sites/default/files 236 | fi 237 | ;; 238 | 239 | *) 240 | echo "Error - Invalid project type." 241 | exit -1 242 | esac 243 | 244 | # This will remove the sudo timestamp. There are a couple of reasons for this. The first is that 245 | # it will force the user to validate on every script run. And the second is that since the script 246 | # should take less than 15 minutes (which is the default sudo timestamp) then by validating at the 247 | # start we should be able to carry out a full script run without sudo timing out. 248 | sudo -k 249 | 250 | # ------------------------------------------------------------------------------------------------- 251 | echo 252 | echo `date` 253 | echo "This is the URL for the new site: " 254 | echo ${USER}-is-${INITIAL_SITE_NAME}.${SERVER_FQDN} 255 | # ------------------------------------------------------------------------------------------------- 256 | 257 | 258 | # ------------------------------------------------------------------------------------------------- 259 | echo 260 | echo `date` 261 | echo "Finished." 262 | # ------------------------------------------------------------------------------------------------- 263 | 264 | exit 0 265 | -------------------------------------------------------------------------------- /pulllivecopyfromdatadump: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=================================================================================== 3 | # 4 | # FILE: pulllivecopyfromdatadump 5 | # 6 | # USAGE: pulllivecopyfromdatadump -p [project type] 7 | # 8 | # DESCRIPTION: This will create a livecopy site from a data dump. 9 | # 10 | # OPTIONS: see function ’usage’ below 11 | # NOTES: --- 12 | # AUTHOR: Kevin Bailey, kbailey@freewayprojects.com 13 | # COMPANY: Freeway Projects Limited 14 | #=================================================================================== 15 | 16 | # Make sure only one Pullpush script is running at any one time. 17 | touch /var/lock/pullpush 18 | chmod --quiet 666 /var/lock/pullpush 19 | exec 9>/var/lock/pullpush 20 | if ! flock -n 9 ; then 21 | echo "Another Pullpush script is currently running - try again later."; 22 | exit 1 23 | fi 24 | 25 | # ------------------------------------------------------------------------------------------------- 26 | # Set up global variables. 27 | # 28 | # We are going to explicitly set the script name variable. Obviously the script name is available 29 | # as $0 - but this is not consistent and may or may not contain the path. Also, this means we can 30 | # use the bash debugger without needing to handle the fact that $0 would contain something like 31 | # 'bashdb'. 32 | # ------------------------------------------------------------------------------------------------- 33 | SCRIPT_NAME=pulllivecopyfromdatadump 34 | DATE_TIME=$(date +%Y%m%d-%H%M%S) 35 | 36 | # ------------------------------------------------------------------------------------------------- 37 | # Set up the user to be able to run sudo commands - this will be revoked at the end of the script. 38 | # ------------------------------------------------------------------------------------------------- 39 | sudo -v 40 | 41 | # ------------------------------------------------------------------------------------------------- 42 | # Log all output from the script. 43 | # 44 | # As we are going to be carrying out multiple steps and it is important we can see all the output 45 | # to be able to diagnose problems. 46 | # ------------------------------------------------------------------------------------------------- 47 | 48 | # Create a place for the log files. 49 | sudo mkdir -p /var/log/pullpush 50 | sudo chmod 777 /var/log/pullpush 51 | 52 | # Create a pipe... 53 | tmppipe=$(mktemp -u) 54 | mkfifo ${tmppipe} 55 | 56 | # ...then start a tee process which takes as its input the pipe - and output to the logfile (and 57 | # standard output) and then push the tee process into the background (subshell). 58 | tee < ${tmppipe} /var/log/pullpush/${DATE_TIME}_${USER}_${SCRIPT_NAME}.log & 59 | 60 | # Redirect both standard output and standard error to the pipe just created - these outputs 61 | # will then be directed via the pipe to standard output (the current shell) and the log file. 62 | exec &> ${tmppipe} 63 | 64 | # This sets up the pipe to be removed - it will only be fully dropped when no process is using it. 65 | rm ${tmppipe} 66 | 67 | # ------------------------------------------------------------------------------------------------- 68 | # Import Pullpush functions. 69 | # ------------------------------------------------------------------------------------------------- 70 | source /usr/local/share/pullpush/pullpush_functions 71 | 72 | # ------------------------------------------------------------------------------------------------- 73 | # Local functions 74 | # 75 | # Here we will define all the functions used by this script. 76 | # ------------------------------------------------------------------------------------------------- 77 | 78 | # Output a usage message - used when the parameters input are not correct. 79 | usage () { 80 | echo "Usage: $SCRIPT_NAME -p [project name]" 81 | } 82 | 83 | # ------------------------------------------------------------------------------------------------- 84 | # Testing parameters 85 | # ------------------------------------------------------------------------------------------------- 86 | while getopts ":p:" opt; do 87 | case $opt in 88 | p) 89 | PROJECT_NAME=$OPTARG 90 | ;; 91 | \?) 92 | echo "Invalid option: -$OPTARG" >&2 93 | usage 94 | exit 1 95 | ;; 96 | :) 97 | echo "Option -$OPTARG requires an argument." >&2 98 | usage 99 | exit 1 100 | ;; 101 | esac 102 | done 103 | 104 | # Check the parameter has had a value assigned. 105 | if [ -z $PROJECT_NAME ] 106 | then 107 | echo "ERROR - The project name needs to be set." 108 | usage 109 | exit 1 110 | fi 111 | 112 | # Check the project exists. 113 | if [ ! -e /home/beta/projects/${PROJECT_NAME}/web ] 114 | then 115 | echo "ERROR - The project does not appear to exist." 116 | usage 117 | exit 1 118 | fi 119 | 120 | # Check the data dump file exists. 121 | if [ ! -e /home/livecopy/projects/${PROJECT_NAME}/live_dumps/database_dump.sql ] 122 | then 123 | echo "ERROR - The data dump file is missing." 124 | echo "The script is expecting to be able to read the file /home/livecopy/projects/${PROJECT_NAME}/live_dumps/database_dump.sql." 125 | usage 126 | exit 1 127 | fi 128 | 129 | # Load the project settings file or display an error if it does not exist. 130 | if [ -e /etc/pullpush/projects/${PROJECT_NAME}.conf ] 131 | then 132 | source /etc/pullpush/projects/${PROJECT_NAME}.conf 133 | else 134 | echo "ERROR - The project settings file /etc/pullpush/projects/${PROJECT_NAME}.conf not found." 135 | exit 1 136 | fi 137 | 138 | # Load the configuration file and check it was loaded OK. 139 | __load_configuration_file 140 | 141 | if [ $? -ne 0 ] 142 | then 143 | echo "Configuration file was not loaded." 144 | fi 145 | 146 | echo "All tests completed OK." 147 | echo "Project name: ${PROJECT_NAME}" 148 | 149 | # ------------------------------------------------------------------------------------------------- 150 | # The plan. 151 | # 152 | ## Check dump files have been sent to the dev server. 153 | ## If necessary create the vhost and database. 154 | ## Unzip the site files. 155 | ## Load the database from the db dump. 156 | ## Append the database connection settings to the settings.php file. 157 | # ------------------------------------------------------------------------------------------------- 158 | 159 | # Set up the database and database user. 160 | DATABASE_NAME=livecopypr${PROJECT_NAME} 161 | DATABASE_USER=livecopypr${PROJECT_NAME} 162 | DATABASE_PASSWORD=`cat /dev/urandom | base64 | tr -d '[:punct:]' | tr -d '[:digit:]' | tr -d '[:upper:]' | cut -c1-10 | head -1` 163 | 164 | # If necessary create the database and the vhost. We are going to check the vhost 165 | # conf file exists - and will assume that if the vhost has not been set up then 166 | # the DB has not been set up. 167 | # if [ ! -e /home/livecopy/projects/${PROJECT_NAME}/web ] 168 | if [ ! -e /etc/apache2/sites-available/livecopy-pr-${PROJECT_NAME} ] 169 | then 170 | 171 | echo "Setting up the vhost..." 172 | __set_up_vhost livecopy-pr-${PROJECT_NAME} /home/livecopy/projects/${PROJECT_NAME}/web livecopy 173 | 174 | echo "Creating database..." 175 | __create_mysql_database_and_user_account ${DATABASE_NAME} ${DATABASE_USER} ${DATABASE_PASSWORD} 176 | else 177 | 178 | # Here we are going to update the privileges so we have the password in this script and we can add it to the settings file. 179 | # Also, it is a good idea to refresh the password to prevent connecting to the wrong database. 180 | echo "Updating database user as database has already been created..." 181 | mysql --execute="GRANT ALL ON ${DATABASE_NAME}.* TO '${DATABASE_USER}'@'localhost' IDENTIFIED BY '${DATABASE_PASSWORD}';" ${DATABASE_NAME} 182 | fi 183 | 184 | # Load the DB from the backup. 185 | ##mysql livecopypr${PROJECT_NAME} < /home/livecopy/data_dumps/${PROJECT_NAME}_${DATETIME_STAMP}.sql 186 | 187 | # todo - we need to drop the database and recreate it. 188 | mysqladmin --force drop livecopypr${PROJECT_NAME} 189 | mysqladmin create livecopypr${PROJECT_NAME} 190 | mysql livecopypr${PROJECT_NAME} < /home/livecopy/projects/${PROJECT_NAME}/live_dumps/database_dump.sql 191 | 192 | # Remove the exsiting site files and unzip the live site files. 193 | sudo -u livecopy -i sh -c "rm -rf /home/livecopy/projects/${PROJECT_NAME}/web" 194 | sudo -u livecopy -i sh -c "mkdir -p /home/livecopy/projects/${PROJECT_NAME}/web" 195 | sudo -u livecopy -i sh -c "gzip -dq /home/livecopy/projects/${PROJECT_NAME}/live_dumps/site_files.tar.gz" 196 | sudo -u livecopy -i sh -c "tar -x --file=/home/livecopy/projects/${PROJECT_NAME}/live_dumps/site_files.tar --directory=/home/livecopy/projects/${PROJECT_NAME}/web --strip-components=4" 197 | 198 | # Here we are going recreate the zip file so that this script can run again. 199 | sudo -u livecopy -i sh -c "gzip /home/livecopy/projects/${PROJECT_NAME}/live_dumps/site_files.tar" 200 | 201 | # Update the settings file. 202 | case "${PROJECT_TYPE}" in 203 | 204 | drupal7) 205 | 206 | # We will copy the file before changing it as changing it in place gets complicated when trying to escape the sudo command. 207 | # Changing permissions may be neccessary as we do not know what permissions the files have been sent down with. We are 208 | # also going to explicitly set the temp file directory and the private file directory to make them suitable for the dev 209 | # server. 210 | sudo -u livecopy -i sh -c "chmod -R 755 /home/livecopy/projects/${PROJECT_NAME}/web" 211 | sudo -u livecopy -i sh -c "chmod -R 777 /home/livecopy/projects/${PROJECT_NAME}/web/sites/default/files" 212 | cp /home/livecopy/projects/${PROJECT_NAME}/web/sites/default/settings.php /home/${USER}/settings.php.livecopypr${PROJECT_NAME} 213 | cat <> /home/${USER}/settings.php.livecopypr${PROJECT_NAME} 214 | 215 | \$databases = array ( 216 | 'default' => 217 | array ( 218 | 'default' => 219 | array ( 220 | 'database' => '${DATABASE_NAME}', 221 | 'username' => '${DATABASE_USER}', 222 | 'password' => '${DATABASE_PASSWORD}', 223 | 'host' => 'localhost', 224 | 'port' => '', 225 | 'driver' => 'mysql', 226 | 'prefix' => '${DATABASE_PREFIX}', 227 | ), 228 | ), 229 | ); 230 | 231 | \$conf['file_temporary_path'] = '/tmp'; 232 | 233 | EOFSETTINGS 234 | 235 | sudo -u livecopy -i sh -c "cp /home/${USER}/settings.php.livecopypr${PROJECT_NAME} /home/livecopy/projects/${PROJECT_NAME}/web/sites/default/settings.php" 236 | rm /home/${USER}/settings.php.livecopypr${PROJECT_NAME} 237 | ;; 238 | 239 | drupal6) 240 | 241 | # We will copy the file before changing it as changing it in place gets complicated when trying to excape the sudo command. 242 | cp /home/livecopy/projects/${PROJECT_NAME}/web/sites/default/settings.php /home/${USER}/settings.php.livecopypr${PROJECT_NAME} 243 | echo "\$db_url = 'mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@localhost/${DATABASE_NAME}';" >> /home/${USER}/settings.php.livecopypr${PROJECT_NAME} 244 | sudo -u livecopy -i sh -c "cp /home/${USER}/settings.php.livecopypr${PROJECT_NAME} /home/livecopy/projects/${PROJECT_NAME}/web/sites/default/settings.php" 245 | rm /home/${USER}/settings.php.livecopypr${PROJECT_NAME} 246 | ;; 247 | 248 | *) 249 | echo "Error - Invalid project type." 250 | exit -1 251 | esac 252 | 253 | # Clear out any caches - this may be needed as the site is now in a different location. 254 | case "${PROJECT_TYPE}" in 255 | 256 | drupal7|drupal6) 257 | sudo -u livecopy -i sh -c "drush --root=/home/livecopy/projects/${PROJECT_NAME}/web cache-clear all" 258 | ;; 259 | 260 | *) 261 | echo "Error - Invalid project type." 262 | exit 1 263 | esac 264 | 265 | # ------------------------------------------------------------------------------------------------- 266 | echo 267 | echo `date` 268 | echo "Finished - the live copy of the site is at http://livecopy-pr-${PROJECT_NAME}.${SERVER_FQDN}" 269 | # ------------------------------------------------------------------------------------------------- 270 | 271 | exit 0 272 | -------------------------------------------------------------------------------- /pushdevtobeta: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=================================================================================== 3 | # 4 | # FILE: pushdevtobeta 5 | # 6 | # USAGE: pushdevtobeta [project type] 7 | # 8 | # DESCRIPTION: This will push the local dev copy up to the beta version. 9 | # 10 | # OPTIONS: see function ’usage’ below 11 | # NOTES: --- 12 | # AUTHOR: Kevin Bailey, kbailey@freewayprojects.com 13 | # COMPANY: Freeway Projects Limited 14 | #=================================================================================== 15 | 16 | # Make sure only one Pullpush script is running at any one time. 17 | touch /var/lock/pullpush 18 | chmod --quiet 666 /var/lock/pullpush 19 | exec 9>/var/lock/pullpush 20 | if ! flock -n 9 ; then 21 | echo "Another Pullpush script is currently running - try again later."; 22 | exit 1 23 | fi 24 | 25 | # ------------------------------------------------------------------------------------------------- 26 | # Set up global variables. 27 | # 28 | # We are going to explicitly set the script name variable. Obviously the script name is available 29 | # as $0 - but this is not consistent and may or may not contain the path. Also, this means we can 30 | # use the bash debugger without needing to handle the fact that $0 would contain something like 31 | # 'bashdb'. 32 | # ------------------------------------------------------------------------------------------------- 33 | SCRIPT_NAME=pushdevtobeta 34 | DATE_TIME=$(date +%Y%m%d-%H%M%S) 35 | 36 | # ------------------------------------------------------------------------------------------------- 37 | # Set up the user to be able to run sudo commands - this will be revoked at the end of the script. 38 | # ------------------------------------------------------------------------------------------------- 39 | sudo -v 40 | 41 | # ------------------------------------------------------------------------------------------------- 42 | # Log all output from the script. 43 | # 44 | # As we are going to be carrying out multiple steps and it is important we can see all the output 45 | # to be able to diagnose problems. 46 | # ------------------------------------------------------------------------------------------------- 47 | 48 | # Create a place for the log files. 49 | sudo mkdir -p /var/log/pullpush 50 | sudo chmod 777 /var/log/pullpush 51 | 52 | # Create a pipe... 53 | tmppipe=$(mktemp -u) 54 | mkfifo ${tmppipe} 55 | 56 | # ...then start a tee process which takes as its input the pipe - and output to the logfile (and 57 | # standard output) and then push the tee process into the background (subshell). 58 | tee < ${tmppipe} /var/log/pullpush/${DATE_TIME}_${USER}_${SCRIPT_NAME}.log & 59 | 60 | # Redirect both standard output and standard error to the pipe just created - these outputs 61 | # will then be directed via the pipe to standard output (the current shell) and the log file. 62 | exec &> ${tmppipe} 63 | 64 | # This sets up the pipe to be removed - it will only be fully dropped when no process is using it. 65 | rm ${tmppipe} 66 | 67 | # ------------------------------------------------------------------------------------------------- 68 | # Import Pullpush functions. 69 | # ------------------------------------------------------------------------------------------------- 70 | source /usr/local/share/pullpush/pullpush_functions 71 | 72 | # ------------------------------------------------------------------------------------------------- 73 | # Local functions 74 | # 75 | # Here we will define all the functions used by this script. 76 | # ------------------------------------------------------------------------------------------------- 77 | 78 | # Output a usage message - used when the parameters input are not correct. 79 | usage () { 80 | echo "Usage: $SCRIPT_NAME -p [project name]" 81 | } 82 | 83 | # ------------------------------------------------------------------------------------------------- 84 | # Testing parameters 85 | # ------------------------------------------------------------------------------------------------- 86 | while getopts ":p:" opt; do 87 | case $opt in 88 | p) 89 | PROJECT_NAME=$OPTARG 90 | ;; 91 | \?) 92 | echo "Invalid option: -$OPTARG" >&2 93 | usage 94 | exit 1 95 | ;; 96 | :) 97 | echo "Option -$OPTARG requires an argument." >&2 98 | usage 99 | exit 1 100 | ;; 101 | esac 102 | done 103 | 104 | # Check the parameter has had a value assigned. 105 | if [ -z $PROJECT_NAME ] 106 | then 107 | echo "The project name needs to be set." 108 | usage 109 | exit 1 110 | fi 111 | 112 | # Check the project exists. 113 | if [ ! -e /home/beta/projects/${PROJECT_NAME}/web ] 114 | then 115 | echo "The project does not appear to exist." 116 | usage 117 | exit 1 118 | fi 119 | 120 | # Load the project settings file or display an error if it does not exist. 121 | if [ -e /etc/pullpush/projects/${PROJECT_NAME}.conf ] 122 | then 123 | source /etc/pullpush/projects/${PROJECT_NAME}.conf 124 | else 125 | echo "ERROR - The project settings file /etc/pullpush/projects/${PROJECT_NAME}.conf not found." 126 | exit 1 127 | fi 128 | 129 | # Load the configuration file and check it was loaded OK. 130 | __load_configuration_file 131 | 132 | if [ $? -ne 0 ] 133 | then 134 | echo "Configuration file was not loaded." 135 | fi 136 | 137 | echo "All tests completed OK." 138 | echo "Project name: ${PROJECT_NAME}" 139 | 140 | # ------------------------------------------------------------------------------------------------- 141 | echo 142 | echo `date` 143 | echo "Take sites offline..." 144 | # ------------------------------------------------------------------------------------------------- 145 | 146 | # Future versions of the script will need to pick up if the site is D6 or D7. It is possible that 147 | # both of these commands can be run on D6 and D7 safely. 148 | 149 | # These are the commands for Drupal 6. 150 | # drush @${DEV_SITE_NAME} vset --always-set site_offline 1 151 | # drush @${BETA_SITE_NAME} vset --always-set site_offline 1 152 | 153 | # These commands work for Drupal 7. 154 | ##drush @${DEV_SITE_NAME} vset maintenance_mode 1 --yes 155 | ##drush @${BETA_SITE_NAME} vset maintenance_mode 1 --yes 156 | 157 | 158 | # ------------------------------------------------------------------------------------------------- 159 | echo 160 | echo `date` 161 | echo "Changing permissions on the files/ directory to enable the script user to be able to work with wwwrun owned files..." 162 | # ------------------------------------------------------------------------------------------------- 163 | ##sudo chmod -R 777 ${BETA_DOCUMENT_ROOT}/sites/default/files 164 | ##sudo chmod -R 777 ${DEV_DOCUMENT_ROOT}/sites/default/files 165 | 166 | # ------------------------------------------------------------------------------------------------- 167 | echo 168 | echo `date` 169 | echo "Clearing out the caches on the sites to trim the database and files/ before copying..." 170 | # ------------------------------------------------------------------------------------------------- 171 | case "${PROJECT_TYPE}" in 172 | 173 | drupal7|drupal6) 174 | drush --root=/home/${USER}/projects/${PROJECT_NAME}/web cache-clear all 175 | ;; 176 | 177 | *) 178 | echo "Error - Invalid project type." 179 | exit 1 180 | esac 181 | 182 | # Bear in mind here that we may need to chmod the /files directory to 777 if we are not using Apache-ITK. 183 | ##drush @${DEV_SITE_NAME} cache-clear all 184 | ##drush @${BETA_SITE_NAME} cache-clear all 185 | 186 | ##drush --root=/home/${USER}/projects/${PROJECT_NAME} cache-clear all 187 | ##drush --root=/home/beta/web/${PROJECT_NAME} cache-clear all 188 | 189 | # ------------------------------------------------------------------------------------------------- 190 | echo 191 | echo `date` 192 | echo "Make backup copy of the dev site database to reload later into beta..." 193 | # ------------------------------------------------------------------------------------------------- 194 | 195 | mkdir -p /home/${USER}/backups/dev_sites 196 | ##mysqldump ${USER}${PROJECT_NAME} > /home/${USER}/backups/dev_sites/${PROJECT_NAME}_${DATE_TIME}.sql 197 | mysqldump ${USER}pr${PROJECT_NAME} > /home/${USER}/backups/dev_sites/${USER}pr${PROJECT_NAME}.sql 198 | 199 | ## We are not going to back up the files as this could get too large and take too long. Daily 200 | # server backups should be used if needed. 201 | ##tar --create --file=/home/${USER}/backups/dev_sites/${PROJECT_NAME}_${DATE_TIME}.tar /home/${USER}/projects/${PROJECT_NAME} 202 | ##tar --create --file=/home/${USER}/backups/dev_sites/${PROJECT_NAME}.tar /home/${USER}/projects/${PROJECT_NAME}/web 203 | 204 | # ------------------------------------------------------------------------------------------------- 205 | echo 206 | echo `date` 207 | echo "Make backup copy of the beta site..." 208 | # ------------------------------------------------------------------------------------------------- 209 | ##mysqldump -u ${BETA_MYSQL_USER} -p${BETA_MYSQL_PASS} ${BETA_MYSQL_DATABASE} > ${BACKUP_LOCATION}${DATE_TIME}_${BETA_MYSQL_DATABASE}.sql 210 | ##tar --create --file=${BACKUP_LOCATION}${DATE_TIME}_${BETA_SITE_NAME}.tar ${BETA_DOCUMENT_ROOT} 211 | 212 | 213 | ## We are not going to backup the beta site due to time and space considerations. When pulling 214 | # from beta to dev there is a complete snapshot made including a database dump. 215 | ##mkdir -p /home/${USER}/backups/beta_sites 216 | ##sudo mysqldump beta${PROJECT_NAME} > /home/${USER}/backups/beta_sites/${PROJECT_NAME}_${DATE_TIME}.sql 217 | ##sudo tar --create --file=/home/${USER}/backups/beta_sites/${PROJECT_NAME}_${DATE_TIME}.tar /home/beta/web/${PROJECT_NAME} 218 | 219 | 220 | # ------------------------------------------------------------------------------------------------- 221 | echo 222 | echo `date` 223 | echo "Check local version of the code matches the current SVN version - if it doesn't then the version in SVN has been updated..." 224 | # ------------------------------------------------------------------------------------------------- 225 | 226 | # Now checking that the revision number of dev's local svn copy matches the repository. If they don't match then the repository must have been 227 | # updated by another process or by another developer pushing up to beta. 228 | # NB - This shouldn't have happened as this script is supposed to run after the script has been run to pull the dev from beta - and so the 229 | # revision numbers should match. 230 | # We would need to see where that update come from and what (if any) database changes were made. 231 | 232 | dev_local_revision=$(svn info /home/${USER}/projects/${PROJECT_NAME}/web | grep '^Revision:' | sed s/^Revision:[[:space:]]*// ) 233 | remote_revision=$(svn info http://localhost/svn/${PROJECT_NAME} | grep '^Revision:' | awk '{print $2}') 234 | 235 | echo "Current dev_local_revision:${dev_local_revision}" 236 | echo "Current remote_revision:${remote_revision}" 237 | 238 | if [ "$dev_local_revision" != "$remote_revision" ] 239 | then 240 | echo "The revision number of the local copy does not match the remote respository version - this needs to be looked into - someone/some process has updated the repository - also check the database." 241 | exit 1 242 | fi 243 | 244 | # ------------------------------------------------------------------------------------------------- 245 | echo 246 | echo `date` 247 | echo "Here we will add a file to make sure that there is at least one file change to check in which will bump up the revision number..." 248 | # ------------------------------------------------------------------------------------------------- 249 | echo $(date) > /home/${USER}/projects/${PROJECT_NAME}/web/force_revision_bump.txt 250 | 251 | # ------------------------------------------------------------------------------------------------- 252 | echo 253 | echo `date` 254 | echo "Add/Delete locally added and deleted files..." 255 | # ------------------------------------------------------------------------------------------------- 256 | echo "Adding all new files to svn control list..." 257 | svn status /home/${USER}/projects/${PROJECT_NAME}/web | grep "^?" | sed s/^?// | sed s/[[:space:]]*// | xargs -i svn add "{}" 258 | 259 | echo "If files have been deleted then SVN needs to mark them for deletion..." 260 | svn status /home/${USER}/projects/${PROJECT_NAME}/web | grep "^\!" | sed s/^\!// | sed s/[[:space:]]*// | xargs -i svn delete "{}" 261 | 262 | echo "Committing and deleting the files which have changed in dev..." 263 | svn commit -m "${DATE_TIME} - Committing added/changed/deleted data files from ${USER}-${PROJECT_NAME} into repository." /home/${USER}/projects/${PROJECT_NAME}/web 264 | 265 | # Here we will check if the commit ran OK. This should pick up the return value from the svn command 266 | # but for now we will put in a visual safety check. In fact this check would be a good idea anyway 267 | # as a safety check. 268 | read -p "Did the commit run OK (y/n)?" 269 | if [ $REPLY != "y" ]; then 270 | echo "You will need to check why the files can not be commited before running this script again - Exiting..." 271 | exit 1 272 | fi 273 | echo "Continuing with the script..." 274 | 275 | # Now we will run an update - the reason for this is so the revision number of dev local and 276 | # the repository will match and can therefore be tested before running the next commit from dev. 277 | # I.e. After running this update the revision numbers match. When running the next test before 278 | # committing the dev files changes we can check the revision numbers and if they don't match then 279 | # the repository must have been updated by another process. This would then need to be investigated. 280 | echo "SVN update the local dev copy to get the revision number to match the repository revision..." 281 | svn update /home/${USER}/projects/${PROJECT_NAME}/web 282 | 283 | # ------------------------------------------------------------------------------------------------- 284 | echo 285 | echo `date` 286 | echo "SVN update beta site files from SVN..." 287 | # ------------------------------------------------------------------------------------------------- 288 | 289 | ##ssh beta@localhost "svn update /home/beta/web/${PROJECT_NAME}" 290 | sudo -u beta -i sh -c "svn update /home/beta/projects/${PROJECT_NAME}/web" 291 | 292 | # NB Now we need to chmod permissions on the files/ directory to enable the web server to manipulate 293 | # the files which have just been pulled out from SVN. 294 | if [ "${WEB_SERVER_TYPE}" = "apache2prefork" ] 295 | then 296 | echo 297 | echo `date` 298 | echo "Add the www-data user to the beta group so that the web server can write to the files/ directory..." 299 | sudo adduser --quiet www-data beta 300 | 301 | echo "Add the beta user to the www-data so the beta user can work with files with SVN etc..." 302 | sudo adduser --quiet beta www-data 303 | 304 | echo 305 | echo `date` 306 | echo "Setting permissions for the files/ directory so the web server can write to it..." 307 | sudo chmod -R 775 /home/beta/projects/${PROJECT_NAME}/web/sites/default/files 308 | fi 309 | 310 | # NB Now we need to chmod permissions on the files/ directory to enable the web server to manipulate 311 | # these files. 312 | ##sudo chmod -R 777 ${BETA_DOCUMENT_ROOT}/sites/default/files 313 | 314 | # ------------------------------------------------------------------------------------------------- 315 | echo 316 | echo `date` 317 | echo "Copy database from dev to beta..." 318 | # ------------------------------------------------------------------------------------------------- 319 | ##mysqladmin --force -u ${BETA_MYSQL_USER} -p${BETA_MYSQL_PASS} drop ${BETA_MYSQL_DATABASE} 320 | ##mysqladmin -u ${BETA_MYSQL_USER} -p${BETA_MYSQL_PASS} create ${BETA_MYSQL_DATABASE} 321 | 322 | ##rm ${BACKUP_LOCATION}sql_sync_dump.sql 323 | ##drush sql-sync @${DEV_SITE_NAME} @${BETA_SITE_NAME} --no-cache --source-dump=${BACKUP_LOCATION}sql_sync_dump.sql 324 | 325 | mysqladmin --force drop betapr${PROJECT_NAME} 326 | mysqladmin create betapr${PROJECT_NAME} 327 | mysql betapr${PROJECT_NAME} < /home/${USER}/backups/dev_sites/${USER}pr${PROJECT_NAME}.sql 328 | 329 | # ------------------------------------------------------------------------------------------------- 330 | echo 331 | echo `date` 332 | echo "Here we will clear out the caches again - this is needed by some modules such as ldap..." 333 | # ------------------------------------------------------------------------------------------------- 334 | ##drush @${DEV_SITE_NAME} cache-clear all 335 | ##drush @${BETA_SITE_NAME} cache-clear all 336 | 337 | ###drush --root=/home/${USER}/projects/${PROJECT_NAME} cache-clear all 338 | ###drush --root=/home/beta/web/${PROJECT_NAME} cache-clear all 339 | # ------------------------------------------------------------------------------------------------- 340 | echo 341 | echo `date` 342 | echo "Clearing out the beta cache to clean it up..." 343 | # ------------------------------------------------------------------------------------------------- 344 | case "${PROJECT_TYPE}" in 345 | 346 | drupal7|drupal6) 347 | drush --root=/home/beta/projects/${PROJECT_NAME}/web cache-clear all 348 | ;; 349 | 350 | *) 351 | echo "Error - Invalid project type." 352 | exit 1 353 | esac 354 | 355 | ### ------------------------------------------------------------------------------------------------- 356 | ##echo 357 | ##echo `date` 358 | ##echo "Bring sites online..." 359 | ### ------------------------------------------------------------------------------------------------- 360 | 361 | # These are the D6 commands. 362 | ##drush @${DEV_SITE_NAME} vset --always-set site_offline 0 363 | ##drush @${BETA_SITE_NAME} vset --always-set site_offline 0 364 | 365 | # These commands work for Drupal 7. 366 | ##drush @${DEV_SITE_NAME} vset maintenance_mode 0 --yes 367 | ##drush @${BETA_SITE_NAME} vset maintenance_mode 0 --yes 368 | 369 | echo "The softlock is being turned off...." 370 | case "${PROJECT_TYPE}" in 371 | 372 | drupal7) 373 | 374 | drush -r /home/beta/projects/${PROJECT_NAME}/web vset maintenance_mode 0 --yes 375 | ;; 376 | 377 | drupal6) 378 | 379 | drush -r /home/beta/projects/${PROJECT_NAME}/web vset site_offline 0 --yes 380 | ;; 381 | 382 | *) 383 | echo "Error - Invalid project type." 384 | exit 1 385 | esac 386 | 387 | echo "The new revision number for the project is: $(svn info http://localhost/svn/${PROJECT_NAME} | grep '^Revision:' | awk '{print $2}')" 388 | 389 | # ------------------------------------------------------------------------------------------------- 390 | echo 391 | echo `date` 392 | echo "Finished..." 393 | # ------------------------------------------------------------------------------------------------- 394 | 395 | exit 0 396 | -------------------------------------------------------------------------------- /pushinitialsitetobeta: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=================================================================================== 3 | # 4 | # FILE: pushinitialsitetobeta 5 | # 6 | # USAGE: pushinitialsitetobeta -t [project type] -i [initial site name] -p [project name (1 to 6 alphanumeric characters)] 7 | # 8 | # DESCRIPTION: This will take an initial site and create a beta site from it. 9 | # 10 | # OPTIONS: see function ’usage’ below 11 | # NOTES: --- 12 | # AUTHOR: Kevin Bailey, kbailey@freewayprojects.com 13 | # COMPANY: Freeway Projects Limited 14 | #=================================================================================== 15 | 16 | # Make sure only one Pullpush script is running at any one time. 17 | touch /var/lock/pullpush 18 | chmod --quiet 666 /var/lock/pullpush 19 | exec 9>/var/lock/pullpush 20 | if ! flock -n 9 ; then 21 | echo "Another Pullpush script is currently running - try again later."; 22 | exit 1 23 | fi 24 | 25 | # ------------------------------------------------------------------------------------------------- 26 | # Set up global variables. 27 | # 28 | # We are going to explicitly set the script name variable. Obviously the script name is available 29 | # as $0 - but this is not consistent and may or may not contain the path. Also, this means we can 30 | # use the bash debugger without needing to handle the fact that $0 would contain something like 31 | # 'bashdb'. 32 | # ------------------------------------------------------------------------------------------------- 33 | SCRIPT_NAME=pushinitialsitetobeta 34 | DATE_TIME=$(date +%Y%m%d-%H%M%S) 35 | 36 | # ------------------------------------------------------------------------------------------------- 37 | # Set up the user to be able to run sudo commands - this will be revoked at the end of the script. 38 | # ------------------------------------------------------------------------------------------------- 39 | sudo -v 40 | 41 | # ------------------------------------------------------------------------------------------------- 42 | # Log all output from the script. 43 | # 44 | # As we are going to be carrying out multiple steps and it is important we can see all the output 45 | # to be able to diagnose problems. 46 | # ------------------------------------------------------------------------------------------------- 47 | 48 | # Create a place for the log files. 49 | sudo mkdir -p /var/log/pullpush 50 | sudo chmod 777 /var/log/pullpush 51 | 52 | # Create a pipe... 53 | tmppipe=$(mktemp -u) 54 | mkfifo ${tmppipe} 55 | 56 | # ...then start a tee process which takes as its input the pipe - and output to the logfile (and 57 | # standard output) and then push the tee process into the background (subshell). 58 | tee < ${tmppipe} /var/log/pullpush/${DATE_TIME}_${USER}_${SCRIPT_NAME}.log & 59 | 60 | # Redirect both standard output and standard error to the pipe just created - these outputs 61 | # will then be directed via the pipe to standard output (the current shell) and the log file. 62 | exec &> ${tmppipe} 63 | 64 | # This sets up the pipe to be removed - it will only be fully dropped when no process is using it. 65 | rm ${tmppipe} 66 | 67 | # ------------------------------------------------------------------------------------------------- 68 | # Import Pullpush functions. 69 | # ------------------------------------------------------------------------------------------------- 70 | source /usr/local/share/pullpush/pullpush_functions 71 | 72 | # ------------------------------------------------------------------------------------------------- 73 | # Local functions 74 | # 75 | # Here we will define all the functions used by this script. 76 | # ------------------------------------------------------------------------------------------------- 77 | 78 | # Output a usage message - used when the parameters input are not correct. 79 | usage () { 80 | echo "Usage: $SCRIPT_NAME -t [project type] -i [initial site name] -p [project name (1 to 6 alphanumeric characters)]" 81 | } 82 | 83 | # ------------------------------------------------------------------------------------------------- 84 | # Testing parameters 85 | # ------------------------------------------------------------------------------------------------- 86 | while getopts ":t:i:p:" opt; do 87 | case $opt in 88 | t) 89 | PROJECT_TYPE=$OPTARG 90 | ;; 91 | i) 92 | INITIAL_SITE_NAME=$OPTARG 93 | ;; 94 | p) 95 | PROJECT_NAME=$OPTARG 96 | ;; 97 | \?) 98 | echo "Invalid option: -$OPTARG" >&2 99 | usage 100 | exit 1 101 | ;; 102 | :) 103 | echo "Option -$OPTARG requires an argument." >&2 104 | usage 105 | exit 1 106 | ;; 107 | esac 108 | done 109 | 110 | # Check all parameters have had values assigned. 111 | if [ -z $PROJECT_TYPE ] || [ -z $INITIAL_SITE_NAME ] || [ -z $PROJECT_NAME ] 112 | then 113 | echo "The project type, the initial site name and the project name need to be set." 114 | usage 115 | exit 1 116 | fi 117 | 118 | # Check that the project type is valid. 119 | if [ $PROJECT_TYPE != "drupal7" ] && [ $PROJECT_TYPE != "drupal6" ] 120 | then 121 | echo "The currently supported project types are 'drupal7' and drupal6." 122 | exit 1 123 | fi 124 | 125 | # Check that the project name is valid. 126 | if [ ${#PROJECT_NAME} -gt 6 ]; then 127 | echo "The project name should be no longer than 6 characters." 128 | usage 129 | exit 1 130 | fi 131 | 132 | # Check that only alphanumeric characters are used for the project name. 133 | compressed="$(echo ${PROJECT_NAME} | sed -e 's/[^[:alnum:]]//g')" 134 | if [ "$compressed" != "${PROJECT_NAME}" ] ; then 135 | echo "The project name should only contain alphanumeric characters." 136 | usage 137 | exit 1 138 | fi 139 | 140 | if [ -e /home/beta/projects/${PROJECT_NAME} ] 141 | then 142 | echo "The project name has been used already - choose a different project name." 143 | usage 144 | exit 1 145 | fi 146 | 147 | # Check the initial site exists. 148 | if [ ! -e /home/${USER}/initial_sites/${INITIAL_SITE_NAME} ] 149 | then 150 | echo "The initial site does not appear to exist." 151 | usage 152 | exit 1 153 | fi 154 | 155 | # Load the configuration file and check it was loaded OK. 156 | __load_configuration_file 157 | 158 | if [ $? -ne 0 ] 159 | then 160 | echo "Configuration file was not loaded." 161 | fi 162 | 163 | echo "All tests completed OK." 164 | 165 | echo "Project name: ${PROJECT_TYPE}" 166 | echo "Initial site name: ${INITIAL_SITE_NAME}" 167 | echo "Project name: ${PROJECT_NAME}" 168 | 169 | # ------------------------------------------------------------------------------------------------- 170 | echo 171 | echo `date` 172 | echo "Make database dump file..." 173 | # ------------------------------------------------------------------------------------------------- 174 | mkdir -p ~/backups/initial_sites 175 | ##sudo mysqldump ${USER}is${INITIAL_SITE_NAME} > /home/${USER}/backups/initial_sites/${USER}is${INITIAL_SITE_NAME}_${DATE_TIME}.sql 176 | mysqldump ${USER}is${INITIAL_SITE_NAME} > /home/${USER}/backups/initial_sites/${USER}is${INITIAL_SITE_NAME}.sql 177 | ####tar --create --file=/home/${USER}/backups/initial_sites/${USER}is${INITIAL_SITE_NAME}_${DATE_TIME}.tar /home/${USER}/initial_sites/${INITIAL_SITE_NAME}/web 178 | 179 | # ------------------------------------------------------------------------------------------------- 180 | echo 181 | echo `date` 182 | echo "For Drupal sites we should clear out the caches..." 183 | # ------------------------------------------------------------------------------------------------- 184 | case "${PROJECT_TYPE}" in 185 | 186 | drupal7|drupal6) 187 | drush --root=/home/${USER}/initial_sites/${INITIAL_SITE_NAME}/web cache-clear all 188 | ;; 189 | 190 | *) 191 | echo "Error - Invalid project type." 192 | exit 1 193 | esac 194 | 195 | # ------------------------------------------------------------------------------------------------- 196 | echo 197 | echo `date` 198 | echo "Creating the database for the beta site and loading the initial database into it..." 199 | # ------------------------------------------------------------------------------------------------- 200 | 201 | DATABASE_NAME=betapr${PROJECT_NAME} 202 | DATABASE_USER=betapr${PROJECT_NAME} 203 | DATABASE_PASSWORD=`cat /dev/urandom | base64 | tr -d '[:punct:]' | tr -d '[:digit:]' | tr -d '[:upper:]' | cut -c1-10 | head -1` 204 | __create_mysql_database_and_user_account ${DATABASE_NAME} ${DATABASE_USER} ${DATABASE_PASSWORD} 205 | 206 | mysql betapr${PROJECT_NAME} < /home/${USER}/backups/initial_sites/${USER}is${INITIAL_SITE_NAME}.sql 207 | 208 | # ------------------------------------------------------------------------------------------------- 209 | echo 210 | echo `date` 211 | echo "Creating the Subversion repository for this project and import the initial files..." 212 | # ------------------------------------------------------------------------------------------------- 213 | sudo svnadmin create /var/lib/svn/${PROJECT_NAME} 214 | 215 | # We will set the ownership to www-data as we will primarily be using HTTP to access the archive. 216 | sudo chown -R www-data:www-data /var/lib/svn/${PROJECT_NAME} 217 | 218 | # Here we will put a dump of the database into the code repository. This means that the site can 219 | # be rebuilt from an export from the repository if needed. 220 | ####cp /home/${USER}/backups/initial_sites/${USER}is${INITIAL_SITE_NAME}_${DATE_TIME}.sql /home/${USER}/initial_sites/${INITIAL_SITE_NAME}/web/${USER}is${INITIAL_SITE_NAME}_${DATE_TIME}.sql 221 | 222 | svn import /home/${USER}/initial_sites/${INITIAL_SITE_NAME}/web http://localhost/svn/${PROJECT_NAME} -m "Initial import." 223 | 224 | # ------------------------------------------------------------------------------------------------- 225 | echo 226 | echo `date` 227 | echo "Checkout the files from SVN ..." 228 | # ------------------------------------------------------------------------------------------------- 229 | 230 | case "${PROJECT_TYPE}" in 231 | 232 | drupal7|drupal6) 233 | 234 | # Pull the files from the repository and remove the settings.php from SVN control. 235 | sudo -u beta -i sh -c "svn checkout http://localhost/svn/${PROJECT_NAME} /home/beta/projects/${PROJECT_NAME}/web" 236 | 237 | # Here we are going to copy the current settings.php file - which has come from the initial site - to the 238 | # default.settings.php - this then becomes the default settings file which is used as the template when 239 | # other settings.php files are needed. 240 | sudo -u beta -i sh -c "cp /home/beta/projects/${PROJECT_NAME}/web/sites/default/settings.php /home/beta/projects/${PROJECT_NAME}/web/sites/default/default.settings.php" 241 | 242 | # Remove the settings.php file from SVN control. 243 | sudo -u beta -i sh -c "svn delete --keep-local /home/beta/projects/${PROJECT_NAME}/web/sites/default/settings.php" 244 | sudo -u beta -i sh -c "svn propset svn:ignore settings.php /home/beta/projects/${PROJECT_NAME}/web/sites/default" 245 | 246 | sudo -u beta -i sh -c "svn commit -m \"Remove the settings.php file from SVN control and check in an updated default.settings.php.\" /home/beta/projects/${PROJECT_NAME}/web" 247 | #sudo -u beta -i svn commit -q /home/beta/projects/${PROJECT_NAME}/web 248 | 249 | # Here we need to run update to get the local revision number to match the new repository 250 | # revision number. This is used in checks later. 251 | sudo -u beta -i sh -c "svn update /home/beta/projects/${PROJECT_NAME}/web" 252 | 253 | if [ "${WEB_SERVER_TYPE}" = "apache2prefork" ] 254 | then 255 | echo 256 | echo `date` 257 | echo "Add the www-data user to the beta group so that the web server can write to the files/ directory..." 258 | sudo adduser --quiet www-data beta 259 | 260 | echo "Adding the beta user to the www-data group so that the beta user can manipulate the files with SVN..." 261 | sudo adduser --quiet beta www-data 262 | 263 | echo 264 | echo `date` 265 | echo "Setting permissions for the files/ directory so the web server can write to it..." 266 | sudo chmod -R 775 /home/beta/projects/${PROJECT_NAME}/web/sites/default/files 267 | fi 268 | ;; 269 | 270 | *) 271 | echo "Error - Invalid project type." 272 | exit 1 273 | esac 274 | 275 | # ------------------------------------------------------------------------------------------------- 276 | echo 277 | echo `date` 278 | echo "Update the settings.php file with the new database connections..." 279 | # ------------------------------------------------------------------------------------------------- 280 | 281 | case "${PROJECT_TYPE}" in 282 | 283 | drupal7) 284 | 285 | # We will copy the file before changing it as changing it in place gets complicated when trying to excape the sudo command. 286 | cp /home/beta/projects/${PROJECT_NAME}/web/sites/default/settings.php /home/${USER}/settings.php.betapr${PROJECT_NAME} 287 | cat <> /home/${USER}/settings.php.betapr${PROJECT_NAME} 288 | 289 | \$databases = array ( 290 | 'default' => 291 | array ( 292 | 'default' => 293 | array ( 294 | 'database' => '${DATABASE_NAME}', 295 | 'username' => '${DATABASE_USER}', 296 | 'password' => '${DATABASE_PASSWORD}', 297 | 'host' => 'localhost', 298 | 'port' => '', 299 | 'driver' => 'mysql', 300 | 'prefix' => '', 301 | ), 302 | ), 303 | ); 304 | 305 | EOFSETTINGS 306 | 307 | sudo -u beta -i sh -c "cp /home/${USER}/settings.php.betapr${PROJECT_NAME} /home/beta/projects/${PROJECT_NAME}/web/sites/default/settings.php" 308 | rm /home/${USER}/settings.php.betapr${PROJECT_NAME} 309 | ;; 310 | 311 | drupal6) 312 | 313 | # We will copy the file before changing it as changing it in place gets complicated when trying to escape the sudo command. 314 | cp /home/beta/projects/${PROJECT_NAME}/web/sites/default/settings.php /home/${USER}/settings.php.betapr${PROJECT_NAME} 315 | ## echo "\$db_url = 'mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@localhost/${DATABASE_NAME}'" >> /home/${USER}/settings.php.betapr${PROJECT_NAME} 316 | echo "\$db_url = 'mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@localhost/${DATABASE_NAME}';" >> /home/${USER}/settings.php.betapr${PROJECT_NAME} 317 | sudo -u beta -i sh -c "cp /home/${USER}/settings.php.betapr${PROJECT_NAME} /home/beta/projects/${PROJECT_NAME}/web/sites/default/settings.php" 318 | rm /home/${USER}/settings.php.betapr${PROJECT_NAME} 319 | ;; 320 | 321 | *) 322 | echo "Error - Invalid project type." 323 | exit -1 324 | esac 325 | 326 | # ------------------------------------------------------------------------------------------------- 327 | echo 328 | echo `date` 329 | echo "Here we need to set up the configuration file at /etc/pullpush/projects/..." 330 | # ------------------------------------------------------------------------------------------------- 331 | 332 | sudo mkdir -p /etc/pullpush/projects 333 | 334 | case "${PROJECT_TYPE}" in 335 | 336 | drupal7) 337 | sudo sh -c "echo PROJECT_TYPE=drupal7 > /etc/pullpush/projects/${PROJECT_NAME}.conf" 338 | sudo sh -c "echo DATABASE_PREFIX= >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 339 | sudo sh -c "echo >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 340 | sudo sh -c "echo >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 341 | sudo sh -c "echo \"# Set to PUSH_USERS=true to get the users copied from livecopy to deploy.\" >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 342 | sudo sh -c "echo \"#PUSH_USERS=\" >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 343 | sudo sh -c "echo \"# Set to PUSH_TERMS=true to get the users copied from livecopy to deploy.\" >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 344 | sudo sh -c "echo \"#PUSH_TERMS=\" >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 345 | sudo sh -c "echo \"# Set to NODES_TO_PUSH=[comma separated list of content types - no spaces] which need to be copied from livecopy to deploy.\" >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 346 | sudo sh -c "echo \"#NODES_TO_PUSH=\" >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 347 | ;; 348 | 349 | drupal6) 350 | sudo sh -c "echo PROJECT_TYPE=drupal6 > /etc/pullpush/projects/${PROJECT_NAME}.conf" 351 | sudo sh -c "echo DATABASE_PREFIX= >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 352 | sudo sh -c "echo >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 353 | sudo sh -c "echo >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 354 | sudo sh -c "echo \"# Set to PUSH_USERS=true to get the users copied from livecopy to deploy.\" >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 355 | sudo sh -c "echo \"#PUSH_USERS=\" >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 356 | sudo sh -c "echo \"# Set to PUSH_TERMS=true to get the users copied from livecopy to deploy.\" >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 357 | sudo sh -c "echo \"#PUSH_TERMS=\" >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 358 | sudo sh -c "echo \"# Set to NODES_TO_PUSH=[comma separated list of content types - no spaces] which need to be copied from livecopy to deploy.\" >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 359 | sudo sh -c "echo \"#NODES_TO_PUSH=\" >> /etc/pullpush/projects/${PROJECT_NAME}.conf" 360 | ;; 361 | 362 | *) 363 | echo "Error - Invalid project type." 364 | exit -1 365 | esac 366 | 367 | # ------------------------------------------------------------------------------------------------- 368 | echo 369 | echo `date` 370 | echo "Set up the beta vhost..." 371 | # ------------------------------------------------------------------------------------------------- 372 | 373 | # If the projects directory does not exist yet then we need to create it. 374 | ## NB - this should have been created already. 375 | ##if [ ! -e /home/beta/projects ] 376 | ##then 377 | ## sudo mkdir /home/beta/projects 378 | ## sudo chown beta:beta /home/beta/projects 379 | ##fi 380 | 381 | __set_up_vhost beta-pr-${PROJECT_NAME} /home/beta/projects/${PROJECT_NAME}/web beta 382 | 383 | 384 | # ------------------------------------------------------------------------------------------------- 385 | echo 386 | echo `date` 387 | echo "To be tidy we will clear out the caches on the new beta site..." 388 | # ------------------------------------------------------------------------------------------------- 389 | case "${PROJECT_TYPE}" in 390 | 391 | drupal7|drupal6) 392 | drush --root=/home/beta/projects/${PROJECT_NAME}/web cache-clear all 393 | ;; 394 | 395 | *) 396 | echo "Error - Invalid project type." 397 | exit 1 398 | esac 399 | 400 | # ------------------------------------------------------------------------------------------------- 401 | echo 402 | echo `date` 403 | echo "Explicitly setting the maintenance or offline mode for Drupal sites..." 404 | # ------------------------------------------------------------------------------------------------- 405 | # It looks like that in Drupal variables are not set explicitly by default. Here we will set the 406 | # maintenance/offline mode variables so they hold default values which are then read by the 407 | # pulldevfrombeta script. 408 | case "${PROJECT_TYPE}" in 409 | 410 | drupal7) 411 | 412 | drush -r /home/beta/projects/${PROJECT_NAME}/web vset maintenance_mode 0 --yes 413 | ;; 414 | 415 | drupal6) 416 | 417 | drush -r /home/beta/projects/${PROJECT_NAME}/web vset site_offline 0 --yes 418 | ;; 419 | 420 | *) 421 | echo "Error - Invalid project type." 422 | exit 1 423 | esac 424 | 425 | # ------------------------------------------------------------------------------------------------- 426 | echo 427 | echo `date` 428 | echo "Removing sudo permissions..." 429 | # ------------------------------------------------------------------------------------------------- 430 | sudo -k 431 | 432 | # ------------------------------------------------------------------------------------------------- 433 | echo 434 | echo `date` 435 | echo "Finished - the new site is at http://beta-pr-${PROJECT_NAME}.${SERVER_FQDN}" 436 | # ------------------------------------------------------------------------------------------------- 437 | 438 | exit 0 439 | 440 | 441 | -------------------------------------------------------------------------------- /pulldevfrombeta: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=================================================================================== 3 | # 4 | # FILE: pulldevfrombeta 5 | # 6 | # USAGE: pulldevfrombeta -p [project type] 7 | # 8 | # DESCRIPTION: This will pull a copy of a beta site to a dev copy. 9 | # 10 | # OPTIONS: see function ’usage’ below 11 | # NOTES: --- 12 | # AUTHOR: Kevin Bailey, kbailey@freewayprojects.com 13 | # COMPANY: Freeway Projects Limited 14 | #=================================================================================== 15 | 16 | # Make sure only one Pullpush script is running at any one time. 17 | touch /var/lock/pullpush 18 | chmod --quiet 666 /var/lock/pullpush 19 | exec 9>/var/lock/pullpush 20 | if ! flock -n 9 ; then 21 | echo "Another Pullpush script is currently running - try again later."; 22 | exit 1 23 | fi 24 | 25 | # ------------------------------------------------------------------------------------------------- 26 | # Set up global variables. 27 | # 28 | # We are going to explicitly set the script name variable. Obviously the script name is available 29 | # as $0 - but this is not consistent and may or may not contain the path. Also, this means we can 30 | # use the bash debugger without needing to handle the fact that $0 would contain something like 31 | # 'bashdb'. 32 | # ------------------------------------------------------------------------------------------------- 33 | SCRIPT_NAME=pulldevfrombeta 34 | DATE_TIME=$(date +%Y%m%d-%H%M%S) 35 | 36 | # ------------------------------------------------------------------------------------------------- 37 | # Set up the user to be able to run sudo commands - this will be revoked at the end of the script. 38 | # ------------------------------------------------------------------------------------------------- 39 | sudo -v 40 | 41 | # ------------------------------------------------------------------------------------------------- 42 | # Log all output from the script. 43 | # 44 | # As we are going to be carrying out multiple steps and it is important we can see all the output 45 | # to be able to diagnose problems. 46 | # ------------------------------------------------------------------------------------------------- 47 | 48 | # Create a place for the log files. 49 | sudo mkdir -p /var/log/pullpush 50 | sudo chmod 777 /var/log/pullpush 51 | 52 | # Create a pipe... 53 | tmppipe=$(mktemp -u) 54 | mkfifo ${tmppipe} 55 | 56 | # ...then start a tee process which takes as its input the pipe - and output to the logfile (and 57 | # standard output) and then push the tee process into the background (subshell). 58 | tee < ${tmppipe} /var/log/pullpush/${DATE_TIME}_${USER}_${SCRIPT_NAME}.log & 59 | 60 | # Redirect both standard output and standard error to the pipe just created - these outputs 61 | # will then be directed via the pipe to standard output (the current shell) and the log file. 62 | exec &> ${tmppipe} 63 | 64 | # This sets up the pipe to be removed - it will only be fully dropped when no process is using it. 65 | rm ${tmppipe} 66 | 67 | # ------------------------------------------------------------------------------------------------- 68 | # Import Pullpush functions. 69 | # ------------------------------------------------------------------------------------------------- 70 | source /usr/local/share/pullpush/pullpush_functions 71 | 72 | # ------------------------------------------------------------------------------------------------- 73 | # Local functions 74 | # 75 | # Here we will define all the functions used by this script. 76 | # ------------------------------------------------------------------------------------------------- 77 | 78 | # Output a usage message - used when the parameters input are not correct. 79 | usage () { 80 | echo "Usage: $SCRIPT_NAME -p [project name] -s [softlock (yes|no)]" 81 | } 82 | 83 | 84 | # ------------------------------------------------------------------------------------------------- 85 | # Testing parameters 86 | # ------------------------------------------------------------------------------------------------- 87 | while getopts ":p:s:" opt; do 88 | case $opt in 89 | p) 90 | PROJECT_NAME=$OPTARG 91 | ;; 92 | s) 93 | SOFTLOCK=$OPTARG 94 | ;; 95 | \?) 96 | echo "Invalid option: -$OPTARG" >&2 97 | usage 98 | exit 1 99 | ;; 100 | :) 101 | echo "Option -$OPTARG requires an argument." >&2 102 | usage 103 | exit 1 104 | ;; 105 | esac 106 | done 107 | 108 | # Check the parameter has had a value assigned. 109 | if [ -z $PROJECT_NAME ] 110 | then 111 | echo "The project name needs to be set." 112 | usage 113 | exit 1 114 | fi 115 | 116 | # Check the project exists. 117 | if [ ! -e /home/beta/projects/${PROJECT_NAME}/web ] 118 | then 119 | echo "The project does not appear to exist." 120 | usage 121 | exit 1 122 | fi 123 | 124 | # Check the softlock value has been set 125 | if [ -z $SOFTLOCK ] 126 | then 127 | echo "The softlock parameter needs to be set." 128 | usage 129 | exit 1 130 | fi 131 | 132 | if [ $SOFTLOCK != "yes" ] && [ $SOFTLOCK != "no" ] 133 | then 134 | echo "The softlock parameter needs to be set to either 'yes' or 'no'." 135 | usage 136 | exit 1 137 | fi 138 | 139 | # Load the project settings file or display an error if it does not exist. 140 | if [ -e /etc/pullpush/projects/${PROJECT_NAME}.conf ] 141 | then 142 | source /etc/pullpush/projects/${PROJECT_NAME}.conf 143 | else 144 | echo "ERROR - The project settings file /etc/pullpush/projects/${PROJECT_NAME}.conf not found." 145 | exit 1 146 | fi 147 | 148 | # Load the configuration file and check it was loaded OK. 149 | __load_configuration_file 150 | 151 | if [ $? -ne 0 ] 152 | then 153 | echo "Configuration file was not loaded." 154 | fi 155 | 156 | echo "All tests completed OK." 157 | echo "Project name: ${PROJECT_NAME}" 158 | 159 | # ------------------------------------------------------------------------------------------------- 160 | # Here we will look to see if the softlock has been set - if it has then we need to warn the user and 161 | # give them chance to cancel the pull. 162 | # ------------------------------------------------------------------------------------------------- 163 | case "${PROJECT_TYPE}" in 164 | 165 | drupal7) 166 | 167 | MAINTENANCE_MODE=$(drush --root=/home/beta/projects/${PROJECT_NAME}/web vget maintenance_mode --exact) 168 | case "${MAINTENANCE_MODE}" in 169 | 170 | "maintenance_mode: 1"|"maintenance_mode: '1'") 171 | echo "The beta site is currently in maintenance mode which indicates that a dev has pulled a copy and set the softlock." 172 | echo "You can still pull a copy of the beta site to your dev copy but if you push changes you may prevent another developer from pushing updates." 173 | 174 | read -p "Do you still want to pull a copy of beta to your dev copy (y/n)?" 175 | if [ $REPLY != "y" ]; then 176 | echo "Cancelling pull from beta..." 177 | exit 1 178 | fi 179 | echo "Continuing with the pull from beta..." 180 | ;; 181 | 182 | "maintenance_mode: 0"|"maintenance_mode: '0'") 183 | echo "The site is not in maintenance mode." 184 | ;; 185 | 186 | *) 187 | echo "WARNING - can not determine maintenance mode." 188 | # exit 1 189 | esac 190 | ;; 191 | 192 | 193 | drupal6) 194 | 195 | SITE_OFFLINE=$(drush --root=/home/beta/projects/${PROJECT_NAME}/web vget site_offline --exact) 196 | case "${SITE_OFFLINE}" in 197 | 198 | "site_offline: 1") 199 | echo "The beta site is currently in offline mode which indicates that a dev has pulled a copy and set the softlock." 200 | echo "You can still pull a copy of the beta site to your dev copy but if you push changes you may prevent another developer from pushing updates." 201 | 202 | read -p "Do you still want to pull a copy of beta to your dev copy (y/n)?" 203 | if [ $REPLY != "y" ]; then 204 | echo "Cancelling pull from beta..." 205 | exit 1 206 | fi 207 | echo "Continuing with the pull from beta..." 208 | ;; 209 | 210 | "site_offline: 0") 211 | echo "The site is not in offline mode." 212 | ;; 213 | 214 | *) 215 | echo "ERROR - can not determine maintenance mode." 216 | exit 1 217 | esac 218 | ;; 219 | 220 | *) 221 | echo "Error - Invalid project type." 222 | exit 1 223 | esac 224 | 225 | # ------------------------------------------------------------------------------------------------- 226 | echo 227 | echo `date` 228 | echo "Before working with the beta site we will clear out the caches..." 229 | # ------------------------------------------------------------------------------------------------- 230 | case "${PROJECT_TYPE}" in 231 | 232 | drupal7|drupal6) 233 | drush --root=/home/beta/projects/${PROJECT_NAME}/web cache-clear all 234 | ;; 235 | 236 | *) 237 | echo "Error - Invalid project type." 238 | exit 1 239 | esac 240 | 241 | # ------------------------------------------------------------------------------------------------- 242 | echo 243 | echo `date` 244 | echo "Make backup copy of the beta site database..." 245 | # ------------------------------------------------------------------------------------------------- 246 | mkdir -p /home/${USER}/backups/beta_sites 247 | mysqldump betapr${PROJECT_NAME} > /home/${USER}/backups/beta_sites/${PROJECT_NAME}.sql 248 | ##tar --create --file=/home/${USER}/backups/beta_sites/${PROJECT_NAME}_${DATE_TIME}.tar /home/beta/projects/${PROJECT_NAME}/web 249 | 250 | # ------------------------------------------------------------------------------------------------- 251 | echo 252 | echo `date` 253 | echo "Here we will set or unset the softlock ..." 254 | # ------------------------------------------------------------------------------------------------- 255 | case "${PROJECT_TYPE}" in 256 | 257 | drupal7) 258 | 259 | case "${SOFTLOCK}" in 260 | 261 | yes) 262 | echo "The softlock is being turned on..." 263 | drush -r /home/beta/projects/${PROJECT_NAME}/web vset maintenance_mode 1 --yes 264 | ;; 265 | 266 | no) 267 | echo "The softlock is being turned off..." 268 | drush -r /home/beta/projects/${PROJECT_NAME}/web vset maintenance_mode 0 --yes 269 | ;; 270 | 271 | *) 272 | echo "Error - Invalid softlock choice." 273 | exit 1 274 | esac 275 | ;; 276 | 277 | drupal6) 278 | 279 | case "${SOFTLOCK}" in 280 | 281 | yes) 282 | echo "The softlock is being turned on..." 283 | drush -r /home/beta/projects/${PROJECT_NAME}/web vset site_offline 1 --yes 284 | ;; 285 | 286 | no) 287 | echo "The softlock is being turned off..." 288 | drush -r /home/beta/projects/${PROJECT_NAME}/web vset site_offline 0 --yes 289 | ;; 290 | 291 | *) 292 | echo "Error - Invalid softlock choice." 293 | exit 1 294 | esac 295 | ;; 296 | 297 | *) 298 | echo "Error - Invalid project type." 299 | exit 1 300 | esac 301 | 302 | # ------------------------------------------------------------------------------------------------- 303 | echo 304 | echo `date` 305 | echo "Checking if the dev site exists - if not then it will be created as a copy of beta ..." 306 | # ------------------------------------------------------------------------------------------------- 307 | if [ ! -e /home/${USER}/projects/${PROJECT_NAME}/web ] 308 | then 309 | # In this block we are going to: 310 | # 1. Check beta files into SVN 311 | # 312 | # 1. Create a DB for the dev site. 313 | # 2. Load the database from the beta database backup. 314 | # 3. Checkout files from SVN. 315 | # 4. Update settings.php with the database settings. 316 | # 5. Set up vhost 317 | 318 | echo "The dev site does not exist so it is being created..." 319 | 320 | echo "Checking the beta site files into SVN..." 321 | __check_beta_files_into_svn 322 | 323 | echo "Creating database..." 324 | DATABASE_NAME=${USER}pr${PROJECT_NAME} 325 | DATABASE_USER=${USER}pr${PROJECT_NAME} 326 | DATABASE_PASSWORD=`cat /dev/urandom | base64 | tr -d '[:punct:]' | tr -d '[:digit:]' | tr -d '[:upper:]' | cut -c1-10 | head -1` 327 | __create_mysql_database_and_user_account ${DATABASE_NAME} ${DATABASE_USER} ${DATABASE_PASSWORD} 328 | 329 | echo "Loading the database from the beta database backup..." 330 | mysql ${USER}pr${PROJECT_NAME} < /home/${USER}/backups/beta_sites/${PROJECT_NAME}.sql 331 | 332 | echo "Checking out the files from SVN to the new dev site..." 333 | svn checkout http://localhost/svn/${PROJECT_NAME} /home/${USER}/projects/${PROJECT_NAME}/web 334 | 335 | if [ "${WEB_SERVER_TYPE}" = "apache2prefork" ] 336 | then 337 | echo 338 | echo `date` 339 | echo "Add the www-data user to the developers group so that the web server can write to the files/ directory..." 340 | sudo adduser --quiet www-data ${USER} 341 | 342 | echo "Adding the dev user to the www-data group so that the dev user can manipulate the files with SVN..." 343 | sudo adduser --quiet ${USER} www-data 344 | 345 | echo 346 | echo `date` 347 | echo "Setting permissions for the files/ directory so the web server can write to it..." 348 | sudo chmod -R 775 /home/${USER}/projects/${PROJECT_NAME}/web/sites/default/files 349 | fi 350 | 351 | echo "Update settings.php with the database settings..." 352 | # NB - We are going to base the settings file on default.settings.php. Any modifications to the 353 | # settings.php file which are not database settings should be applied to the default.settings.php 354 | # file so that other developers get the same base settings.php. 355 | cp /home/${USER}/projects/${PROJECT_NAME}/web/sites/default/default.settings.php /home/${USER}/projects/${PROJECT_NAME}/web/sites/default/settings.php 356 | 357 | case "${PROJECT_TYPE}" in 358 | 359 | drupal7) 360 | 361 | cat <> /home/${USER}/projects/${PROJECT_NAME}/web/sites/default/settings.php 362 | 363 | \$databases = array ( 364 | 'default' => 365 | array ( 366 | 'default' => 367 | array ( 368 | 'database' => '${DATABASE_NAME}', 369 | 'username' => '${DATABASE_USER}', 370 | 'password' => '${DATABASE_PASSWORD}', 371 | 'host' => 'localhost', 372 | 'port' => '', 373 | 'driver' => 'mysql', 374 | 'prefix' => '${DATABASE_PREFIX}', 375 | ), 376 | ), 377 | ); 378 | 379 | EOFSETTINGS 380 | 381 | ;; 382 | 383 | drupal6) 384 | 385 | echo "\$db_url = 'mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@localhost/${DATABASE_NAME}';" >> /home/${USER}/projects/${PROJECT_NAME}/web/sites/default/settings.php 386 | ;; 387 | 388 | *) 389 | echo "Error - Invalid project type." 390 | exit 1 391 | esac 392 | 393 | echo "Setting up the vhost..." 394 | __set_up_vhost ${USER}-pr-${PROJECT_NAME} /home/${USER}/projects/${PROJECT_NAME}/web ${USER} 395 | 396 | else 397 | echo "The dev copy of the site already exists so we will update it..." 398 | 399 | # Before first we will check beta files into SVN. 400 | # First we will revert the files. 401 | # Then we will update the files from the repository. 402 | # Then we will overwrite the developer database with the beta database. 403 | 404 | echo "Checking the beta site files into SVN..." 405 | __check_beta_files_into_svn 406 | 407 | echo "Reverting the current dev files to to latest revision in the SVN repository..." 408 | # Todo - Maybe here we can clear out any cache/temp files. 409 | # Todo - Maybe before reverting we could maybe rename modified files. 410 | 411 | # Here we are going to revert all local files so we can update from SVN without conflicts. 412 | 413 | # NB - RE deleted directories 414 | # 'svn revert' will not revert deleted directories - but if there are any deleted directories then 415 | # they should show up in the 'svn status' output check which is run next. They should show if they 416 | # were deleted using rmdir or via 'svn delete'. 417 | svn revert --recursive /home/${USER}/projects/${PROJECT_NAME}/web 418 | 419 | # We are going to check the current svn status of the local dev repository. 420 | # Due to the revert command which has just been run there sould be no modified files. 421 | 422 | # Here we are removing any extra files. Errors may be caused if users have added files to beta which 423 | # have the same name as any files which are being added by the developer - so it is necessary to remove 424 | # the files from the developers copy before pulling down the new beta files. 425 | svn status /home/${USER}/projects/${PROJECT_NAME}/web | grep "^?" | sed s/^?// | sed s/[[:space:]]*// | xargs -r -d '\n' rm -r 426 | 427 | # The --quiet option tells 'svn status' to not output names of files which are not under 428 | # version control. 429 | dev_svn_status=$(svn --quiet status /home/${USER}/projects/${PROJECT_NAME}/web) 430 | 431 | # If there was any output then we want to stop the script so the user can check changes. 432 | if [ -n "$dev_svn_status" ] 433 | then 434 | echo "There are modified files/directories in your dev version which have not been reverted - run 'svn status' and check the modified files." 435 | exit 0 436 | fi 437 | 438 | 439 | # ------------------------------------------------------------------------------------------------- 440 | echo 441 | echo `date` 442 | echo "Checkout latest SVN files to dev..." 443 | # ------------------------------------------------------------------------------------------------- 444 | # This gets the dev files to be a match for what is in the repository which has just been updated 445 | # with the files from beta. There may be some local files which are not in SVN and certain other 446 | # files such as settings.php and some cache files which may be different on local as well. 447 | svn update /home/${USER}/projects/${PROJECT_NAME}/web 448 | 449 | # SVN pulls the files out with standard ownership and permissions - for Apache Prefork we need 450 | # to set the permissions to allow the web server to work with the files/ directory. 451 | if [ "${WEB_SERVER_TYPE}" = "apache2prefork" ] 452 | then 453 | echo 454 | echo `date` 455 | echo "Add the www-data user to the developers group so that the web server can write to the files/ directory..." 456 | sudo adduser --quiet www-data ${USER} 457 | 458 | echo "Adding the dev user to the www-data group so that the dev user can manipulate the files with SVN..." 459 | sudo adduser --quiet ${USER} www-data 460 | 461 | echo 462 | echo `date` 463 | echo "Setting permissions for the files/ directory so the web server can write to it..." 464 | sudo chmod -R 775 /home/${USER}/projects/${PROJECT_NAME}/web/sites/default/files 465 | fi 466 | 467 | echo "Copy beta database on to dev..." 468 | mysqladmin --force drop ${USER}pr${PROJECT_NAME} 469 | mysqladmin create ${USER}pr${PROJECT_NAME} 470 | mysql ${USER}pr${PROJECT_NAME} < /home/${USER}/backups/beta_sites/${PROJECT_NAME}.sql 471 | 472 | fi 473 | 474 | # ------------------------------------------------------------------------------------------------- 475 | echo 476 | echo `date` 477 | echo "Here we will clear out caches - this avoids issues and keeps the sizes down..." 478 | # ------------------------------------------------------------------------------------------------- 479 | case "${PROJECT_TYPE}" in 480 | 481 | drupal7|drupal6) 482 | drush --root=/home/beta/projects/${PROJECT_NAME}/web cache-clear all 483 | drush --root=/home/${USER}/projects/${PROJECT_NAME}/web cache-clear all 484 | ;; 485 | 486 | *) 487 | echo "Error - Invalid project type." 488 | exit 1 489 | esac 490 | 491 | # ------------------------------------------------------------------------------------------------- 492 | echo 493 | echo `date` 494 | echo "Removing sudo permissions..." 495 | # ------------------------------------------------------------------------------------------------- 496 | sudo -k 497 | 498 | # ------------------------------------------------------------------------------------------------- 499 | echo 500 | echo `date` 501 | echo "Finished - the developer copy of the site is at http://${USER}-pr-${PROJECT_NAME}.${SERVER_FQDN}" 502 | # ------------------------------------------------------------------------------------------------- 503 | 504 | exit 0 505 | -------------------------------------------------------------------------------- /pushlivecopydataintodeploy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=================================================================================== 3 | # 4 | # FILE: pushlivecopydataintodeploy 5 | # 6 | # USAGE: pushlivecopydataintodeploy -p [project type] 7 | # 8 | # DESCRIPTION: This will push the data from the live copy into the deploy site. 9 | # 10 | # OPTIONS: see function ’usage’ below 11 | # NOTES: --- 12 | # AUTHOR: Kevin Bailey, kbailey@freewayprojects.com 13 | # COMPANY: Freeway Projects Limited 14 | #=================================================================================== 15 | 16 | # Make sure only one Pullpush script is running at any one time. 17 | touch /var/lock/pullpush 18 | chmod --quiet 666 /var/lock/pullpush 19 | exec 9>/var/lock/pullpush 20 | if ! flock -n 9 ; then 21 | echo "Another Pullpush script is currently running - try again later."; 22 | exit 1 23 | fi 24 | 25 | # ------------------------------------------------------------------------------------------------- 26 | # Set up global variables. 27 | # 28 | # We are going to explicitly set the script name variable. Obviously the script name is available 29 | # as $0 - but this is not consistent and may or may not contain the path. Also, this means we can 30 | # use the bash debugger without needing to handle the fact that $0 would contain something like 31 | # 'bashdb'. 32 | # ------------------------------------------------------------------------------------------------- 33 | SCRIPT_NAME=pushlivecopydataintodeploy 34 | DATE_TIME=$(date +%Y%m%d-%H%M%S) 35 | 36 | # ------------------------------------------------------------------------------------------------- 37 | # Set up the user to be able to run sudo commands - this will be revoked at the end of the script. 38 | # ------------------------------------------------------------------------------------------------- 39 | sudo -v 40 | 41 | # ------------------------------------------------------------------------------------------------- 42 | # Log all output from the script. 43 | # 44 | # As we are going to be carrying out multiple steps and it is important we can see all the output 45 | # to be able to diagnose problems. 46 | # ------------------------------------------------------------------------------------------------- 47 | 48 | # Create a place for the log files. 49 | sudo mkdir -p /var/log/pullpush 50 | sudo chmod 777 /var/log/pullpush 51 | 52 | # Create a pipe... 53 | tmppipe=$(mktemp -u) 54 | mkfifo ${tmppipe} 55 | 56 | # ...then start a tee process which takes as its input the pipe - and output to the logfile (and 57 | # standard output) and then push the tee process into the background (subshell). 58 | tee < ${tmppipe} /var/log/pullpush/${DATE_TIME}_${USER}_${SCRIPT_NAME}.log & 59 | 60 | # Redirect both standard output and standard error to the pipe just created - these outputs 61 | # will then be directed via the pipe to standard output (the current shell) and the log file. 62 | exec &> ${tmppipe} 63 | 64 | # This sets up the pipe to be removed - it will only be fully dropped when no process is using it. 65 | rm ${tmppipe} 66 | 67 | # ------------------------------------------------------------------------------------------------- 68 | # Import Pullpush functions. 69 | # ------------------------------------------------------------------------------------------------- 70 | source /usr/local/share/pullpush/pullpush_functions 71 | 72 | # ------------------------------------------------------------------------------------------------- 73 | # Local functions 74 | # 75 | # Here we will define all the functions used by this script. 76 | # ------------------------------------------------------------------------------------------------- 77 | 78 | # Output a usage message - used when the parameters input are not correct. 79 | usage () { 80 | echo "Usage: $SCRIPT_NAME -p [project name]" 81 | } 82 | 83 | # ------------------------------------------------------------------------------------------------- 84 | # Testing parameters 85 | # ------------------------------------------------------------------------------------------------- 86 | while getopts ":p:" opt; do 87 | case $opt in 88 | p) 89 | PROJECT_NAME=$OPTARG 90 | ;; 91 | \?) 92 | echo "Invalid option: -$OPTARG" >&2 93 | usage 94 | exit 1 95 | ;; 96 | :) 97 | echo "Option -$OPTARG requires an argument." >&2 98 | usage 99 | exit 1 100 | ;; 101 | esac 102 | done 103 | 104 | # Check the parameter has had a value assigned. 105 | #if [ -z $PROJECT_NAME ] 106 | #then 107 | # echo "The project name needs to be set." 108 | # usage 109 | # exit 1 110 | #fi 111 | 112 | # Check the project exists. 113 | if [ ! -e /home/beta/projects/${PROJECT_NAME}/web ] 114 | then 115 | echo "The project does not appear to exist." 116 | usage 117 | exit 1 118 | fi 119 | 120 | # Load the project settings file or display an error if it does not exist. 121 | if [ -e /etc/pullpush/projects/${PROJECT_NAME}.conf ] 122 | then 123 | source /etc/pullpush/projects/${PROJECT_NAME}.conf 124 | else 125 | echo "ERROR - The project settings file /etc/pullpush/projects/${PROJECT_NAME}.conf not found." 126 | exit 1 127 | fi 128 | 129 | # Load the configuration file and check it was loaded OK. 130 | __load_configuration_file 131 | 132 | if [ $? -ne 0 ] 133 | then 134 | echo "Configuration file was not loaded." 135 | fi 136 | 137 | echo "All tests completed OK." 138 | echo "Project name: ${PROJECT_NAME}" 139 | 140 | echo 141 | echo "Picked up from the project conf file..." 142 | echo "PUSH_USERS: $PUSH_USERS" 143 | echo "PUSH_TERMS: $PUSH_TERMS" 144 | echo "NODES_TO_PUSH: $NODES_TO_PUSH" 145 | 146 | # ------------------------------------------------------------------------------------------------- 147 | echo 148 | echo `date` 149 | echo "Checking in case there is not data set to be pushed from livecopy to data..." 150 | # ------------------------------------------------------------------------------------------------- 151 | ##if [ ! ${PUSH_USERS} ] && [ ! ${PUSH_TERMS} ] && [ ${NODES_TO_PUSH}=="" ] 152 | ##if [[ ${PUSH_USERS} != "true" ]] && [[ ${PUSH_TERMS} != "true" ]] && [[ ${NODES_TO_PUSH} == "" ]] 153 | if [[ ( ${PUSH_USERS} != "true" ) && ( ${PUSH_TERMS} != "true" ) && ( ${NODES_TO_PUSH} == "" ) ]] 154 | then 155 | 156 | echo "WARNING - There currently the project configuration file is set to not push any data from livecopy to deploy." 157 | echo "To set data which should be pushed look at the contents of /etc/pullpush/projects/${PROJECT_NAME}.conf" 158 | exit 1 159 | 160 | fi 161 | 162 | echo "jumped test" 163 | 164 | 165 | case "${PROJECT_TYPE}" in 166 | 167 | drupal7|drupal6) 168 | 169 | echo "Adding or updating the data_export_import module to the livecopysite..." 170 | # We are going to remove then re-install the module to avoid prompts and to make sure we have the latest version. 171 | sudo -u livecopy -i sh -c "drush --root=/home/livecopy/projects/${PROJECT_NAME}/web --yes pm-disable data_export_import" 172 | sudo -u livecopy -i sh -c "drush --root=/home/livecopy/projects/${PROJECT_NAME}/web --yes pm-uninstall data_export_import" 173 | sudo -u livecopy -i sh -c "rm -r /home/livecopy/projects/${PROJECT_NAME}/web/sites/all/modules/data_export_import" 174 | sudo -u livecopy -i sh -c "drush --root=/home/livecopy/projects/${PROJECT_NAME}/web pm-download data_export_import" 175 | sudo -u livecopy -i sh -c "drush --root=/home/livecopy/projects/${PROJECT_NAME}/web --yes pm-enable data_export_import" 176 | 177 | echo "Adding the data_export_import module to the deploy..." 178 | # We are going to remove then re-install the module to avoid prompts and to make sure we have the latest version. 179 | sudo -u deploy -i sh -c "drush --root=/home/deploy/projects/${PROJECT_NAME}/web --yes pm-disable data_export_import" 180 | sudo -u deploy -i sh -c "drush --root=/home/deploy/projects/${PROJECT_NAME}/web --yes pm-uninstall data_export_import" 181 | sudo -u deploy -i sh -c "rm -r /home/deploy/projects/${PROJECT_NAME}/web/sites/all/modules/data_export_import" 182 | sudo -u deploy -i sh -c "drush --root=/home/deploy/projects/${PROJECT_NAME}/web pm-download data_export_import" 183 | sudo -u deploy -i sh -c "drush --root=/home/deploy/projects/${PROJECT_NAME}/web --yes pm-enable data_export_import" 184 | 185 | if [[ ${PUSH_USERS} == "true" ]] 186 | then 187 | echo "Pushing users from livecopy to deploy..." 188 | # ------------------------------------------------------------------------------------------------- 189 | echo 190 | echo `date` 191 | echo "Copy the users across..." 192 | # ------------------------------------------------------------------------------------------------- 193 | ##USER_FILE_PRODUCED=$(ssh livecopy@localhost "drush ${LIVECOPY_DRUSH_ALIAS} dei-ex users") 194 | ###USER_FILE_PRODUCED=$(sudo -u livecopy -i drush --root=/home/livecopy/projects/${PROJECT_NAME}/web dei-ex users) 195 | USER_FILE_PRODUCED=$(sudo -u livecopy -i sh -c "drush --root=/home/livecopy/projects/${PROJECT_NAME}/web dei-ex users") 196 | 197 | echo "USER_FILE_PRODUCED:${USER_FILE_PRODUCED}" 198 | 199 | 200 | #ssh deploy@localhost "mkdir -p ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users" 201 | #ssh deploy@localhost "cp ${LIVECOPY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users/${USER_FILE_PRODUCED} ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users/${FILENAME}" 202 | #ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im users --file=${USER_FILE_PRODUCED}" 203 | 204 | sudo -u deploy -i sh -c "mkdir -p /home/deploy/projects/${PROJECT_NAME}/web/sites/default/files/data_export_import/users" 205 | sudo -u deploy -i sh -c "cp /home/livecopy/projects/${PROJECT_NAME}/web/sites/default/files/data_export_import/users/${USER_FILE_PRODUCED} /home/deploy/projects/${PROJECT_NAME}/web/sites/default/files/data_export_import/users/${USER_FILE_PRODUCED}" 206 | ##ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im users --file=${USER_FILE_PRODUCED}" 207 | sudo -u deploy -i sh -c "drush --root=/home/deploy/projects/${PROJECT_NAME}/web dei-im users --file=${USER_FILE_PRODUCED}" 208 | 209 | 210 | fi 211 | 212 | 213 | if [[ ${PUSH_TERMS} == "true" ]] 214 | then 215 | echo "Pushing terms from livecopy to deploy..." 216 | 217 | # ------------------------------------------------------------------------------------------------- 218 | echo 219 | echo `date` 220 | echo "Copy the terms across..." 221 | # ------------------------------------------------------------------------------------------------- 222 | ##USER_FILE_PRODUCED=$(ssh livecopy@localhost "drush ${LIVECOPY_DRUSH_ALIAS} dei-ex users") 223 | ###TERM_FILE_PRODUCED=$(sudo -u livecopy drush --root=/home/livecopy/projects/${PROJECT_NAME}/web dei-ex terms) 224 | TERM_FILE_PRODUCED=$(sudo -u livecopy -i sh -c "drush --root=/home/livecopy/projects/${PROJECT_NAME}/web dei-ex terms") 225 | 226 | echo "TERM_FILE_PRODUCED:${TERM_FILE_PRODUCED}" 227 | 228 | 229 | #ssh deploy@localhost "mkdir -p ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users" 230 | #ssh deploy@localhost "cp ${LIVECOPY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users/${USER_FILE_PRODUCED} ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users/${FILENAME}" 231 | #ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im users --file=${USER_FILE_PRODUCED}" 232 | 233 | sudo -u deploy -i sh -c "mkdir -p /home/deploy/projects/${PROJECT_NAME}/web/sites/default/files/data_export_import/taxonomy_terms" 234 | sudo -u deploy -i sh -c "cp /home/livecopy/projects/${PROJECT_NAME}/web/sites/default/files/data_export_import/taxonomy_terms/${TERM_FILE_PRODUCED} /home/deploy/projects/${PROJECT_NAME}/web/sites/default/files/data_export_import/taxonomy_terms/${TERM_FILE_PRODUCED}" 235 | ##ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im users --file=${USER_FILE_PRODUCED}" 236 | sudo -u deploy -i sh -c "drush --root=/home/deploy/projects/${PROJECT_NAME}/web dei-im terms --file=${TERM_FILE_PRODUCED}" 237 | 238 | 239 | 240 | fi 241 | 242 | 243 | if [[ ${NODES_TO_PUSH} != "" ]] 244 | then 245 | 246 | # ------------------------------------------------------------------------------------------------- 247 | echo 248 | echo `date` 249 | echo "Copy the nodes across..." 250 | # ------------------------------------------------------------------------------------------------- 251 | ##ssh livecopy@localhost "drush @livecopy_${PROJECT_NAME} dei-ex nodes --content-types=${NODE_CONTENT_TYPES}" > files.txt 252 | 253 | 254 | ##FILES_PRODUCED=$(ssh livecopy@localhost "drush ${LIVECOPY_DRUSH_ALIAS} dei-ex nodes --content-types=${NODE_CONTENT_TYPES}") 255 | ###FILES_PRODUCED=$(sudo -u livecopy drush --root=/home/livecopy/projects/${PROJECT_NAME}/web dei-ex nodes --content-types=${NODES_TO_PUSH}) 256 | FILES_PRODUCED=$(sudo -u livecopy -i sh -c "drush --root=/home/livecopy/projects/${PROJECT_NAME}/web dei-ex nodes --content-types=${NODES_TO_PUSH}") 257 | 258 | 259 | 260 | echo "FILES_PRODUCED:${FILES_PRODUCED}" 261 | 262 | 263 | 264 | for FILENAME in $FILES_PRODUCED 265 | do 266 | echo "File being imported:${FILENAME}" 267 | 268 | # ssh deploy@localhost "mkdir -p ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/nodes" 269 | # ssh deploy@localhost "cp ${LIVECOPY_DOCUMENT_ROOT}/sites/default/files/data_export_import/nodes/${FILENAME} ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/nodes/${FILENAME}" 270 | # ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im nodes --file=${FILENAME}" 271 | 272 | sudo -u deploy -i sh -c "mkdir -p /home/deploy/projects/${PROJECT_NAME}/web/sites/default/files/data_export_import/nodes" 273 | sudo -u deploy -i sh -c "cp /home/livecopy/projects/${PROJECT_NAME}/web/sites/default/files/data_export_import/nodes/${FILENAME} /home/deploy/projects/${PROJECT_NAME}/web/sites/default/files/data_export_import/nodes/${FILENAME}" 274 | sudo -u deploy -i sh -c "drush --root=/home/deploy/projects/${PROJECT_NAME}/web dei-im nodes --file=${FILENAME}" 275 | 276 | done 277 | fi 278 | ;; 279 | 280 | *) 281 | echo "Error - Invalid project type." 282 | exit 1 283 | esac 284 | 285 | exit 0 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | exit 0 294 | 295 | 296 | # ------------------------------------------------------------------------------------------------- 297 | # The plan. 298 | # 299 | # For Drupal: 300 | # Install data_export_import module to both deploy and livecopy sites. 301 | # Copy users (if needed) 302 | # Copy terms (if needed) 303 | # Copy nodes (if needed) 304 | # ------------------------------------------------------------------------------------------------- 305 | 306 | case "${PROJECT_TYPE}" in 307 | 308 | drupal7|drupal6) 309 | 310 | echo "Adding the data_export_import module to the livecopysite..." 311 | sudo -u livecopy -i drush --root=/home/livecopy/projects/${PROJECT_NAME}/web pm-download data_export_import 312 | sudo -u livecopy -i drush --root=/home/livecopy/projects/${PROJECT_NAME}/web --yes pm-enable data_export_import 313 | 314 | echo "Adding the data_export_import module to the deploy..." 315 | sudo -u deploy -i drush --root=/home/deploy/web/${PROJECT_NAME} pm-download data_export_import 316 | sudo -u deploy -i drush --root=/home/deploy/web/${PROJECT_NAME} --yes pm-enable data_export_import 317 | 318 | 319 | exit 0 320 | 321 | # ------------------------------------------------------------------------------------------------- 322 | echo 323 | echo `date` 324 | echo "Copy the users across..." 325 | # ------------------------------------------------------------------------------------------------- 326 | ##USER_FILE_PRODUCED=$(ssh livecopy@localhost "drush ${LIVECOPY_DRUSH_ALIAS} dei-ex users") 327 | USER_FILE_PRODUCED=$(sudo -u livecopy -i drush --root=/home/livecopy/projects/${PROJECT_NAME}/web dei-ex users) 328 | 329 | echo "USER_FILE_PRODUCED:${USER_FILE_PRODUCED}" 330 | 331 | 332 | #ssh deploy@localhost "mkdir -p ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users" 333 | #ssh deploy@localhost "cp ${LIVECOPY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users/${USER_FILE_PRODUCED} ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users/${FILENAME}" 334 | #ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im users --file=${USER_FILE_PRODUCED}" 335 | 336 | sudo -u deploy -i mkdir -p /home/deploy/projects/${PROJECT_NAME}/web/sites/default/files/data_export_import/users 337 | sudo -u deploy -i cp /home/livecopy/projects/${PROJECT_NAME}/web/sites/default/files/data_export_import/users/${USER_FILE_PRODUCED} /home/deploy/projects/${PROJECT_NAME}/web/sites/default/files/data_export_import/users/${USER_FILE_PRODUCED} 338 | ##ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im users --file=${USER_FILE_PRODUCED}" 339 | sudo -u deploy -i drush --root=/home/deploy/projects/${PROJECT_NAME}/web dei-im users --file=${USER_FILE_PRODUCED} 340 | 341 | # HERE HERE HERE. 342 | # ------------------------------------------------------------------------------------------------- 343 | echo 344 | echo `date` 345 | echo "Copy the terms across..." 346 | # ------------------------------------------------------------------------------------------------- 347 | ##USER_FILE_PRODUCED=$(ssh livecopy@localhost "drush ${LIVECOPY_DRUSH_ALIAS} dei-ex users") 348 | TERM_FILE_PRODUCED=$(sudo -u livecopy drush --root=/home/livecopy/web/${PROJECT_NAME} dei-ex terms) 349 | 350 | echo "TERM_FILE_PRODUCED:${TERM_FILE_PRODUCED}" 351 | 352 | 353 | #ssh deploy@localhost "mkdir -p ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users" 354 | #ssh deploy@localhost "cp ${LIVECOPY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users/${USER_FILE_PRODUCED} ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users/${FILENAME}" 355 | #ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im users --file=${USER_FILE_PRODUCED}" 356 | 357 | sudo -u deploy mkdir -p /home/deploy/web/${PROJECT_NAME}/sites/default/files/data_export_import/taxonomy_terms 358 | sudo -u deploy cp /home/livecopy/web/${PROJECT_NAME}/sites/default/files/data_export_import/taxonomy_terms/${TERM_FILE_PRODUCED} /home/deploy/web/${PROJECT_NAME}/sites/default/files/data_export_import/taxonomy_terms/${TERM_FILE_PRODUCED} 359 | ##ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im users --file=${USER_FILE_PRODUCED}" 360 | sudo -u deploy drush --root=/home/deploy/web/${PROJECT_NAME} dei-im terms --file=${TERM_FILE_PRODUCED} 361 | 362 | 363 | 364 | # ------------------------------------------------------------------------------------------------- 365 | echo 366 | echo `date` 367 | echo "Copy the nodes across..." 368 | # ------------------------------------------------------------------------------------------------- 369 | ##ssh livecopy@localhost "drush @livecopy_${PROJECT_NAME} dei-ex nodes --content-types=${NODE_CONTENT_TYPES}" > files.txt 370 | 371 | 372 | ##FILES_PRODUCED=$(ssh livecopy@localhost "drush ${LIVECOPY_DRUSH_ALIAS} dei-ex nodes --content-types=${NODE_CONTENT_TYPES}") 373 | FILES_PRODUCED=$(sudo -u livecopy drush --root=/home/livecopy/web/${PROJECT_NAME} dei-ex nodes --content-types=${CONTENT_TYPES}) 374 | 375 | 376 | 377 | echo "FILES_PRODUCED:${FILES_PRODUCED}" 378 | 379 | 380 | 381 | for FILENAME in $FILES_PRODUCED 382 | do 383 | echo "File being imported:${FILENAME}" 384 | 385 | # ssh deploy@localhost "mkdir -p ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/nodes" 386 | # ssh deploy@localhost "cp ${LIVECOPY_DOCUMENT_ROOT}/sites/default/files/data_export_import/nodes/${FILENAME} ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/nodes/${FILENAME}" 387 | # ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im nodes --file=${FILENAME}" 388 | 389 | sudo -u deploy mkdir -p /home/deploy/web/${PROJECT_NAME}/sites/default/files/data_export_import/nodes 390 | sudo -u deploy cp /home/livecopy/web/${PROJECT_NAME}/sites/default/files/data_export_import/nodes/${FILENAME} /home/deploy/web/${PROJECT_NAME}/sites/default/files/data_export_import/nodes/${FILENAME} 391 | sudo -u deploy drush --root=/home/deploy/web/${PROJECT_NAME} dei-im nodes --file=${FILENAME} 392 | 393 | done 394 | 395 | 396 | 397 | 398 | 399 | 400 | ;; 401 | 402 | *) 403 | echo "Error - Invalid project type." 404 | exit 1 405 | esac 406 | 407 | 408 | 409 | exit 0 410 | 411 | 412 | 413 | 414 | # pushlivecopydataintodeploy 415 | # Push livecopy data into deploy 416 | 417 | # --------------------------------------------------------------------------------------------------- 418 | # Script which will export the data from the livecopy site and import that data into the deploy site. 419 | # --------------------------------------------------------------------------------------------------- 420 | 421 | # ------------------------------------------------------------------------------------------------- 422 | # Logging setup 423 | # ------------------------------------------------------------------------------------------------- 424 | 425 | # These lines have been copied from http://stackoverflow.com/questions/3173131/redirect-copy-of-stdout-to-log-file-from-within-bash-script-itself 426 | # and will send the script output to a log file. 427 | mkdir -p ~/logs/pullpush 428 | DATE_TIME=`date +%Y%m%d-%H%M%S` 429 | logfile=~/logs/pullpush/pushlivecopydataintodeploy_${DATE_TIME}.log 430 | mkfifo ${logfile}.pipe 431 | tee < ${logfile}.pipe $logfile & 432 | exec &> ${logfile}.pipe 433 | rm ${logfile}.pipe 434 | 435 | # ------------------------------------------------------------------------------------------------- 436 | # We are going to bring in a parameter which will be used to pull in a file containing values for 437 | # variables - this is to prevent users accidentally using someone elses databases and web space. 438 | # ------------------------------------------------------------------------------------------------- 439 | 440 | : <<'QWERTY' 441 | 442 | 443 | 444 | echo 445 | echo `date` 446 | echo "Testing for argument..." 447 | if [ $1 ] 448 | then 449 | echo "Project argument supplied OK as $1" 450 | echo 451 | else 452 | echo "ERROR - No argument supplied" 453 | exit -1 454 | fi 455 | 456 | # Check the variables file exists. 457 | if [ -e ~/.pullpush/${1} ] 458 | then 459 | source ~/.pullpush/$1 460 | else 461 | echo "ERROR - Configuration file $1 not found." 462 | exit -1 463 | fi 464 | 465 | # Check the global settings file exists. 466 | if [ -e /home/pullpush/.pullpush/projects/${1} ] 467 | then 468 | source /home/pullpush/.pullpush/projects/${1} 469 | else 470 | echo "ERROR - Global configuration file $1 not found." 471 | exit -1 472 | fi 473 | 474 | DATE_TIME=`date +%Y%m%d-%H%M%S` 475 | 476 | 477 | # Pull in any Subtype files which means that the fucntions in those 478 | # files will be available. 479 | 480 | 481 | for SUBTYPE in $PROJECT_SUBTYPES 482 | do 483 | echo 484 | echo "SUBTYPE:" 485 | echo "$SUBTYPE" 486 | 487 | source /home/pullpush/project_subtypes/${PROJECT_TYPE}/${SUBTYPE} 488 | 489 | 490 | done 491 | 492 | 493 | for SUBTYPE in $PROJECT_SUBTYPES 494 | do 495 | 496 | if [ "$SUBTYPE" = "icms" ] 497 | then 498 | 499 | echo 500 | echo "we will run the function" 501 | transfer_icms_data 502 | 503 | fi 504 | 505 | 506 | done 507 | 508 | QWERTY 509 | 510 | 511 | echo 512 | echo `date` 513 | echo "Testing for argument which should be the project name..." 514 | if [ $1 ] 515 | then 516 | echo "Argument supplied OK as $1" 517 | echo 518 | else 519 | echo "ERROR - No argument supplied" 520 | exit -1 521 | fi 522 | 523 | echo 524 | echo `date` 525 | echo "Testing for argument which should be the content types..." 526 | if [ $2 ] 527 | then 528 | echo "Argument supplied OK as $2" 529 | echo 530 | else 531 | echo "ERROR - No argument supplied" 532 | exit -1 533 | fi 534 | 535 | # Set up variables used through this script. 536 | PROJECT_NAME=${1} 537 | CONTENT_TYPES=${2} 538 | DATE_TIME=`date +%Y%m%d-%H%M%S` 539 | 540 | # Check the Pullpush configuration file exists. 541 | if [ -e /etc/pullpush/pullpush.conf ] 542 | then 543 | source /etc/pullpush/pullpush.conf 544 | else 545 | echo 546 | echo "ERROR - Pullpush configuration file not found." 547 | exit -1 548 | fi 549 | 550 | # Check the project settings file exists. 551 | if [ -e /etc/pullpush/projects/${PROJECT_NAME}.conf ] 552 | then 553 | source /etc/pullpush/projects/${PROJECT_NAME}.conf 554 | else 555 | echo "ERROR - The configuration file /etc/pullpush/projects/${PROJECT_NAME}.conf not found." 556 | exit -1 557 | fi 558 | 559 | ## exit 560 | 561 | 562 | 563 | 564 | ### ------------------------------------------------------------------------------------------------- 565 | ##echo 566 | ##echo `date` 567 | ##echo "Disable the rules module to prevent rules from being fired off when data is imported..." 568 | ### ------------------------------------------------------------------------------------------------- 569 | ##ssh deploy@localhost "drush --yes ${DEPLOY_DRUSH_ALIAS} dis rules*" 570 | 571 | 572 | 573 | 574 | # ------------------------------------------------------------------------------------------------- 575 | echo 576 | echo `date` 577 | echo "Installing the data export import module into the livecopy website..." 578 | # ------------------------------------------------------------------------------------------------- 579 | ##ssh livecopy@localhost "drush ${LIVECOPY_DRUSH_ALIAS} pm-download data_export_import" 580 | ##ssh livecopy@localhost "drush ${LIVECOPY_DRUSH_ALIAS} --yes pm-enable data_export_import" 581 | 582 | sudo -u livecopy drush --root=/home/livecopy/web/${PROJECT_NAME} pm-download data_export_import 583 | sudo -u livecopy drush --root=/home/livecopy/web/${PROJECT_NAME} --yes pm-enable data_export_import 584 | 585 | 586 | # ------------------------------------------------------------------------------------------------- 587 | echo 588 | echo `date` 589 | echo "Installing the data export import module into the deploy website..." 590 | # ------------------------------------------------------------------------------------------------- 591 | ##ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} pm-download data_export_import" 592 | ##ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} --yes pm-enable data_export_import" 593 | 594 | sudo -u deploy drush --root=/home/deploy/web/${PROJECT_NAME} pm-download data_export_import 595 | sudo -u deploy drush --root=/home/deploy/web/${PROJECT_NAME} --yes pm-enable data_export_import 596 | 597 | 598 | # ------------------------------------------------------------------------------------------------- 599 | echo 600 | echo `date` 601 | echo "Copy the users across..." 602 | # ------------------------------------------------------------------------------------------------- 603 | ##USER_FILE_PRODUCED=$(ssh livecopy@localhost "drush ${LIVECOPY_DRUSH_ALIAS} dei-ex users") 604 | USER_FILE_PRODUCED=$(sudo -u livecopy drush --root=/home/livecopy/web/${PROJECT_NAME} dei-ex users) 605 | 606 | echo "USER_FILE_PRODUCED:${USER_FILE_PRODUCED}" 607 | 608 | 609 | #ssh deploy@localhost "mkdir -p ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users" 610 | #ssh deploy@localhost "cp ${LIVECOPY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users/${USER_FILE_PRODUCED} ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users/${FILENAME}" 611 | #ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im users --file=${USER_FILE_PRODUCED}" 612 | 613 | sudo -u deploy mkdir -p /home/deploy/web/${PROJECT_NAME}/sites/default/files/data_export_import/users 614 | sudo -u deploy cp /home/livecopy/web/${PROJECT_NAME}/sites/default/files/data_export_import/users/${USER_FILE_PRODUCED} /home/deploy/web/${PROJECT_NAME}/sites/default/files/data_export_import/users/${USER_FILE_PRODUCED} 615 | ##ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im users --file=${USER_FILE_PRODUCED}" 616 | sudo -u deploy drush --root=/home/deploy/web/${PROJECT_NAME} dei-im users --file=${USER_FILE_PRODUCED} 617 | 618 | 619 | # ------------------------------------------------------------------------------------------------- 620 | echo 621 | echo `date` 622 | echo "Copy the terms across..." 623 | # ------------------------------------------------------------------------------------------------- 624 | ##USER_FILE_PRODUCED=$(ssh livecopy@localhost "drush ${LIVECOPY_DRUSH_ALIAS} dei-ex users") 625 | TERM_FILE_PRODUCED=$(sudo -u livecopy drush --root=/home/livecopy/web/${PROJECT_NAME} dei-ex terms) 626 | 627 | echo "TERM_FILE_PRODUCED:${TERM_FILE_PRODUCED}" 628 | 629 | 630 | #ssh deploy@localhost "mkdir -p ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users" 631 | #ssh deploy@localhost "cp ${LIVECOPY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users/${USER_FILE_PRODUCED} ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/users/${FILENAME}" 632 | #ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im users --file=${USER_FILE_PRODUCED}" 633 | 634 | sudo -u deploy mkdir -p /home/deploy/web/${PROJECT_NAME}/sites/default/files/data_export_import/taxonomy_terms 635 | sudo -u deploy cp /home/livecopy/web/${PROJECT_NAME}/sites/default/files/data_export_import/taxonomy_terms/${TERM_FILE_PRODUCED} /home/deploy/web/${PROJECT_NAME}/sites/default/files/data_export_import/taxonomy_terms/${TERM_FILE_PRODUCED} 636 | ##ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im users --file=${USER_FILE_PRODUCED}" 637 | sudo -u deploy drush --root=/home/deploy/web/${PROJECT_NAME} dei-im terms --file=${TERM_FILE_PRODUCED} 638 | 639 | 640 | 641 | # ------------------------------------------------------------------------------------------------- 642 | echo 643 | echo `date` 644 | echo "Copy the nodes across..." 645 | # ------------------------------------------------------------------------------------------------- 646 | ##ssh livecopy@localhost "drush @livecopy_${PROJECT_NAME} dei-ex nodes --content-types=${NODE_CONTENT_TYPES}" > files.txt 647 | 648 | 649 | ##FILES_PRODUCED=$(ssh livecopy@localhost "drush ${LIVECOPY_DRUSH_ALIAS} dei-ex nodes --content-types=${NODE_CONTENT_TYPES}") 650 | FILES_PRODUCED=$(sudo -u livecopy drush --root=/home/livecopy/web/${PROJECT_NAME} dei-ex nodes --content-types=${CONTENT_TYPES}) 651 | 652 | 653 | 654 | echo "FILES_PRODUCED:${FILES_PRODUCED}" 655 | 656 | 657 | 658 | for FILENAME in $FILES_PRODUCED 659 | do 660 | echo "File being imported:${FILENAME}" 661 | 662 | # ssh deploy@localhost "mkdir -p ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/nodes" 663 | # ssh deploy@localhost "cp ${LIVECOPY_DOCUMENT_ROOT}/sites/default/files/data_export_import/nodes/${FILENAME} ${DEPLOY_DOCUMENT_ROOT}/sites/default/files/data_export_import/nodes/${FILENAME}" 664 | # ssh deploy@localhost "drush ${DEPLOY_DRUSH_ALIAS} dei-im nodes --file=${FILENAME}" 665 | 666 | sudo -u deploy mkdir -p /home/deploy/web/${PROJECT_NAME}/sites/default/files/data_export_import/nodes 667 | sudo -u deploy cp /home/livecopy/web/${PROJECT_NAME}/sites/default/files/data_export_import/nodes/${FILENAME} /home/deploy/web/${PROJECT_NAME}/sites/default/files/data_export_import/nodes/${FILENAME} 668 | sudo -u deploy drush --root=/home/deploy/web/${PROJECT_NAME} dei-im nodes --file=${FILENAME} 669 | 670 | done 671 | 672 | 673 | 674 | ##source /home/pullpush/.pullpush/projects/${1} 675 | 676 | 677 | ## Sort out the extra requirements. 678 | 679 | ## Carry out project extras. 680 | ##for EXTRA in $PROJECT_EXTRAS 681 | ##do 682 | ## echo 683 | ## echo "EXTRA" 684 | ## echo "$EXTRA" 685 | ##done 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | # ------------------------------------------------------------------------------------------------- 694 | ##echo 695 | ##echo `date` 696 | ##echo "Re-enable the Rules module - existing rules should still be in place..." 697 | # ------------------------------------------------------------------------------------------------- 698 | ##ssh deploy@localhost "drush --yes ${DEPLOY_DRUSH_ALIAS} en rules" 699 | ##ssh deploy@localhost "drush --yes ${DEPLOY_DRUSH_ALIAS} en rules_admin" 700 | 701 | # ------------------------------------------------------------------------------------------------- 702 | echo 703 | echo `date` 704 | echo "Finished." 705 | # ------------------------------------------------------------------------------------------------- 706 | 707 | exit 0 --------------------------------------------------------------------------------