-
Notifications
You must be signed in to change notification settings - Fork 0
/
joffeshort
executable file
·51 lines (36 loc) · 1.07 KB
/
joffeshort
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
#!/bin/bash
set -ueo pipefail
# See .joffeshort.env.sample for sample config
# assign REMOTE_HOST, REMOTE_FOLDER variables
source .joffeshort.env
read -r -d '' USAGE << EOM || true
$(basename $0) SOURCE_FILE REMOTE_NAME
Quickly upload a file to my server
uses:
* create short URL to print something
EOM
usage.sh "$USAGE" $@ && exit
[ $# -lt 1 ] && $0 --help && exit
function lsUpdate() {
#shellcheck disable=SC2029
ssh $REMOTE_HOST "ls -lh $REMOTE_FOLDER > $REMOTE_FOLDER/ls.txt" # add public directory listing
}
function lsRemote() {
lsUpdate
#shellcheck disable=SC2029
ssh $REMOTE_HOST "ls -lh $REMOTE_FOLDER" # show short files
}
[ "$1" = "ls" ] && lsRemote && exit
if [ "$1" = "rm" ]; then
#shellcheck disable=SC2029
ssh $REMOTE_HOST "rm $REMOTE_FOLDER/$2"
lsRemote
exit
fi
sourceFile=${1??Enter a source file}
remoteName=${2??Enter the short remote name}
remotePath="$REMOTE_FOLDER/$remoteName"
rsync -avz "$sourceFile" "$REMOTE_HOST:$remotePath"
#shellcheck disable=SC2029
ssh $REMOTE_HOST "chmod ugo+r $remotePath" # make sure permissions allow reading
lsUpdate