forked from modern-dev/ftp-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·143 lines (125 loc) · 4.39 KB
/
entrypoint.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
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
#!/bin/sh -e
echo "▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼"
echo ""
echo " ___ _ _ "
echo " | _| |_ ___ ___ _____|_|___ ___ ___ ___ "
echo " | _| _| . |___| | | _| _| . | _|"
echo " |_| |_| | _| |_|_|_|_|_| |_| |___|_| "
echo " |_| "
echo ""
echo "▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲"
echo ""
echo "=== 📋 Environment variables ==="
echo "INPUT_SERVER: ${INPUT_SERVER}"
echo "INPUT_USER: ${INPUT_USER}"
echo "INPUT_PASSWORD: ${INPUT_PASSWORD}"
echo "INPUT_LOCAL_DIR: ${INPUT_LOCAL_DIR}"
echo "INPUT_REMOTE_DIR: ${INPUT_REMOTE_DIR}"
echo "INPUT_DELETE: ${INPUT_DELETE}"
echo "INPUT_EXCLUDE: ${INPUT_EXCLUDE}"
echo "INPUT_EXCLUDE_GLOB: ${INPUT_EXCLUDE_GLOB}"
echo "INPUT_MAX_RETRIES: ${INPUT_MAX_RETRIES}"
echo "INPUT_NO_SYMLINKS: ${INPUT_NO_SYMLINKS}"
echo "INPUT_FTP_SSL_ALLOW: ${INPUT_FTP_SSL_ALLOW}"
echo "INPUT_FTP_USE_FEAT: ${INPUT_FTP_USE_FEAT}"
echo "INPUT_FTP_NOP_INTERVAL: ${INPUT_FTP_NOP_INTERVAL}"
echo "INPUT_NET_MAX_RETRIES: ${INPUT_NET_MAX_RETRIES}"
echo "INPUT_NET_PERSIST_RETRIES: ${INPUT_NET_PERSIST_RETRIES}"
echo "INPUT_NET_TIMEOUT: ${INPUT_NET_TIMEOUT}"
echo "INPUT_DNS_MAX_RETRIES: ${INPUT_DNS_MAX_RETRIES}"
echo "INPUT_DNS_FATAL_TIMEOUT: ${INPUT_DNS_FATAL_TIMEOUT}"
echo ""
echo "=== 📂 Current location ==="
pwd
echo ""
echo "=== List this directory ==="
ls -lha
echo ""
FTP_SETTINGS="set ftp:ssl-allow ${INPUT_FTP_SSL_ALLOW};"
FTP_SETTINGS="${FTP_SETTINGS} set ftp:use-feat ${INPUT_FTP_USE_FEAT};"
FTP_SETTINGS="${FTP_SETTINGS} set ftp:nop-interval ${INPUT_FTP_NOP_INTERVAL};"
FTP_SETTINGS="${FTP_SETTINGS} set net:max-retries ${INPUT_NET_MAX_RETRIES};"
FTP_SETTINGS="${FTP_SETTINGS} set net:persist-retries ${INPUT_NET_PERSIST_RETRIES};"
FTP_SETTINGS="${FTP_SETTINGS} set net:timeout ${INPUT_NET_TIMEOUT};"
FTP_SETTINGS="${FTP_SETTINGS} set dns:max-retries ${INPUT_DNS_MAX_RETRIES};"
FTP_SETTINGS="${FTP_SETTINGS} set dns:fatal-timeout ${INPUT_DNS_FATAL_TIMEOUT};"
MIRROR_COMMAND="mirror --continue --reverse"
if [ -z "${INPUT_MAX_RETRIES}" ]; then
INPUT_MAX_RETRIES="10"
fi
if [ -z "${INPUT_LOCAL_DIR}" ]; then
INPUT_LOCAL_DIR="./"
else
if [ "${INPUT_LOCAL_DIR}" != "./" ]; then
INPUT_LOCAL_DIR="${INPUT_LOCAL_DIR}/"
fi
fi
if [ -z "${INPUT_REMOTE_DIR}" ]; then
INPUT_REMOTE_DIR="./"
else
if [ "${INPUT_REMOTE_DIR}" != "./" ]; then
INPUT_REMOTE_DIR="${INPUT_REMOTE_DIR}/"
fi
fi
if [ "${INPUT_NO_SYMLINKS}" = "true" ]; then
MIRROR_COMMAND="${MIRROR_COMMAND} --no-symlinks"
fi
if [ "${INPUT_DELETE}" = "true" ]; then
MIRROR_COMMAND="${MIRROR_COMMAND} --delete"
fi
if [ -n "$INPUT_EXCLUDE" ]; then
for exl in $INPUT_EXCLUDE ; do
MIRROR_COMMAND="${MIRROR_COMMAND} --exclude ${exl}"
done
fi
if [ -n "$INPUT_EXCLUDE_GLOB" ]; then
for exl in $INPUT_EXCLUDE_GLOB ; do
MIRROR_COMMAND="${MIRROR_COMMAND} --exclude-glob ${exl}"
done
fi
echo "=== 📁 Directories ==="
echo "INPUT_LOCAL_DIR: ${INPUT_LOCAL_DIR}"
echo "INPUT_REMOTE_DIR: ${INPUT_REMOTE_DIR}"
echo ""
echo "=== List local directory | ${INPUT_LOCAL_DIR} ==="
ls -lha "${INPUT_LOCAL_DIR}"
echo ""
echo "=== ⬆️ LFTP ==="
echo "lftp"
echo " FTP_SETTINGS -> ${FTP_SETTINGS}"
echo " MIRROR_COMMAND -> ${MIRROR_COMMAND}"
echo " INPUT_LOCAL_DIR -> ${INPUT_LOCAL_DIR}"
echo " INPUT_REMOTE_DIR -> ${INPUT_REMOTE_DIR}"
echo ""
echo "=== * ℹ️ NOTE * ==="
echo "The upload should be fast depends how many files and what size they have."
echo "If the process take for several minutes, please stop the job and run it again."
echo ""
COUNTER=1
SUCCESS=""
until [ ${COUNTER} -gt ${INPUT_MAX_RETRIES} ]; do
echo ""
echo "Try #: ${COUNTER}"
echo "# ---------------------------------------------"
lftp \
-u "${INPUT_USER}","${INPUT_PASSWORD}" \
"${INPUT_SERVER}" \
-e "${FTP_SETTINGS} ${MIRROR_COMMAND} ${INPUT_LOCAL_DIR} ${INPUT_REMOTE_DIR}; quit;" &&
SUCCESS="true"
if [ -n "${SUCCESS}" ]; then
break
fi
sleep 1m
COUNTER=$((COUNTER + 1))
done
if [ -z "${SUCCESS}" ]; then
echo ""
echo "=============================="
echo "= 👎🏻 ERROR: UPLOAD FAILED ="
echo "=============================="
exit 1
fi
echo ""
echo "=============================="
echo "= 🚀 FTP UPLOAD FINISHED! ="
echo "=============================="