@@ -16,8 +16,6 @@ Cyan='\033[0;36m' # Cyan
16
16
White=' \033[0;37m' # White
17
17
18
18
set -o pipefail
19
- # readonly file="$2"
20
- # readonly u_folder="$3"
21
19
readonly status_dir=" $( mktemp -d) "
22
20
23
21
trap " rm -rf $status_dir " EXIT
@@ -74,18 +72,23 @@ setup () {
74
72
echo " Setup Completed"
75
73
}
76
74
75
+ # Generates new filename with random strings at last (before extension if present).
76
+ # new name for 'myfile.txt' -> 'myfile-78e11b8c.txt'
77
+ # new name for 'myfile' -> 'myfile-78e11b8c'
77
78
add_random_string () {
78
79
local filename=" $1 "
79
80
local extension=" ${filename##* .} "
80
81
local name=" ${filename% .* } "
81
82
local random_string=" $( date +%s | sha256sum | base64 | head -c 8) "
82
- if [ " $extension " == " $filename " ]; then
83
- new_filename=" $name -$random_string "
83
+ if [ -z " $extension " ]; then
84
+ new_filename=" $name -$random_string "
84
85
else
85
- new_filename=" $name -$random_string .$extension "
86
+ new_filename=" $name -$random_string .$extension "
86
87
fi
87
88
}
88
89
90
+ # Simple progressbar animation.
91
+ # Usage : progress_bar ${percentage} ${upload_speed} $(eta) ${status}
89
92
progress_bar () {
90
93
if [ " $( tput cols) " -lt 84 ]; then
91
94
[ -z $1 ] && set -- " (Starting)" " ..." " ..." " ..."
@@ -118,6 +121,7 @@ progress_bar() {
118
121
fi
119
122
}
120
123
124
+ # Upload file to give folder and use new filename if -r argument was passed and printing out new animation.
121
125
rclone_progress_bar () {
122
126
tput civis
123
127
echo " Starting download..."
@@ -137,6 +141,8 @@ rclone_progress_bar() {
137
141
done # || echo -ne "\rDownload Can't be completed, Check download link." && tput cnorm && exit 1
138
142
tput cnorm
139
143
}
144
+
145
+ # Final part of animation if upload was succesfull.
140
146
end_animation () {
141
147
tput civis
142
148
@@ -207,6 +213,7 @@ function url_encode() {
207
213
-e ' s/~/%7e/g'
208
214
}
209
215
216
+ # rclone_progress_bar -> progress_bar -> end_animation -> Print dowload link.
210
217
upload () {
211
218
echo " Initializing process, might take up to 10 seconds..."
212
219
rclone_progress_bar
@@ -224,20 +231,29 @@ upload () {
224
231
225
232
help () {
226
233
echo "
234
+ ${aqua} Usage : ksau [OPTION]... [FILE]...${normal}
235
+
236
+ ${aqua} upload [FILE] [FOLDER]${normal} : Uploads the given file to the given folder
237
+ on index.
238
+
239
+ ${aqua} upload -r [FILE] [FOLDER]${normal} : Uploads the given file to the given folder
240
+ but with new filename with random strings
241
+ at last (before extension if present).
242
+
243
+ ${aqua} setup${normal} : Recquired while using first time.
227
244
228
- ${aqua} Usage : ksau <options> <params>${normal}
245
+ ${aqua} update${normal} : Fetch and install latest version
246
+ available.
229
247
230
- ${aqua} upload <filename> <folder to upload>${normal} : Uploads the given file to the given folder.
231
- ${aqua} setup${normal} : Recquired while using first time.
232
- ${aqua} update${normal} : Fetch and install latest version available.
233
- ${aqua} dependencies${normal} : Installs recquired dependencies.
234
- ${aqua} help${normal} : To get this message.
235
- ${aqua} version${normal} : To get version info.
248
+ ${aqua} dependencies${normal} : Installs recquired dependencies.
249
+
250
+ ${aqua} help${normal} : To get this message.
251
+
252
+ ${aqua} version${normal} : To get version info.
236
253
237
254
Example : ${lightgreen} ksau upload test.txt Public
238
255
239
256
${orange} Tool By Sauraj (@Ksauraj)${normal}
240
-
241
257
"
242
258
}
243
259
@@ -254,7 +270,7 @@ update () {
254
270
}
255
271
256
272
version () {
257
- echo " ${orange} Version - 1.5 (Stable) ${normal} "
273
+ echo " ${orange} Version - 1.5.1 (Stable) ${normal} "
258
274
}
259
275
260
276
if [[ $1 == " upload" ]]; then
0 commit comments