forked from srlefevre/zfs-repl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource-config
executable file
·180 lines (146 loc) · 3.72 KB
/
source-config
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#! /bin/bash
# creates a configuration for target system that can be piped to a file
find_bins() {
# params:
# list of exec to find
# results var
[ $# -ne 2 ] && exit 1
local execs
local result_var
local p
local paths
local IFS
local e
local uid
declare -a execs=($1)
result_var=$2
uid=$(id -u )
#find and check bins
for e in ${execs[*]}; do
p=$(which $e 2> /dev/null)
if [[ $? -ne 0 || $e = "date" ]]; then
# try to find it
guess_bin $e
p="${_guess_bin}"
fi
# root doesn't need sudo
if [[ $e == sudo && $uid -eq 0 ]]; then
p=' '
fi
paths="${paths}${p}"$'\n'
done
printf -v "${result_var}" '%s' "${paths}"
}
guess_bin() {
# params
# exec
[ $# -ne 1 ] && exit 1
local ex
local path_list
local k
local cmd
local IFS
local out
ex=$1
path_list="/sbin /bin /usr/sbin /usr/bin /usr/gnu/bin"
#build command to run
IFS=' '
for k in $path_list; do
if [ -x $k/$ex ]; then
out=$k/$ex;
if [ $ex = date ]; then
test_date "$out"
if [ $? -eq 0 ]; then
break
else
out=
fi
fi
else
out=" "
fi;
done
printf -v "_${FUNCNAME}" '%s' "${out}"
}
test_date() {
# params
# path to date commmand to test
local ex
ex=$1
$ex --date="-2 days" > /dev/null 2>&1
}
usage() {
echo "Usage: $(basename $0 .sh)"
exit 0
}
declare -a VARS=('SUDO=%s' 'ZFS="$SUDO %s"' 'GZIP=%s' 'XZ=%s' 'NC=%s' 'SOCAT=%s' 'MBUFFER=%s' 'CAT=%s' 'OPENSSL=%s' 'LOGGER=%s' 'MAILX=%s' 'SHUF=%s' 'DATE=%s')
#EXECS="sudo zfs zcat xzcat nc socat mbuffer cat openssl logger mailx pv shuf date"
EXECS="sudo zfs gzip xz nc socat mbuffer cat openssl logger mailx pv shuf date"
BINS=
CONFIG_PATH=/etc/zfs-repl
#HOST_CONF=$CONFIG_PATH/$HOST.conf
CONFIG="# local source for zfs-repl"$'\n'
find_bins "$EXECS" "BINS"
IFS=$'\n'
i=0
for v in $BINS; do
printf -v t "${VARS[$i]}" "$v"
CONFIG="${CONFIG}${t}"$'\n'
i=$(( i + 1 ))
done
echo "$CONFIG"
tee << EOF
##### settings
# uncomment the settings below to over ride the defaults in the zfs-repl script
# settings in this file can be over ridden by command line options to zfs-repl script
#
# minimally set the email addresses
mail_from=
mail_to=
mail_subject="zfs-replication log"
#process files/paths
LOCK_PATH=/var/lock
LOG_FILE=/var/log/zfs-repl.log
#log to syslog (true/false)
#SYSLOG=true
#date format used in log file
# see 'man date' or 'info date' for options
#DATE_FORMAT="+%Y-%m-%d %H:%M:%S"
# default transport protocol (see 'zfs-repl --help' for valid options)
#PROTOCOL=MBUFFER
# ssh cipher to use
#SSH_CIPHER="-c blowfish"
#netcat local and remote options
# see 'man nc' for options
#NC_OPTS=
#RMT_NC_OPTS="-l"
#mbuffer local and remote options
# see 'man mbuffer' for options
#MBUFFER_OPTS="-s 128k -m 256M -q -v 1"
#RMT_MBUFFER_OPTS="-s 128k -m 256M -q -v 1"
#socat local and remote options
# see 'man socat' for options
#SOCAT_OPTS=
#RMT_SOCAT_OPTS=
#socat local and remote TCP transport options
#SOCAT_TCP_OPTS="retry=5"
#RMT_SOCAT_TCP_OPTS=
# seconds to wait for non-ssh protocols to initiate send/receive connection before timing out
#REPL_INIT_TIMEOUT=120
# default compression tool and compression level (see 'zfs-repl --help' for valid options)
#COMPRESSION=GZIP
#COMP_LEVEL=6
# for non-ssh protocols set the default port
# 'auto' picks a number within the range specified in PORT_RANGE
# this is helpful when your running multiple concurrent replications to the same host
#PROTOCOL_PORT='auto'
#PORT_RANGE=60000-65000
# always email replication log (true/false)
#SENDMAIL=false
# email repliction log when an error occurs (true/false)
#ERR_MAIL=true
#encrypt replication over non-ssh protocols (true/false)
#ENCRYPT=false
#encryption password. if left null/blank, a new password will be generated for each replication session
#ENCRYPT_PASSWORD=
EOF