@@ -20,71 +20,68 @@ readonly status_dir="$(mktemp -d)"
20
20
21
21
trap " rm -rf $status_dir " EXIT
22
22
23
- dependencies () {
24
- echo " "
25
- echo " Make sure you have sudo privilages"
26
- echo " This will only work for Linux/macOS/BSD systems."
27
- echo " "
28
- sudo curl https://rclone.org/install.sh 2> /dev/null | sudo bash > /dev/null 2>&1
29
- echo " "
30
- echo " ${orange} Please install jq manually, No script found"
31
- echo " Possibly with
23
+ dependencies () {
24
+ echo " "
25
+ echo " Make sure you have sudo privilages"
26
+ echo " This will only work for Linux/macOS/BSD systems."
27
+ echo " "
28
+ sudo curl https://rclone.org/install.sh 2> /dev/null | sudo bash > /dev/null 2>&1
29
+ echo " "
30
+ echo " ${orange} Please install jq manually, No script found"
31
+ echo " Possibly with
32
32
${aqua} sudo apt-get install jq ${normal} OR
33
33
${aqua} sudo pacman -S jq ${normal} OR
34
34
${aqua} sudo dnf install jq ${normal} OR
35
35
${aqua} sudo zypper install jq ${normal} OR
36
36
${aqua} apk add jq ${normal} OR
37
37
${aqua} pkg install jq${normal} "
38
- echo ' '
38
+ echo ' '
39
39
}
40
40
41
- setup () {
42
- mkdir -p ~ /.config/rclone
43
- rm ~ /.config/rclone/rclone.conf > /dev/null 2>&1
44
- if ! command -v wget & > /dev/null
45
- then
46
- echo " ${aqua} Does this machine even have simple pkgs installed?"
47
- echo " Please install ${orange} wget ${aqua} manually and continue...${normal} "
48
- exit
49
- fi
50
- wget https://gist.githubusercontent.com/noobyysauraj/cf531848e0d849296406d38a98b2a544/raw/rclone.conf > /dev/null 2>&1
51
- mv rclone.conf ~ /.config/rclone
52
- if ! command -v rclone & > /dev/null
53
- then
54
- echo " ${aqua} Dependencies not found. Make sure to proceed with the command 'ksau dependencies'"
55
- echo " ${aqua} OR manually install ${orange} rclone ${aqua} and ${orange} jq${normal} "
56
- exit
57
- else
58
- if ! command -v jq & > /dev/null
59
- then
60
- echo " ${aqua} Dependencies not found. Make sure to proceed with the command 'ksau dependencies'"
61
- echo " ${aqua} Please install jq manually, No script found"
62
- echo " Possibly with
41
+ setup () {
42
+ mkdir -p ~ /.config/rclone
43
+ rm ~ /.config/rclone/rclone.conf > /dev/null 2>&1
44
+ if ! command -v wget & > /dev/null; then
45
+ echo " ${aqua} Does this machine even have simple pkgs installed?"
46
+ echo " Please install ${orange} wget ${aqua} manually and continue...${normal} "
47
+ exit
48
+ fi
49
+ wget https://gist.githubusercontent.com/noobyysauraj/cf531848e0d849296406d38a98b2a544/raw/rclone.conf > /dev/null 2>&1
50
+ mv rclone.conf ~ /.config/rclone
51
+ if ! command -v rclone & > /dev/null; then
52
+ echo " ${aqua} Dependencies not found. Make sure to proceed with the command 'ksau dependencies'"
53
+ echo " ${aqua} OR manually install ${orange} rclone ${aqua} and ${orange} jq${normal} "
54
+ exit
55
+ else
56
+ if ! command -v jq & > /dev/null; then
57
+ echo " ${aqua} Dependencies not found. Make sure to proceed with the command 'ksau dependencies'"
58
+ echo " ${aqua} Please install jq manually, No script found"
59
+ echo " Possibly with
63
60
${aqua} sudo apt-get install jq ${normal} OR
64
61
${aqua} sudo pacman -S jq ${normal} OR
65
62
${aqua} sudo dnf install jq ${normal} OR
66
63
${aqua} sudo zypper install jq ${normal} OR
67
64
${aqua} apk add jq ${normal} OR
68
65
${aqua} pkg install jq${normal} "
69
- exit
70
- fi
71
- fi
72
- echo " Setup Completed"
66
+ exit
67
+ fi
68
+ fi
69
+ echo " Setup Completed"
73
70
}
74
71
75
72
# Generates new filename with random strings at last (before extension if present).
76
73
# new name for 'myfile.txt' -> 'myfile-78e11b8c.txt'
77
74
# new name for 'myfile' -> 'myfile-78e11b8c'
78
75
add_random_string () {
79
- local filename=" $1 "
80
- local extension=" ${filename##* .} "
81
- local name=" ${filename% .* } "
82
- local random_string=" $( date +%s | sha256sum | base64 | head -c 8) "
83
- if [ -z " $extension " ]; then
84
- new_filename=" $name -$random_string "
85
- else
86
- new_filename=" $name -$random_string .$extension "
87
- fi
76
+ local filename=" $1 "
77
+ local extension=" ${filename##* .} "
78
+ local name=" ${filename% .* } "
79
+ local random_string=" $( date +%s | sha256sum | base64 | head -c 8) "
80
+ if [ -z " $extension " ]; then
81
+ new_filename=" $name -$random_string "
82
+ else
83
+ new_filename=" $name -$random_string .$extension "
84
+ fi
88
85
}
89
86
90
87
# Simple progressbar animation.
@@ -128,14 +125,14 @@ rclone_progress_bar() {
128
125
rm -f log
129
126
touch log
130
127
if [ -z " $new_filename " ]; then new_filename=$( basename " $file " ) ; fi
131
- rclone -P --checkers=32 --onedrive-chunk-size 60M copyto " $file " oned:/" ${u_folder} " /" $new_filename " | tee log > /dev/null || touch " $status_dir /failed" &
128
+ rclone -P --checkers=32 --onedrive-chunk-size 60M copyto " $file " oned:/" ${u_folder} " /" $new_filename " | tee log > /dev/null || touch " $status_dir /failed" &
132
129
until [ -z " $( jobs -r) " ]; do
133
130
if [ -f " $status_dir /failed" ]; then
134
131
echo
135
132
echo " ${Red} Upload failed!${Normal} "
136
133
break
137
134
fi
138
- show_bar=$( progress_bar $( grep -Eo ' [0-9]{1,3}' % log | tail -n1 | cut -d ' %' -f 1) $( grep ' ETA' log | tail -n1 | cut -d ' ,' -f5) $( grep ' ETA' log | tail -n1 | cut -d ' ,' -f6 | sed ' s/ETA //' ) $( grep ' ETA' log | tail -n1 | cut -d ' ,' -f3 | sed ' s/^.* //' ) )
135
+ show_bar=$( progress_bar $( grep -Eo ' [0-9]{1,3}' % log | tail -n1 | cut -d ' %' -f 1) $( grep ' ETA' log | tail -n1 | cut -d ' ,' -f5) $( grep ' ETA' log | tail -n1 | cut -d ' ,' -f6 | sed ' s/ETA //' ) $( grep ' ETA' log | tail -n1 | cut -d ' ,' -f3 | sed ' s/^.* //' ) )
139
136
echo -ne " \r$show_bar "
140
137
sleep 0.1
141
138
done # || echo -ne "\rDownload Can't be completed, Check download link." && tput cnorm && exit 1
@@ -174,63 +171,61 @@ end_animation() {
174
171
tput cnorm
175
172
}
176
173
177
-
178
-
179
174
# Below function is copied from - https://gist.github.com/jaytaylor/5a90c49e0976aadfe0726a847ce58736
180
175
# Credit to @jkishner for https://gist.github.com/jkishner/2fccb24640a27c2d7ac9
181
176
function url_encode() {
182
- echo " $@ " \
183
- | sed \
184
- -e ' s/%/%25/g' \
185
- -e ' s/ /%20/g' \
186
- -e ' s/!/%21/g' \
187
- -e ' s/"/%22/g' \
188
- -e " s/'/%27/g" \
189
- -e ' s/#/%23/g' \
190
- -e ' s/(/%28/g' \
191
- -e ' s/)/%29/g' \
192
- -e ' s/+/%2b/g' \
193
- -e ' s/,/%2c/g' \
194
- -e ' s/-/%2d/g' \
195
- -e ' s/:/%3a/g' \
196
- -e ' s/;/%3b/g' \
197
- -e ' s/?/%3f/g' \
198
- -e ' s/@/%40/g' \
199
- -e ' s/\$/%24/g' \
200
- -e ' s/\&/%26/g' \
201
- -e ' s/\*/%2a/g' \
202
- -e ' s/\./%2e/g' \
203
- -e ' s/\//%2f/g' \
204
- -e ' s/\[/%5b/g' \
205
- -e ' s/\\/%5c/g' \
206
- -e ' s/\]/%5d/g' \
207
- -e ' s/\^/%5e/g' \
208
- -e ' s/_/%5f/g' \
209
- -e ' s/`/%60/g' \
210
- -e ' s/{/%7b/g' \
211
- -e ' s/|/%7c/g' \
212
- -e ' s/}/%7d/g' \
213
- -e ' s/~/%7e/g'
177
+ echo " $@ " |
178
+ sed \
179
+ -e ' s/%/%25/g' \
180
+ -e ' s/ /%20/g' \
181
+ -e ' s/!/%21/g' \
182
+ -e ' s/"/%22/g' \
183
+ -e " s/'/%27/g" \
184
+ -e ' s/#/%23/g' \
185
+ -e ' s/(/%28/g' \
186
+ -e ' s/)/%29/g' \
187
+ -e ' s/+/%2b/g' \
188
+ -e ' s/,/%2c/g' \
189
+ -e ' s/-/%2d/g' \
190
+ -e ' s/:/%3a/g' \
191
+ -e ' s/;/%3b/g' \
192
+ -e ' s/?/%3f/g' \
193
+ -e ' s/@/%40/g' \
194
+ -e ' s/\$/%24/g' \
195
+ -e ' s/\&/%26/g' \
196
+ -e ' s/\*/%2a/g' \
197
+ -e ' s/\./%2e/g' \
198
+ -e ' s/\//%2f/g' \
199
+ -e ' s/\[/%5b/g' \
200
+ -e ' s/\\/%5c/g' \
201
+ -e ' s/\]/%5d/g' \
202
+ -e ' s/\^/%5e/g' \
203
+ -e ' s/_/%5f/g' \
204
+ -e ' s/`/%60/g' \
205
+ -e ' s/{/%7b/g' \
206
+ -e ' s/|/%7c/g' \
207
+ -e ' s/}/%7d/g' \
208
+ -e ' s/~/%7e/g'
214
209
}
215
210
216
211
# rclone_progress_bar -> progress_bar -> end_animation -> Print dowload link.
217
- upload () {
218
- echo " Initializing process, might take up to 10 seconds..."
219
- rclone_progress_bar
220
- wait
221
- if [ -f " $status_dir /failed" ]; then
222
- echo -e " \rUpload Failed .......\n"
223
- exit 1
224
- fi
225
- end_animation
226
- url_file=$( url_encode " ${new_filename} " )
227
- url_folder=$( jq -rn --arg x " ${u_folder%/ } " ' $x|@uri' )
228
- echo " Upload Completed "
229
- echo " Download link - ${lightgreen} https://index.sauraj.eu.org/${url_folder} /${url_file}${normal} "
212
+ upload () {
213
+ echo " Initializing process, might take up to 10 seconds..."
214
+ rclone_progress_bar
215
+ wait
216
+ if [ -f " $status_dir /failed" ]; then
217
+ echo -e " \rUpload Failed .......\n"
218
+ exit 1
219
+ fi
220
+ end_animation
221
+ url_file=$( url_encode " ${new_filename} " )
222
+ url_folder=$( jq -rn --arg x " ${u_folder%/ } " ' $x|@uri' )
223
+ echo " Upload Completed "
224
+ echo " Download link - ${lightgreen} https://index.sauraj.eu.org/${url_folder} /${url_file}${normal} "
230
225
}
231
226
232
- help () {
233
- echo "
227
+ help () {
228
+ echo "
234
229
${aqua} Usage : ksau [OPTION]... [FILE]...${normal}
235
230
236
231
${aqua} upload [FILE] [FOLDER]${normal} : Uploads the given file to the given folder
@@ -255,22 +250,22 @@ Example : ${lightgreen}ksau upload test.txt Public
255
250
256
251
${orange} Tool By Sauraj (@Ksauraj)${normal}
257
252
"
258
- }
253
+ }
259
254
260
- update () {
261
- echo " ${orange} Current" " $( ksau version) "
262
- echo " ${orange} Fetching latest version.${normal} "
263
- curl https://raw.githubusercontent.com/noobyysauraj/global_index_source/master/ksau > ksau 2> /dev/null
264
- sudo rm /usr/local/bin/ksau
265
- sudo mv ksau /usr/local/bin
266
- chmod +x /usr/local/bin/ksau
267
- echo " ${orange} Update Finished${normal} "
268
- echo " ${orange} Updated to" " $( ksau version) "
269
- echo " ${normal} "
255
+ update () {
256
+ echo " ${orange} Current" " $( ksau version) "
257
+ echo " ${orange} Fetching latest version.${normal} "
258
+ curl https://raw.githubusercontent.com/noobyysauraj/global_index_source/master/ksau > ksau 2> /dev/null
259
+ sudo rm /usr/local/bin/ksau
260
+ sudo mv ksau /usr/local/bin
261
+ chmod +x /usr/local/bin/ksau
262
+ echo " ${orange} Update Finished${normal} "
263
+ echo " ${orange} Updated to" " $( ksau version) "
264
+ echo " ${normal} "
270
265
}
271
266
272
- version () {
273
- echo " ${orange} Version - 1.5.1 (Stable) ${normal} "
267
+ version () {
268
+ echo " ${orange} Version - 1.5.1 (Stable) ${normal} "
274
269
}
275
270
276
271
if [[ $1 == " upload" ]]; then
301
296
echo " Unknown Argument passed."
302
297
help
303
298
fi
304
-
0 commit comments