-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsync_vps.sh
More file actions
executable file
·42 lines (35 loc) · 886 Bytes
/
sync_vps.sh
File metadata and controls
executable file
·42 lines (35 loc) · 886 Bytes
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
#!/bin/bash
# Define variables
LOCAL_PATH=~/dev/zui
VPS_USER=pow
VPS_IP=34.169.172.111
SSH_KEY=~/.ssh/google_compute_engine
VPS_PATH=~/dev/zui
# Function to check if command was successful
check_status() {
if [ $? -ne 0 ]; then
echo "Error: $1 failed"
exit 1
fi
}
# Ensure we're in the correct local directory
cd "$LOCAL_PATH" || {
echo "Error: Cannot change to local directory $LOCAL_PATH"
exit 1
}
# Git operations on local machine
echo "Pushing local changes..."
git push
check_status "Git push"
# SSH into VPS and pull changes
echo "Connecting to VPS and pulling changes..."
ssh -i "$SSH_KEY" "$VPS_USER@$VPS_IP" << EOF
cd $VPS_PATH || {
echo "Error: Cannot change to VPS directory $VPS_PATH"
exit 1
}
git pull
exit
EOF
check_status "VPS operations"
echo "Successfully updated both local and VPS repositories!"