Skip to content

Commit 6cf2312

Browse files
authored
Merge pull request #13 from adhocore/10-12-auth
Support custom auth (or curl args)
2 parents a1c2499 + 9b7160f commit 6cf2312

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ script:
2121

2222
# upload
2323
- './tusd_linux_amd64/tusd --upload-dir ~/.tusd-data --base-path /tus/ > /dev/null 2>&1 &'
24-
- './tusc.sh -H 0:1080 -f tusd_linux_amd64.tar.gz -a sha256 -b /tus/'
24+
- './tusc.sh -H 0:1080 -f tusd_linux_amd64.tar.gz -a sha256 -b /tus/ -- -v'
2525

2626
# download and verify
2727
- 'URL=$(./tusc.sh -H 0:1080 -f tusd_linux_amd64.tar.gz -a sha256 -b /tus/ -L -C -S | cut -c 6-999)'

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ chmod +x ~/tusc && mv ~/tusc ~/.local/bin/tusc
4545
tusc is bash implementation of tus-client (https://tus.io).
4646
4747
Usage:
48-
tusc <--options>
49-
tusc <host> <file> [algo]
48+
tusc <--options> -- [curl args]
49+
tusc <host> <file> [algo] -- [curl args]
5050
5151
Options:
5252
-a --algo The algorigthm for key &/or checksum.
@@ -70,8 +70,8 @@ chmod +x ~/tusc && mv ~/tusc ~/.local/bin/tusc
7070
tusc --version # prints current version of itself
7171
tusc 0:1080 ww.mp4 # uploads ww.mp4 to http://0.0.0.0:1080/files/
7272
tusc -H 0:1080 -f ww.mp4 # same as above
73+
tusc -H 0:1080 -f ww.mp4 -- -Lv # same as above plus sends -Lv to curl command
7374
tusc -H 0:1080 -f ww.mp4 -a sha256 # same as above but uses sha256 algo for key/checksum
74-
tusc -H 0:1080 -f ww.mp4 -b /store/ # uploads ww.mp4 to http://0.0.0.0:1080/store/
7575
```
7676

7777
If you want to parse the output of `tusc`, pass in `-C` (no color) and `-S` (no spin) flags. Eg:
@@ -80,6 +80,15 @@ If you want to parse the output of `tusc`, pass in `-C` (no color) and `-S` (no
8080
wget $(tusc -H 0:1080 -f ww.mp4 -L -S -C | cut -c 6-999) -O ww.mp4.1
8181
```
8282

83+
### Authentication
84+
85+
If your tusd server requires special header or token for auth, just pass in `[curl args]`:
86+
```sh
87+
tusc -H 0:1080 -f ww.mp4 -b /store/ -- -H 'Authorization: Bearer <token>'
88+
```
89+
90+
In fact you can pass in anything after `--` as extra curl parameter.
91+
8392
### Preview
8493
See `tusc` in action with debug mode where the upload is aborted frequently with `Ctrl+C` interrupt.
8594

tusc.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
if [[ -f ~/.tus.dbg ]]; then set -ex; else set -e; fi
1212

13-
FULL=$(readlink -f $0) TUSC=$(basename $0) SPINID=0
13+
FULL=$(readlink -f $0) TUSC=$(basename $0) SPINID=0 CURLARGS=
1414

1515
declare -A HEADERS # assoc headers of last request
1616
declare ISOK=0 # is last request ok?
@@ -107,7 +107,7 @@ request()
107107
echo > $HEADER
108108
[[ $CREDS ]] && USERPASS="--basic --user '$USER:$PASS' "
109109
[[ $DEBUG ]] && comment "> curl ${USERPASS//:$PASS/}-sSLD $HEADER -H 'Tus-Resumable: 1.0.0' $1"
110-
BODY=$(bash -c "curl $USERPASS-sSLD $HEADER -H 'Tus-Resumable: 1.0.0' $1") HEADERS=()
110+
BODY=$(bash -c "curl $USERPASS-sSLD $HEADER -H 'Tus-Resumable: 1.0.0' $CURLARGS $1") HEADERS=()
111111

112112
while IFS=':' read key value; do
113113
if [[ "${key:0:5}" == "HTTP/" ]]; then
@@ -178,6 +178,7 @@ while [[ $# -gt 0 ]]; do
178178
-S | --no-spin) NOSPIN=1; shift ;;
179179
-u | --update) update; exit 0 ;;
180180
--version | version) version; exit 0 ;;
181+
--) shift; CURLARGS=$@; break ;;
181182
*) if [[ $HOST ]]; then
182183
if [[ $FILE ]]; then SUMALGO="${SUMALGO:-$1}"; else FILE="$1"; fi
183184
else HOST=$1; fi

0 commit comments

Comments
 (0)