@@ -19,11 +19,24 @@ Purple='\033[0;35m' # Purple
1919Cyan=' \033[0;36m' # Cyan
2020White=' \033[0;37m' # White
2121
22+ UPLINE=$( tput cuu1)
23+ CLEARLINE=$( tput el)
24+
2225set -o pipefail
2326readonly status_dir=" $( mktemp -d) "
2427
2528trap " rm -rf $status_dir " EXIT
2629
30+ upline () {
31+ for _ in $( seq $1 ) ; do
32+ echo -ne " $UPLINE "
33+ done
34+ }
35+
36+ clearline () {
37+ echo -ne " $CLEARLINE "
38+ }
39+
2740dependencies () {
2841 if declare -p TERMUX_VERSION & > /dev/null; then
2942 echo " Starting Installation...."
@@ -100,41 +113,35 @@ add_random_string() {
100113# Simple progressbar animation.
101114# Usage : progress_bar ${percentage} ${upload_speed} $(eta) ${status}
102115progress_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-
109116 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} ---------<=]"
111118 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} --------<==]"
113120 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} -------<===]"
115122 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} ------<====]"
117124 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} -----<=====]"
119126 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} ----<======]"
121128 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} ---<=======]"
123130 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} --<========]"
125132 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} -<=========]"
127134 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} <==========]"
129136 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} ===========]"
131138 fi
132139}
133140
134141# Upload file to give folder and use new filename if -r argument was passed and printing out new animation.
135142rclone_progress_bar () {
136143 tput civis
137- echo " Starting download ..."
144+ echo " Starting upload ..."
138145 rm -f log
139146 touch log
140147 if [ -z " $new_filename " ]; then new_filename=$( basename " $file " ) ; fi
@@ -145,45 +152,20 @@ rclone_progress_bar() {
145152 echo " ${Red} Upload failed!${Normal} "
146153 break
147154 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) "
151165 done # || echo -ne "\rDownload Can't be completed, Check download link." && tput cnorm && exit 1
152166 tput cnorm
153167}
154168
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-
187169# Below function is copied from - https://gist.github.com/jaytaylor/5a90c49e0976aadfe0726a847ce58736
188170# Credit to @jkishner for https://gist.github.com/jkishner/2fccb24640a27c2d7ac9
189171function url_encode() {
@@ -221,7 +203,7 @@ function url_encode() {
221203 -e ' s/~/%7e/g'
222204}
223205
224- # rclone_progress_bar -> progress_bar -> end_animation -> Print dowload link.
206+ # rclone_progress_bar -> progress_bar -> Print dowload link.
225207upload () {
226208 echo " Initializing process, might take up to 10 seconds..."
227209 rclone_progress_bar
@@ -230,11 +212,11 @@ upload() {
230212 echo -e " \rUpload Failed .......\n"
231213 exit 1
232214 fi
233- end_animation
234215 url_file=$( url_encode " ${new_filename} " )
235216 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} "
238220}
239221
240222help () {
0 commit comments