Add upload script and use bash

This commit is contained in:
Christoph Schlosser 2017-10-25 23:59:10 +02:00
parent ba60bcf066
commit 6ae5a11253
2 changed files with 38 additions and 1 deletions

View File

@ -2,7 +2,8 @@ FROM alpine
RUN apk --no-cache add \ RUN apk --no-cache add \
libressl \ libressl \
lftp lftp \
bash
ADD upload.sh /bin/ ADD upload.sh /bin/
RUN chmod +x /bin/upload.sh RUN chmod +x /bin/upload.sh

36
upload.sh Normal file → Executable file
View File

@ -1 +1,37 @@
#!/bin/bash #!/bin/bash
if [ -z "$PLUGIN_USERNAME" ]; then
echo "Need to set username"
exit 1
fi
if [ -z "$PLUGIN_HOSTNAME" ]; then
echo "Need to set hostname"
exit 1
fi
if [ -z "$PLUGIN_SECURE" ]; then
PLUGIN_SECURE="true"
fi
if [ -z "$PLUGIN_DEST_DIR" ]; then
PLUGIN_DEST_DIR="/"
fi
if [ -z "$PLUGIN_SRC_DIR" ]; then
PLUGIN_SRC_DIR="/"
fi
PLUGIN_EXCLUDE_STR=""
PLUGIN_INCLUDE_STR=""
IFS=',' read -ra in_arr <<< "$PLUGIN_EXCLUDE"
for i in "${in_arr[@]}"; do
PLUGIN_EXCLUDE_STR="$PLUGIN_EXCLUDE_STR -x $i"
done
IFS=',' read -ra in_arr <<< "$PLUGIN_INCLUDE"
for i in "${in_arr[@]}"; do
PLUGIN_INCLUDE_STR="$PLUGIN_INCLUDE_STR -x $i"
done
lftp -c "open -u $PLUGIN_USERNAME,$FTP_PASSWORD $PLUGIN_HOSTNAME; set ftp:ssl-force $PLUGIN_SECURE; set ftp:ssl-protect-data $PLUGIN_SECURE; mirror -R $PLUGIN_INCLUDE_STR $PLUGIN_EXCLUDE_STR $(pwd)$PLUGIN_SRC_DIR $PLUGIN_DEST_DIR"