Skip to content

Instantly share code, notes, and snippets.

@4selin
Last active July 1, 2018 09:31
Show Gist options
  • Save 4selin/31623a93fca7b9a060ab0eebfa4c5afb to your computer and use it in GitHub Desktop.
Save 4selin/31623a93fca7b9a060ab0eebfa4c5afb to your computer and use it in GitHub Desktop.
deploy bash script
#!/bin/bash -x
# -v verbose Print each command to stdout before executing it
# -x xtrace Similar to -v, but expands commands
#Remote User
user=_enter_user_
#Remote Group
group=www-data
#Remote Server
server=_enter_server_ip_
#Local wp-content dir
local_dir=/path/to/local_project/root
#Remote wp-content dir
remote_dir=/path/to/remote_project/root
# current datetime
now=$(date +"%Y-%m-%d_%H:%M:%S")
# dirs to deploy. separated by space
dirs="vendor wp-content/themes/enter_your_theme wp-content/plugins/enter_your_plugin"
# deploy archive filename
archive_deploy=deploy_${now}.zip
# backup archive filename
archive_backup=backup_${now}.zip
# Let's go
# cd to local folder
cd ${local_dir}
# zip folders
zip -rq -1 ${archive_deploy} ${dirs}
# copy zip to remote folder
scp ./${archive_deploy} ${user}@${server}:${remote_dir}
# ssh to remote server
ssh ${user}@${server} <<HERE
# cd to remove folder
cd ${remote_dir}
# zip remote folders, -m move into zipfile (delete OS files)
zip -rqmT -1 ${archive_backup} ${dirs}
# unzip deploy archive
unzip -o ${archive_deploy}
# chown dirs
chown -R ${user}:${group} ${dirs}
# chmod dirs and files
find ${dirs} -type d -exec chmod 755 {} \;
find ${dirs} -type f -exec chmod 644 {} \;
HERE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment