-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.sh
executable file
·63 lines (55 loc) · 1.91 KB
/
upload.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
#!/usr/bin/env bash
set -e
function require() {
if ! command -v "$1" &>/dev/null; then
echo "Requires $1"
exit 1
fi
}
function upload_via_ftp() {
require lftp
PREPEND_COMMANDS="set ftp:ssl-allow no;" # ¯\_(ツ)_/
APPEND_COMMANDS="exit"
lftp -e "$PREPEND_COMMANDS mirror -R $SRC $DST; $APPEND_COMMANDS" -u "$USER,$PASS" "$HOST"
}
function upload_via_ssh() {
require rsync
require sshpass
PASSWORD_FILE=$(mktemp -p /tmp my_litte_secret.XXXXXX) || exit 2
chmod 600 "$PASSWORD_FILE"
echo -n "$PASS" > "$PASSWORD_FILE"
# [[ "${SRC}" != */ ]] && SRC="${SRC}/" # append trailing slash if there is none
[[ "${SRC}" == */ ]] && SRC="${SRC: : -1}" # remove trailing slash if there is one
# Avoid password prompt: https://unix.stackexchange.com/a/111534/119362
# sshpass -p $(cat "$PASSWORD_FILE") scp -r "$SRC/." "$USER@$HOST:/$DST"
# sshpass -p $(cat "$PASSWORD_FILE") rsync -rL --progress "$SRC/." "$USER@$HOST:$DST"
rsync -urL --progress "$SRC/." "$USER@$HOST:$DST"
rm "$PASSWORD_FILE"
}
function main() {
SERVER="$1"
case $SERVER in
"strato" )
echo "Uploading to Strato..."
USER=$(pass strato/flipsi | grep ssh-user | cut -f2 -d' ')
HOST=$(pass strato/flipsi | grep ssh-host | cut -f2 -d' ')
PASS=$(pass strato/flipsi | head -n1 | tr -d '\n')
SRC="target/"
DST="www/"
upload_via_ssh
;;
"bplaced" )
echo "Uploading to bplaced..."
USER=$(pass bplaced.net/gmail | grep login | cut -f2 -d' ')
PASS=$(pass bplaced.net/gmail | head -n1 | tr -d '\n')
SRC="target/"
HOST="sflip.bplaced.net"
DST="/www/"
upload_via_ftp
;;
* )
echo "No server given. Provide 'strato' or 'bplaced' as argument."
exit 1
esac
}
main "$@"