-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupload
executable file
·92 lines (75 loc) · 2.73 KB
/
upload
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
#! /bin/sh
# upload - recursively uploads file(s) to a remote server. The
# following environment variables are required:
# - LOCAL_PATH
# - REMOTE_SERVER
# - REMOTE_PATH
# - USERNAME
# - PASSWORD
#
# The following environment variables are optional:
# - DEBUG
# - DELETE_FILES
# - INSECURE_SKIP_SSL_VERIFICATION
# Copyright 2020 Toolhouse, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
. /_func
cd "$LOCAL_PATH" || exit 1
DEBUG_STATEMENT=""
if parse_bool "$DEBUG"; then
DEBUG_STATEMENT=debug;
fi
SSL_VERIFY_STATEMENT=""
if parse_bool "$INSECURE_SKIP_SSL_VERIFICATION"; then
echo "Warning: SSL certificate verification is disabled, this is an insecure mode of operation. To disable this behavior, set INSECURE_SKIP_SSL_VERIFICATION=false"
SSL_VERIFY_STATEMENT="set ssl:verify-certificate false;"
fi
CREATE_REMOTE_DIR_CMD=""
if parse_bool "$CREATE_REMOTE_DIR"; then
CREATE_REMOTE_DIR_CMD="mkdir -p -f $REMOTE_PATH;"
fi
DELETE_ARG=""
if parse_bool "$DELETE_FILES"; then
echo "Warning: This will delete files at destination that are not present at the source. To disable this behavior, set DELETE_FILES=false"
DELETE_ARG=--delete
fi
EXCLUDE_ARG=""
if is_set "$EXCLUDE_FILES"; then
EXCLUDE_ARG="--exclude $EXCLUDE_FILES"
fi
lftp -u "$USERNAME","$PASSWORD" $REMOTE_SERVER <<EOF
$DEBUG_STATEMENT
$SSL_VERIFY_STATEMENT
set cmd:fail-exit yes;
set net:limit-rate $NET_LIMIT_RATE;
set net:limit-max $NET_LIMIT_MAX;
set net:limit-total-rate $NET_LIMIT_TOTAL_RATE;
set net:limit-total-max $NET_LIMIT_TOTAL_MAX;
set net:timeout $NET_TIMEOUT;
set net:reconnect-interval-base $NET_RECONNECT_INTERVAL_BASE;
set net:reconnect-interval-multiplier $NET_RECONNECT_INTERVAL_MULTIPLIER;
set net:max-retries $NET_MAX_RETRIES;
set net:persist-retries $NET_PERSIST_RETRIES;
set mirror:parallel-directories $MIRROR_PARALLEL_DIRECTORIES;
set mirror:parallel-transfer-count $MIRROR_PARALLEL_TRANSFER_COUNT;
set mirror:set-permissions $MIRROR_SET_PERMISSIONS;
set sftp:auto-confirm $SFTP_AUTO_CONFIRM;
set sftp:max-packets-in-flight $SFTP_MAX_PACKETS_IN_FLIGHT;
set sftp:protocol-version $SFTP_PROTOCOL_VERSION;
set sftp:server-program $SFTP_SERVER_PROGRAM;
$CREATE_REMOTE_DIR_CMD
cd $REMOTE_PATH;
mirror --no-perms $DELETE_ARG $EXCLUDE_ARG --reverse;
exit;
EOF