@@ -19,11 +19,24 @@ Purple='\033[0;35m' # Purple
19
19
Cyan=' \033[0;36m' # Cyan
20
20
White=' \033[0;37m' # White
21
21
22
+ UPLINE=$( tput cuu1)
23
+ CLEARLINE=$( tput el)
24
+
22
25
set -o pipefail
23
26
readonly status_dir=" $( mktemp -d) "
24
27
25
28
trap " rm -rf $status_dir " EXIT
26
29
30
+ upline () {
31
+ for _ in $( seq $1 ) ; do
32
+ echo -ne " $UPLINE "
33
+ done
34
+ }
35
+
36
+ clearline () {
37
+ echo -ne " $CLEARLINE "
38
+ }
39
+
27
40
dependencies () {
28
41
if declare -p TERMUX_VERSION & > /dev/null; then
29
42
echo " Starting Installation...."
@@ -100,41 +113,35 @@ add_random_string() {
100
113
# Simple progressbar animation.
101
114
# Usage : progress_bar ${percentage} ${upload_speed} $(eta) ${status}
102
115
progress_bar () {
103
- if [ " $( tput cols) " -lt 84 ]; then
104
- [ -z $1 ] && set -- " (Starting)" " ..." " ..." " ..."
105
- echo " ${Green}${1} % UPS: ${Cyan} 2 ${Yellow} ETA: ${3} STATUS: ${Cyan}${4}${Normal} "
106
- return
107
- fi
108
-
109
116
if [[ ${1} < 10 ]]; then
110
- echo " ${Yellow} Progress ${Green} [=>---------${Cyan}${1} %${Normal}${Green} ---------<=] ${Yellow} UPS: ${Cyan}${2} ${Yellow} ETA: ${Cyan}${3} ${Yellow} STATUS: ${Cyan}${4}${Normal} "
117
+ echo " ${Yellow} Progress ${Green} [=>---------${Cyan}${1} %${Normal}${Green} ---------<=]"
111
118
elif [[ ${1} -lt 20 ]]; then
112
- echo " ${Yellow} Progress ${Green} [==>--------${Cyan}${1} %${Normal}${Green} --------<==] ${Yellow} UPS: ${Cyan}${2} ${Yellow} ETA: ${Cyan}${3} ${Yellow} STATUS: ${Cyan}${4}${Normal} "
119
+ echo " ${Yellow} Progress ${Green} [==>--------${Cyan}${1} %${Normal}${Green} --------<==]"
113
120
elif [[ ${1} -lt 30 ]]; then
114
- echo " ${Yellow} Progress ${Green} [===>-------${Cyan}${1} %${Normal}${Green} -------<===] ${Yellow} UPS: ${Cyan}${2} ${Yellow} ETA: ${Cyan}${3} ${Yellow} STATUS: ${Cyan}${4}${Normal} "
121
+ echo " ${Yellow} Progress ${Green} [===>-------${Cyan}${1} %${Normal}${Green} -------<===]"
115
122
elif [[ ${1} -lt 40 ]]; then
116
- echo " ${Yellow} Progress ${Green} [====>------${Cyan}${1} %${Normal}${Green} ------<====] ${Yellow} UPS: ${Cyan}${2} ${Yellow} ETA: ${Cyan}${3} ${Yellow} STATUS: ${Cyan}${4}${Normal} "
123
+ echo " ${Yellow} Progress ${Green} [====>------${Cyan}${1} %${Normal}${Green} ------<====]"
117
124
elif [[ ${1} -lt 50 ]]; then
118
- echo " ${Yellow} Progress ${Green} [=====>-----${Cyan}${1} %${Normal}${Green} -----<=====] ${Yellow} UPS: ${Cyan}${2} ${Yellow} ETA: ${Cyan}${3} ${Yellow} STATUS: ${Cyan}${4}${Normal} "
125
+ echo " ${Yellow} Progress ${Green} [=====>-----${Cyan}${1} %${Normal}${Green} -----<=====]"
119
126
elif [[ ${1} -lt 60 ]]; then
120
- echo " ${Yellow} Progress ${Green} [======>----${Cyan}${1} %${Normal}${Green} ----<======] ${Yellow} UPS: ${Cyan}${2} ${Yellow} ETA: ${Cyan}${3} ${Yellow} STATUS: ${Cyan}${4}${Normal} "
127
+ echo " ${Yellow} Progress ${Green} [======>----${Cyan}${1} %${Normal}${Green} ----<======]"
121
128
elif [[ ${1} -lt 70 ]]; then
122
- echo " ${Yellow} Progress ${Green} [=======>---${Cyan}${1} %${Normal}${Green} ---<=======] ${Yellow} UPS: ${Cyan}${2} ${Yellow} ETA: ${Cyan}${3} ${Yellow} STATUS: ${Cyan}${4}${Normal} "
129
+ echo " ${Yellow} Progress ${Green} [=======>---${Cyan}${1} %${Normal}${Green} ---<=======]"
123
130
elif [[ ${1} -lt 80 ]]; then
124
- echo " ${Yellow} Progress ${Green} [========>--${Cyan}${1} %${Normal}${Green} --<========] ${Yellow} UPS: ${Cyan}${2} ${Yellow} ETA: ${Cyan}${3} ${Yellow} STATUS: ${Cyan}${4}${Normal} "
131
+ echo " ${Yellow} Progress ${Green} [========>--${Cyan}${1} %${Normal}${Green} --<========]"
125
132
elif [[ ${1} -lt 90 ]]; then
126
- echo " ${Yellow} Progress ${Green} [=========>-${Cyan}${1} %${Normal}${Green} -<=========] ${Yellow} UPS: ${Cyan}${2} ${Yellow} ETA: ${Cyan}${3} ${Yellow} STATUS: ${Cyan}${4}${Normal} "
133
+ echo " ${Yellow} Progress ${Green} [=========>-${Cyan}${1} %${Normal}${Green} -<=========]"
127
134
elif [[ ${1} -lt 100 ]]; then
128
- echo " ${Yellow} Progress ${Green} [==========>${Cyan}${1} %${Normal}${Green} <==========] ${Yellow} UPS: ${Cyan}${2} ${Yellow} ETA: ${Cyan}${3} ${Yellow} STATUS: ${Cyan}${4}${Normal} "
135
+ echo " ${Yellow} Progress ${Green} [==========>${Cyan}${1} %${Normal}${Green} <==========]"
129
136
elif [[ ${1} == 100 ]]; then
130
- echo " ${Yellow} Progress ${Green} [===========${Cyan}${1} %${Normal}${Green} ===========] ${Yellow} UPS: ${Cyan}${2} ${Yellow} ETA: ${Cyan}${3} ${Yellow} STATUS: ${Cyan}${4}${Normal} "
137
+ echo " ${Yellow} Progress ${Green} [===========${Cyan}${1} %${Normal}${Green} ===========]"
131
138
fi
132
139
}
133
140
134
141
# Upload file to give folder and use new filename if -r argument was passed and printing out new animation.
135
142
rclone_progress_bar () {
136
143
tput civis
137
- echo " Starting download ..."
144
+ echo " Starting upload ..."
138
145
rm -f log
139
146
touch log
140
147
if [ -z " $new_filename " ]; then new_filename=$( basename " $file " ) ; fi
@@ -145,45 +152,20 @@ rclone_progress_bar() {
145
152
echo " ${Red} Upload failed!${Normal} "
146
153
break
147
154
fi
148
- 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/^.* //' ) )
149
- echo -ne " \r$show_bar "
150
- sleep 0.1
155
+ local percent=$( grep -Eo ' [0-9]{1,3}' % log | tail -n1 | cut -d ' %' -f 1)
156
+ local ups=$( grep ' ETA' log | tail -n1 | cut -d ' ,' -f5)
157
+ local eta=$( grep ' ETA' log | tail -n1 | cut -d ' ,' -f6 | sed ' s/ETA //' )
158
+ local status=$( grep ' ETA' log | tail -n1 | cut -d ' ,' -f3 | sed ' s/^.* //' )
159
+ progbar=$( progress_bar " $percent " )
160
+ echo -e " $( clearline) $progbar
161
+ $( clearline) ${Yellow} UPS:${Normal} $ups
162
+ $( clearline) ${Yellow} ETA:${Normal} $eta
163
+ $( clearline) ${Yellow} STATUS:${Normal} $status
164
+ $( upline 5) "
151
165
done # || echo -ne "\rDownload Can't be completed, Check download link." && tput cnorm && exit 1
152
166
tput cnorm
153
167
}
154
168
155
- # Final part of animation if upload was succesfull.
156
- end_animation () {
157
- tput civis
158
-
159
- dls=$( grep ' CN' log | tail -n1 | cut -d ' ' -f 4 | sed ' s/DL://' )
160
- echo -ne " \r${Yellow} Progress ${Green} [======->${Cyan} Completed${Green} <-=====] ${Yellow} UPS : ${dls}${Normal} "
161
- sleep 0.2
162
- echo -ne " \r${Yellow} Progress ${Green} [======/>${Cyan} COmpleted${Green} <\=====] ${Yellow} UPS : ${dls}${Normal} "
163
- sleep 0.2
164
- echo -ne " \r${Yellow} Progress ${Green} [======|>${Cyan} COMpleted${Green} <|=====] ${Yellow} UPS : ${dls}${Normal} "
165
- sleep 0.2
166
- echo -ne " \r${Yellow} Progress ${Green} [======\>${Cyan} COMPleted${Green} </=====] ${Yellow} UPS : ${dls}${Normal} "
167
- sleep 0.2
168
- echo -ne " \r${Yellow} Progress ${Green} [======->${Cyan} COMPLeted${Green} <-=====] ${Yellow} UPS : ${dls}${Normal} "
169
- sleep 0.2
170
- echo -ne " \r${Yellow} Progress ${Green} [======/>${Cyan} COMPLEted${Green} <\=====] ${Yellow} UPS : ${dls}${Normal} "
171
- sleep 0.2
172
- echo -ne " \r${Yellow} Progress ${Green} [======|>${Cyan} COMPLETed${Green} <|=====] ${Yellow} UPS : ${dls}${Normal} "
173
- sleep 0.2
174
- echo -ne " \r${Yellow} Progress ${Green} [======\>${Cyan} COMPLETEd${Green} </=====] ${Yellow} UPS : ${dls}${Normal} "
175
- sleep 0.2
176
- echo -ne " \r${Yellow} Progress ${Green} [======->${Cyan} COMPLETED${Green} <-=====] ${Yellow} UPS : ${dls}${Normal} "
177
- sleep 0.2
178
- echo -ne " \r${Yellow} Progress ${Green} [======/>${Cyan} COMPLETED${Green} <\=====] ${Yellow} UPS : ${dls}${Normal} "
179
- sleep 0.2
180
- echo -ne " \r${Yellow} Progress ${Green} [======|>${Cyan} COMPLETED${Green} <|=====] ${Yellow} UPS : ${dls}${Normal} "
181
- sleep 0.2
182
- echo
183
-
184
- tput cnorm
185
- }
186
-
187
169
# Below function is copied from - https://gist.github.com/jaytaylor/5a90c49e0976aadfe0726a847ce58736
188
170
# Credit to @jkishner for https://gist.github.com/jkishner/2fccb24640a27c2d7ac9
189
171
function url_encode() {
@@ -221,7 +203,7 @@ function url_encode() {
221
203
-e ' s/~/%7e/g'
222
204
}
223
205
224
- # rclone_progress_bar -> progress_bar -> end_animation -> Print dowload link.
206
+ # rclone_progress_bar -> progress_bar -> Print dowload link.
225
207
upload () {
226
208
echo " Initializing process, might take up to 10 seconds..."
227
209
rclone_progress_bar
@@ -230,11 +212,11 @@ upload() {
230
212
echo -e " \rUpload Failed .......\n"
231
213
exit 1
232
214
fi
233
- end_animation
234
215
url_file=$( url_encode " ${new_filename} " )
235
216
url_folder=$( jq -rn --arg x " ${u_folder%/ } " ' $x|@uri' )
236
- echo " Upload Completed "
237
- echo " Download link - ${lightgreen} https://index.sauraj.eu.org/${url_folder} /${url_file}${normal} "
217
+ echo -e " \n$( clearline) $( upline 1) $( clearline) $( upline 1) "
218
+ echo " $( clearline) Upload Completed "
219
+ echo " $( clearline) Download link - ${lightgreen} https://index.sauraj.eu.org/${url_folder} /${url_file}${normal} "
238
220
}
239
221
240
222
help () {
0 commit comments