forked from xophz/x.rsync.wp.uploads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.sh
executable file
·52 lines (45 loc) · 1.06 KB
/
.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
#!/bin/bash
while getopts d:i:k:u:c: option
do
case "${option}"
in
d) X_DOMAIN=${OPTARG};;
i) X_INSTANCE=${OPTARG};;
k) X_KEY=${OPTARG};;
u) X_USR=${OPTARG};;
c) X_CONTENT=${OPTARG};;
esac
done
required(){
VAR="X_$1"
if [[ ${!VAR} = "" ]]
then
echo "$1 Required"
exit
fi
}
function xSync(){
RSYNC="sudo rsync -rltDvze 'ssh -i $KEY'"
sudo runuser -l root -c "${RSYNC} ${1}:${2} ${2}"
sudo runuser -l root -c "${RSYNC} ${2} ${1}:${2}"
}
# GET REQUIRED VARS
required DOMAIN
required INSTANCE
required KEY
required USR
required CONTENT
# KEYS & PATHS
KEY="/home/$X_USR/.ssh/$X_KEY"
CONTENT="/var/www/$X_DOMAIN/public/$X_CONTENT"
UPLOADS="$CONTENT/uploads/"
PLUGINS="$CONTENT/plugins/"
THEMES="$CONTENT/themes/"
WFLOGS="$CONTENT/wflogs/"
# RUN CMDS
sudo runuser -l root -c "ssh-keyscan $X_INSTANCE >> ~/.ssh/known_hosts"
xSync "$X_USR@$X_INSTANCE" "$UPLOADS"
xSync "$X_USR@$X_INSTANCE" "$PLUGINS"
xSync "$X_USR@$X_INSTANCE" "$THEMES"
xSync "$X_USR@$X_INSTANCE" "$WFLOGS"
sudo runuser -l root -c "ssh-keygen -R $X_INSTANCE"