2017-11-29 14:35:59 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
remote_host=
|
|
|
|
remote_path=
|
|
|
|
deploy_id=
|
|
|
|
|
2017-12-04 13:25:44 +01:00
|
|
|
show_help(){
|
|
|
|
echo "Usage: $0 [OPTION]..." >&2
|
|
|
|
echo "Deploys a software with rsync over ssh" >&2
|
|
|
|
echo "The options -i, -p and -r are required" >&2
|
|
|
|
echo "" >&2
|
|
|
|
echo " -h Display this help screen" >&2
|
|
|
|
echo " -i <id> Sets the id, a unique name for the deployment" >&2
|
|
|
|
echo " -p <path> Define the base path on the server" >&2
|
|
|
|
echo " -r <host> The remote server name and user" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
while getopts ":hi:p:r:" opt; do
|
2017-11-29 14:35:59 +01:00
|
|
|
case ${opt} in
|
|
|
|
h)
|
2017-12-04 13:25:44 +01:00
|
|
|
show_help
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
r)
|
2017-11-29 14:35:59 +01:00
|
|
|
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
|
2017-12-04 13:25:44 +01:00
|
|
|
show_help
|
2017-11-29 14:35:59 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "syncing ${PWD}/ to ${remote_host}:${remote_path}/${deploy_id}/"
|
|
|
|
|
2018-08-04 21:26:33 +02:00
|
|
|
rsync -vAax --exclude '.git*' --exclude .composer/ --exclude coverage/ --exclude node_modules/ \
|
2017-11-29 14:35:59 +01:00
|
|
|
-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\"
|
|
|
|
|
|
|
|
echo \"Restoring config\"
|
2018-08-20 23:21:02 +02:00
|
|
|
cp \"${deploy_id}-config.php\" \"${remote_path}/${deploy_id}/config/config.php\"
|
2017-11-29 14:35:59 +01:00
|
|
|
fi
|
2018-08-20 23:21:02 +02:00
|
|
|
|
|
|
|
echo \"Changing symlink\"
|
|
|
|
ln -nsf \"${remote_path}/${deploy_id}\" \"${remote_path}/current\"
|
2017-11-29 14:35:59 +01:00
|
|
|
"
|