Skip to content

Commit ee91ad0

Browse files
committed
feat: add locate command, show location when finished
1 parent d9ce486 commit ee91ad0

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

tusc.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ USAGE
7272
}
7373

7474
# get/set tus config
75-
tus-config()
75+
tus-config() # $1 = key, $2 = value
7676
{
7777
TUSFILE=`realpath ~/.tus.json`
7878
if [ ! -f $TUSFILE ]; then echo '{}' > $TUSFILE; fi
@@ -120,14 +120,15 @@ request()
120120
on-exit()
121121
{
122122
rm -f $FILE.part $HFILE
123-
[[ $CHKSUM ]] || return 0
123+
[[ $OFFSET ]] || return 0
124124

125125
OFFSET=${HEADERS[Upload-Offset]:-0} LEFTOVER=$((SIZE - OFFSET))
126126
if [[ $LEFTOVER -eq 0 ]]; then
127127
ok "Uploaded successfully!"
128128
else
129-
info "Unfinished upload, please rerun the command to resume."
129+
error "Unfinished upload, please rerun the command to resume."
130130
fi
131+
info "URL: $TUSURL"
131132
}
132133

133134
# argv parsing
@@ -138,6 +139,7 @@ while [[ $# -gt 0 ]]; do
138139
-f | --file) FILE="$2"; shift 2 ;;
139140
-h | --help | help) usage $1; exit 0 ;;
140141
-H | --host) HOST="$2"; shift 2 ;;
142+
locate) LOCATE=1; shift ;;
141143
-u | --update) update; exit 0 ;;
142144
--version | version) version; exit 0 ;;
143145
*) if [[ $HOST ]]; then
@@ -149,15 +151,14 @@ done
149151

150152
trap on-exit EXIT
151153

152-
[[ $HOST ]] || error "--host required" 1
154+
[[ $HOST ]] || [[ $LOCATE ]] || error "--host required" 1
153155
[[ $FILE ]] || error "--file required" 1
154156
[[ -f $FILE ]] || error "--file doesnt exist" 1
155157

156158
SUMALGO=${SUMALGO:-sha1}
157-
[[ $SUMALGO == "sha"* ]] || error "--algo not supported" 1
159+
[[ $SUMALGO == "sha"* ]] || error "--algo '$SUMALGO' not supported" 1
158160

159161
FILE=`realpath $FILE` NAME=`basename $FILE` SIZE=`stat -c %s $FILE` HFILE=`mktemp -t tus.XXXXXXXXXX`
160-
161162
[[ $DEBUG -eq 1 ]] && info "Host: $HOST | Header: $HFILE\nFile: $NAME | Size: $SIZE"
162163

163164
# calc key &/or checksum
@@ -168,6 +169,7 @@ CHKSUM="$SUMALGO $(echo -n $KEY | base64 -w 0)"
168169

169170
# head request
170171
TUSURL=`tus-config ".[\"$KEY\"].location?"`
172+
[[ $LOCATE ]] && info "URL: $TUSURL" && [[ $TUSURL != "null" ]]; exit $?
171173
[[ "null" != "$TUSURL" ]] && request "--head $TUSURL"
172174

173175
if [[ "null" != "$TUSURL" ]] && [[ $ISOK -eq 1 ]]; then

0 commit comments

Comments
 (0)