-
Notifications
You must be signed in to change notification settings - Fork 1
/
csync.sh
58 lines (54 loc) · 1.54 KB
/
csync.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
#!/bin/sh
CSYNCPIDFILE=$LOCKDIRPATH/csync.pid
csync.sync() {
/usr/sbin/daemon -p $CSYNCPIDFILE /usr/local/sbin/csync2 -vrx && [ -z "$1" ] && return 0
sleep 1
CSYNCPID=`cat $CSYNCPIDFILE`
while true; do
System.daemon.isExist $CSYNCPID || break
sleep 1
done
}
csync.synctarget() {
/usr/sbin/daemon -p $CSYNCPIDFILE /usr/local/sbin/csync2 -vx $@
}
csync.syncinit() {
if [ "$1" ]; then
out.message "sync with $1"
/usr/sbin/daemon -p $CSYNCPIDFILE /usr/local/sbin/csync2 -vrTI $HOSTNAME $1
sleep 1
CSYNCPID=`cat $CSYNCPIDFILE`
while true; do
System.daemon.isExist $CSYNCPID || break
sleep 1
done
/usr/sbin/daemon -p $CSYNCPIDFILE /usr/local/sbin/csync2 -f /etc/hosts /usr/local/etc/csync2.cfg
sleep 1
CSYNCPID=`cat $CSYNCPIDFILE`
while true; do
System.daemon.isExist $CSYNCPID || break
sleep 1
done
csync.sync wait
else
out.error 'give me hostname!'
fi
}
csync.crontab() {
local TIME=15
[ "$1" ] && TIME=$1
echo "*/$TIME * * * * root /usr/sbin/daemon -p $CSYNCPIDFILE /usr/local/sbin/csync2 -vxr"
}
csync.makecert() {
cat <<-EOF
openssl genrsa -out /usr/local/etc/csync2_ssl_key.pem 1024
openssl req -new -key /usr/local/etc/csync2_ssl_key.pem -out /usr/local/etc/csync2_ssl_cert.csr
openssl x509 -req -days 600 -in /usr/local/etc/csync2_ssl_cert.csr -signkey /usr/local/etc/csync2_ssl_key.pem -out /usr/local/etc/csync2_ssl_cert.pem
EOF
}
csync.check() {
pkg.install gnutls security/gnutls
pkg.install csync2 net/csync2 csync.makecert
chmod 4550 /usr/local/sbin/csync2
}
#out.message 'csync: module loaded'