-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·36 lines (28 loc) · 1.04 KB
/
deploy.sh
File metadata and controls
executable file
·36 lines (28 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
set -euo pipefail
# Deployment variables
REMOTE_USER="${REMOTE_USER:?Please set REMOTE_USER}"
REMOTE_HOST="${REMOTE_HOST:?Please set REMOTE_HOST}"
LOCAL_PUBLIC_HTML="./home/public_html"
REMOTE_PUBLIC_HTML="public_html"
# Check local directory is correct (should be repo root)
if [ ! -d "$LOCAL_PUBLIC_HTML" ]; then
echo "Error: $LOCAL_PUBLIC_HTML does not exist."
echo "Please run in repo's root"
exit 1
fi
echo "Deploying $LOCAL_PUBLIC_HTML to $REMOTE_USER@$REMOTE_HOST:~/$REMOTE_PUBLIC_HTML"
TMP_DIR=public_html-`uuidgen`
echo "Copy files with permissions preserved..."
scp -r -p $LOCAL_PUBLIC_HTML "$REMOTE_USER@$REMOTE_HOST:~/$TMP_DIR"
ssh "$REMOTE_USER@$REMOTE_HOST" bash <<EOF
set -euo pipefail
echo "Clean remote directory..."
rm -rf ./public_html || echo "./public_html does not exist already"
echo "Move temporary public_html dir to normal one..."
mv $TMP_DIR ./public_html
echo "Set correct ownership..."
GROUP=\`id -gn\`
chown -R "\$USER:\$GROUP" ~/public_html
EOF
echo "Deployment complete"