-
Notifications
You must be signed in to change notification settings - Fork 1
/
sync.sh
executable file
·65 lines (55 loc) · 2.39 KB
/
sync.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
# !/bin/bash
# MIT License
# Copyright (c) 2019 Beyond Hosting LLC
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#Configurables
DST_HOST='0.0.0.0'
DST_PORT='2202'
#Not implemented yet.
REMOTE_USER='root'
#Clear Vars
unset HA_USERS
echo "# LSYNCD configuration managed by /usr/local/beyondhosting/cpsync" > /etc/lsyncd.conf
# Grab cPanel accounts with a package that begins with 'HASYNC_'
for i in `ls /var/cpanel/users/*`;
do
if grep -Fiq "HASYNC_" $i;
then
# Successfully identified this account requiring HASYNC.
# HA_USERS="\n"$HA_USERS$(basename $i);
HA_USERS=("${HA_USERS[@]}" $(basename $i))
fi
done
# Loop over users and copy new cPanel CPMOVE files and restore them
for i in "${HA_USERS[@]}"; do
if ssh root@$DST_HOST -p $DST_PORT '[ ! -f /var/cpanel/users/$i ]'
then
echo "User '$i' does not exists, transferring cPanel"
/scripts/pkgacct $i
scp -P $DST_PORT /home/cpmove-$i.tar.gz root@$DST_HOST:/home
ssh root@$DST_HOST -p $DST_PORT "/scripts/restorepkg --force /home/cpmove-$i.tar.gz; rm -f /home/cpmove-$i.tar.gz"
rm /home/cpmove-$i.tar.gz -f
else
echo "User cPanel already exists";
fi
# Update lsyncd
echo "Adding User to LSYNCD:" $i
echo "sync{default.rsyncssh, source=\"/home/$i\", host=\"$DST_HOST\", targetdir=\"/home/$i\"}" >> /etc/lsyncd.conf
done;
# Update lsyncd
# Restart lsyncd
systemctl restart lsyncd