Skip to content

Commit a4d74f8

Browse files
committed
feat: add tusc --update
1 parent ea670e1 commit a4d74f8

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

tusc.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# TUS client protocol implementation for bash.
3+
# TUS client 1.0.0 protocol implementation for bash.
44
#
55
# Author:
66
# Jitendra Adhikari <jiten.adhikary@gmail.com>
@@ -26,6 +26,20 @@ comment() { line "$1" 30 1; }
2626
# show version
2727
version() { echo v0.1.1; }
2828

29+
# update tusc
30+
update()
31+
{
32+
NEWVER=`curl -sSL https://raw.githubusercontent.com/adhocore/tusc.sh/master/VERSION`
33+
if [ "v$NEWVER" == "$(version)" ]; then
34+
ok "Already latest version"
35+
return 0
36+
fi
37+
38+
info "Updating $TUSC ..."
39+
curl -sSLo ${FULL} https://raw.githubusercontent.com/adhocore/tusc.sh/master/tusc.sh
40+
ok " Done [${NEWVER}]"
41+
}
42+
2943
# show usage
3044
usage()
3145
{
@@ -44,9 +58,11 @@ usage()
4458
$(info "-f --file") $(comment "The file to upload.")
4559
$(info "-h --help") $(comment "Show help information and usage.")
4660
$(info "-H --host") $(comment "The tus-server host where file is uploaded.")
61+
$(info "-u --update") $(comment "Update tusc to latest version.")
4762
4863
$(ok Examples:)
4964
$TUSC --help # shows this help
65+
$TUSC --update # updates itself
5066
$TUSC --version # prints current version of itself
5167
$TUSC 0:1080 ww.mp4 # uploads ww.mp4 to http://0.0.0.0:1080/files/
5268
$TUSC -H 0:1080 -f ww.mp4 # same as above
@@ -114,8 +130,6 @@ on-exit()
114130
fi
115131
}
116132

117-
trap on-exit EXIT
118-
119133
# argv parsing
120134
while [[ $# -gt 0 ]]; do
121135
case "$1" in
@@ -124,6 +138,7 @@ while [[ $# -gt 0 ]]; do
124138
-f | --file) FILE="$2"; shift 2 ;;
125139
-h | --help | help) usage $1; exit 0 ;;
126140
-H | --host) HOST="$2"; shift 2 ;;
141+
-u | --update) update; exit 0 ;;
127142
--version | version) version; exit 0 ;;
128143
*) if [[ $HOST ]]; then
129144
if [[ $FILE ]]; then SUMALGO="${SUMALGO:-$1}"; else FILE="$1"; fi
@@ -132,6 +147,8 @@ while [[ $# -gt 0 ]]; do
132147
esac
133148
done
134149

150+
trap on-exit EXIT
151+
135152
[[ $HOST ]] || error "--host required" 1
136153
[[ $FILE ]] || error "--file required" 1
137154
[[ -f $FILE ]] || error "--file doesnt exist" 1

0 commit comments

Comments
 (0)