-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlftp-mirror.sh
54 lines (44 loc) · 1.5 KB
/
lftp-mirror.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
#!/bin/sh
# Display variables for troubleshooting
echo -e "Variables set:\\n\
PUID=${PUID}\\n\
PGID=${PGID}\\n\
HOST=${HOST}\\n\
PORT=${PORT}\\n\
USERNAME=${USERNAME}\\n\
REMOTE_DIR=${REMOTE_DIR}\\n\
FINISHED_DIR=${FINISHED_DIR}\\n\
LFTP_PARTS=${LFTP_PARTS}\\n\
LFTP_FILES=${LFTP_FILES}\\n"
# if no finished files directory specified, default to /config/download
[ -z "$FINISHED_DIR" ] && FINISHED_DIR="/config/download"
# create a directory for placing private key for lftp to use
mkdir -p /config/ssh
# create a directory for active downloads
mkdir -p /config/.download
# create finished downloads directory
mkdir -p /config/download
while true
do
# LFTP with specified segment & parallel
echo "[$(date '+%H:%M:%S')] Checking ${REMOTE_DIR} for files....."
lftp -u $USERNAME, sftp://$HOST -p $PORT <<-EOF
set ssl:verify-certificate no
set sftp:auto-confirm yes
set sftp:connect-program "ssh -a -x -i /config/ssh/id_rsa"
mirror -c --no-empty-dirs --Remove-source-files --Remove-source-dirs --use-pget-n=$LFTP_PARTS -P$LFTP_FILES $REMOTE_DIR /config/.download
quit
EOF
if [ "$(ls -A /config/.download)" ]
then
# Move finished downloads to destination directory
echo "[$(date '+%H:%M:%S')] Moving files....."
chmod -R 777 /config/.download/*
mv -fv /config/.download/* $FINISHED_DIR
else
echo "[$(date '+%H:%M:%S')] Nothing to download"
fi
# Repeat process after one minute
echo "[$(date '+%H:%M:%S')] Sleeping for 1 minute"
sleep 1m
done