diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2017-11-29 14:35:59 +0100 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2017-12-04 13:26:36 +0100 |
commit | 12a4f0f44958a4a321e5314e3f6248de1139b6d0 (patch) | |
tree | 818759cde0bfaa220ac3fb0539a5935ef966f801 /deploy.sh | |
parent | 6dfa70974ec3a66f49c7fbdba255f99a31297342 (diff) |
Refactored .gitlab-ci.yml, added deploy to production
Diffstat (limited to 'deploy.sh')
-rwxr-xr-x | deploy.sh | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 00000000..18808041 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +set -e + +remote_host= +remote_path= +deploy_id= + +while getopts ":h:p:i:" opt; do + case ${opt} in + h) + remote_host="$OPTARG" + ;; + p) + remote_path="$OPTARG" + ;; + i) + deploy_id="$OPTARG" + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "The option -$OPTARG requires an argument" >&2 + exit 1 + ;; + esac +done + +if [ -z "${remote_host}" ] || [ -z "${remote_path}" ] || [ -z "${deploy_id}" ]; then + echo "Please specify -h[remote host], -p[remote path] and -i[deploy id]" >&2 + exit 1 +fi + +echo "syncing ${PWD}/ to ${remote_host}:${remote_path}/${deploy_id}/" + +rsync -vAax --exclude '.git*' --exclude .composer/ \ + -e "ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" \ + ./ "${remote_host}:${remote_path}/${deploy_id}/" + +ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${remote_host}" " + set -e + + if [[ -f \"${remote_path}/current/config/config.php\" ]]; then + echo \"Config backup\" + cp \"${remote_path}/current/config/config.php\" \"${deploy_id}-config.php\" + fi + + echo \"Changing symlink\" + unlink \"${remote_path}/current\" + ln -s \"${remote_path}/${deploy_id}\" \"${remote_path}/current\" + + if [[ -f \"${deploy_id}-config.php\" ]]; then + echo \"Restoring config\" + cp \"${deploy_id}-config.php\" \"${remote_path}/current/config/config.php\" + fi +" |