-
Notifications
You must be signed in to change notification settings - Fork 171
/
debian.sh
executable file
·34 lines (31 loc) · 961 Bytes
/
debian.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
#!/bin/bash
# ftpsync wrapper for tunasync
# requires: ftpsync, rsync
set -e
set -o pipefail
set -u
export LOGNAME=tunasync
FTPSYNC="${FTPSYNC:-"ftpsync"}"
FTPSYNC_LOG_DIR="${FTPSYNC_LOG_DIR:-"/var/log/ftpsync"}"
trap 'kill $(jobs -p)' EXIT
if [[ $1 == sync:archive:* ]]; then
${FTPSYNC} $1 &
PID=$!
jobname=${1##sync:archive:}
jobname=${jobname//\/}
jobname=${jobname//.}
sleep 2
if [[ ! -f ${FTPSYNC_LOG_DIR}/ftpsync-${jobname}.log ]]; then
echo "Failed to start ftpsync, please check configuration file."
exit 1
fi
tail --retry -f "${FTPSYNC_LOG_DIR}/ftpsync-${jobname}.log" &
tail --retry -f "${FTPSYNC_LOG_DIR}/rsync-ftpsync-${jobname}.log" &
tail --retry -f "${FTPSYNC_LOG_DIR}/rsync-ftpsync-${jobname}.error" &
wait $PID
sz=$(tail -n 15 ${FTPSYNC_LOG_DIR}/rsync-ftpsync-${jobname}.log.0|grep -Po '(?<=Total file size: )\d+')
[[ -z "$sz" ]] || echo "Total size is" $(numfmt --to=iec $sz)
else
echo "Invalid command line"
exit 1
fi