-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.sh
executable file
·69 lines (55 loc) · 1.88 KB
/
upload.sh
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
# Upload arbitrary files and folders to the remote root
#
# Please have a look at ./wp-sync-deploy.example.env to see all required variables.
#
# The remote folder must exist and be empty, otherwise this script will fail.
#
# COMMANDS:
#
# Upload to production or staging
# `./wp-sync-deploy/upload.sh <production|staging> --paths="file1 folder1 folder2"`
# The directory relative to the script
SCRIPT_DIR=$(realpath $(dirname $0))
# Source files
source "$SCRIPT_DIR/lib/functions.sh"
source "$SCRIPT_DIR/lib/bootstrap.sh"
# Default value for DEPLOY_PATHS
DEPLOY_PATHS=""
# Parse arguments
for arg in "$@"; do
case $arg in
--paths=*)
DEPLOY_PATHS="${arg#*=}"
shift
;;
esac
done
# Check if DEPLOY_PATHS is empty
if [[ -z "$DEPLOY_PATHS" ]]; then
logError "The --paths option was not provided or is empty."
fi
# Will be displayed if no arguments are being provided
USAGE_MESSAGE="Usage:
./wp-sync-deploy/push.sh <production|staging> --paths='file1 folder1 folder2'"
checkRemoteRootExistsAndIsEmpty
logSuccess "All checks successful! Proceeding ..."
logLine
# Confirm the upload
log "📦 Remote host: ${BLUE}$PRETTY_REMOTE_HOST${NC}"
log "📦 Remote dir: ${BLUE}$REMOTE_ROOT_DIR${NC}"
log "📦 Upload: ${BLUE}$(echo "$DEPLOY_PATHS" | sed 's/ /, /g')${NC}"
log "📦 Proceed?"
read -r -p "[y/n] " PROMPT_RESPONSE
# Exit if not confirmed
[[ "$PROMPT_RESPONSE" != "y" ]] && exit 1
log "🚀 ${GREEN}${BOLD}[ LIVE ]${NORMAL}${NC} Pushing to $PRETTY_REMOTE_ENV ..."
# Execute rsync from $LOCAL_ROOT_DIR in a subshell to make sure we are staying in the current pwd
(
cd "$LOCAL_ROOT_DIR"
rsync -avz --delete --relative \
-e "ssh -p $REMOTE_SSH_PORT" \
--exclude-from="$DEPLOYIGNORE_FILE" \
$DEPLOY_PATHS "$REMOTE_SSH:$REMOTE_ROOT_DIR"
)
log "\n✅ ${GREEN}${BOLD}[ LIVE ]${NORMAL}${NC} Push to $PRETTY_REMOTE_ENV completed"