|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 | 3 | #Define colors
|
4 |
| - |
5 |
| - normal=$(echo -en "\e[0m") |
6 |
| - orange=$(echo -en "\e[33m") |
7 |
| - aqua=$(echo -en "\e[36m") |
8 |
| - lightgreen=$(echo -en "\e[92m") |
9 |
| - |
10 |
| -file=$2 |
11 |
| -u_folder=$3 |
| 4 | +normal=$(echo -en "\e[0m") |
| 5 | +orange=$(echo -en "\e[33m") |
| 6 | +aqua=$(echo -en "\e[36m") |
| 7 | +lightgreen=$(echo -en "\e[92m") |
| 8 | +Normal='\033[0m' |
| 9 | +Black='\033[0;30m' # Black |
| 10 | +Red='\033[0;31m' # Red |
| 11 | +Green='\033[0;32m' # Green |
| 12 | +Yellow='\033[0;33m' # Yellow |
| 13 | +Blue='\033[0;34m' # Blue |
| 14 | +Purple='\033[0;35m' # Purple |
| 15 | +Cyan='\033[0;36m' # Cyan |
| 16 | +White='\033[0;37m' # White |
| 17 | + |
| 18 | +#Vars and bash configurations. |
| 19 | +set -o pipefail |
| 20 | +readonly file="$2" |
| 21 | +readonly u_folder="$3" |
| 22 | +readonly status_dir="$(mktemp -d)" |
| 23 | +trap "rm -rf $status_dir" EXIT |
12 | 24 |
|
13 | 25 | dependencies () {
|
14 | 26 | echo "Starting Installation...."
|
@@ -80,23 +92,124 @@ Example : ${lightgreen}ksau upload test.txt Public
|
80 | 92 | ${orange}Tool By @Ksauraj${normal}
|
81 | 93 |
|
82 | 94 | "
|
83 |
| -} |
84 |
| - |
85 |
| -update () { |
86 |
| - echo "${orange}Current" "$(ksau version)" |
87 |
| - echo "${orange}Fetching latest version.${normal}" |
88 |
| - rm $PREFIX/bin/ksau > /dev/null 2>&1 |
89 |
| - rm ksau > /dev/null 2>&1 |
90 |
| - curl https://raw.githubusercontent.com/noobyysauraj/global_index_source/master/termux/ksau > ksau 2>/dev/null |
91 |
| - mv ksau $PREFIX/bin |
92 |
| - chmod +x $PREFIX/bin/ksau |
93 |
| - echo "${orange}Update Finished${normal}" |
94 |
| - echo "${orange}Updated to" "$(ksau version)" |
95 |
| - echo "${normal}" |
| 95 | +} |
| 96 | + |
| 97 | +progress_bar() { |
| 98 | + if [ "$(tput cols)" -lt 84 ]; then |
| 99 | + [ -z $1 ] && set -- "(Starting)" "..." "..." "..." |
| 100 | + echo "${Green}${1}% UPS: ${Cyan}2 ${Yellow}ETA: ${3} STATUS: ${Cyan}${4}${Normal}" |
| 101 | + return |
| 102 | + fi |
| 103 | + |
| 104 | + if [[ ${1} < 10 ]]; then echo "${Yellow}Progress ${Green}[=>---------${Cyan}${1}%${Normal}${Green}---------<=] ${Yellow}Speed:${Cyan}${2} ${Yellow}ETA:${Cyan}${3} ${Yellow}Status:${Cyan}${4}${Normal}" |
| 105 | + elif [[ ${1} -lt 20 ]]; then echo "${Yellow}Progress ${Green}[==>--------${Cyan}${1}%${Normal}${Green}--------<==] ${Yellow}Speed:${Cyan}${2} ${Yellow}ETA:${Cyan}${3} ${Yellow}Status:${Cyan}${4}${Normal}" |
| 106 | + elif [[ ${1} -lt 30 ]]; then echo "${Yellow}Progress ${Green}[===>-------${Cyan}${1}%${Normal}${Green}-------<===] ${Yellow}Speed:${Cyan}${2} ${Yellow}ETA:${Cyan}${3} ${Yellow}Status:${Cyan}${4}${Normal}" |
| 107 | + elif [[ ${1} -lt 40 ]]; then echo "${Yellow}Progress ${Green}[====>------${Cyan}${1}%${Normal}${Green}------<====] ${Yellow}Speed:${Cyan}${2} ${Yellow}ETA:${Cyan}${3} ${Yellow}Status:${Cyan}${4}${Normal}" |
| 108 | + elif [[ ${1} -lt 50 ]]; then echo "${Yellow}Progress ${Green}[=====>-----${Cyan}${1}%${Normal}${Green}-----<=====] ${Yellow}Speed:${Cyan}${2} ${Yellow}ETA:${Cyan}${3} ${Yellow}Status:${Cyan}${4}${Normal}" |
| 109 | + elif [[ ${1} -lt 60 ]]; then echo "${Yellow}Progress ${Green}[======>----${Cyan}${1}%${Normal}${Green}----<======] ${Yellow}Speed:${Cyan}${2} ${Yellow}ETA:${Cyan}${3} ${Yellow}Status:${Cyan}${4}${Normal}" |
| 110 | + elif [[ ${1} -lt 70 ]]; then echo "${Yellow}Progress ${Green}[=======>---${Cyan}${1}%${Normal}${Green}---<=======] ${Yellow}Speed:${Cyan}${2} ${Yellow}ETA:${Cyan}${3} ${Yellow}Status:${Cyan}${4}${Normal}" |
| 111 | + elif [[ ${1} -lt 80 ]]; then echo "${Yellow}Progress ${Green}[========>--${Cyan}${1}%${Normal}${Green}--<========] ${Yellow}Speed:${Cyan}${2} ${Yellow}ETA:${Cyan}${3} ${Yellow}Status:${Cyan}${4}${Normal}" |
| 112 | + elif [[ ${1} -lt 90 ]]; then echo "${Yellow}Progress ${Green}[=========>-${Cyan}${1}%${Normal}${Green}-<=========] ${Yellow}Speed:${Cyan}${2} ${Yellow}ETA:${Cyan}${3} ${Yellow}Status:${Cyan}${4}${Normal}" |
| 113 | + elif [[ ${1} -lt 100 ]]; then echo "${Yellow}Progress ${Green}[==========>${Cyan}${1}%${Normal}${Green}<==========] ${Yellow}Speed:${Cyan}${2} ${Yellow}ETA:${Cyan}${3} ${Yellow}Status:${Cyan}${4}${Normal}" |
| 114 | + elif [[ ${1} == 100 ]]; then echo "${Yellow}Progress ${Green}[===========${Cyan}${1}%${Normal}${Green}===========] ${Yellow}Speed:${Cyan}${2} ${Yellow}ETA:${Cyan}${3} ${Yellow}Status:${Cyan}${4}${Normal}" |
| 115 | + fi |
| 116 | +} |
| 117 | + |
| 118 | +rclone_progress_bar() { |
| 119 | + tput civis |
| 120 | + echo "Starting Upload..." |
| 121 | + rm -f log |
| 122 | + touch log |
| 123 | + rclone -P --checkers=32 --onedrive-chunk-size 60M copy "$file" oned:/"${u_folder}" | tee log >/dev/null || touch "$status_dir/failed" & |
| 124 | + until [ -z "$(jobs -r)" ]; do |
| 125 | + if [ -f "$status_dir/failed" ]; then |
| 126 | + echo |
| 127 | + echo "${Red}Upload failed!${Normal}" |
| 128 | + break |
| 129 | + fi |
| 130 | + 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 | sed 's/^ *//g' | sed 's/ $//g')" "$(grep 'ETA' log | tail -n1 | cut -d ',' -f6 | sed 's/ETA //' | sed 's/^ *//g' | sed 's/ $//g')" "$(grep 'ETA' log | tail -n1 | cut -d ',' -f3 | sed 's/^.* //' | sed 's/^ *//g' | sed 's/ $//g')") |
| 131 | + echo -ne "\r$show_bar" |
| 132 | + sleep 0.1 |
| 133 | + done #|| echo -ne "\rDownload Can't be completed, Check download link." && tput cnorm && exit 1 |
| 134 | + tput cnorm |
| 135 | +} |
| 136 | +end_animation() { |
| 137 | + tput civis |
| 138 | + |
| 139 | + dls=$(grep 'CN' log | tail -n1 | cut -d ' ' -f 4 | sed 's/DL://') |
| 140 | + echo -ne "\r${Yellow}Progress ${Green}[=======->${Cyan}Completed${Green}<-======] ${Yellow}Speed:${dls}${Normal}" && sleep 0.2 |
| 141 | + echo -ne "\r${Yellow}Progress ${Green}[=======/>${Cyan}COmpleted${Green}<\======] ${Yellow}Speed:${dls}${Normal}" && sleep 0.2 |
| 142 | + echo -ne "\r${Yellow}Progress ${Green}[=======|>${Cyan}COMpleted${Green}<|======] ${Yellow}Speed:${dls}${Normal}" && sleep 0.2 |
| 143 | + echo -ne "\r${Yellow}Progress ${Green}[=======\>${Cyan}COMPleted${Green}</======] ${Yellow}Speed:${dls}${Normal}" && sleep 0.2 |
| 144 | + echo -ne "\r${Yellow}Progress ${Green}[=======->${Cyan}COMPLeted${Green}<-======] ${Yellow}Speed:${dls}${Normal}" && sleep 0.2 |
| 145 | + echo -ne "\r${Yellow}Progress ${Green}[=======/>${Cyan}COMPLEted${Green}<\======] ${Yellow}Speed:${dls}${Normal}" && sleep 0.2 |
| 146 | + echo -ne "\r${Yellow}Progress ${Green}[=======|>${Cyan}COMPLETed${Green}<|======] ${Yellow}Speed:${dls}${Normal}" && sleep 0.2 |
| 147 | + echo -ne "\r${Yellow}Progress ${Green}[=======\>${Cyan}COMPLETEd${Green}</======] ${Yellow}Speed:${dls}${Normal}" && sleep 0.2 |
| 148 | + echo -ne "\r${Yellow}Progress ${Green}[=======->${Cyan}COMPLETED${Green}<-======] ${Yellow}Speed:${dls}${Normal}" && sleep 0.2 |
| 149 | + echo -ne "\r${Yellow}Progress ${Green}[=======/>${Cyan}COMPLETED${Green}<\======] ${Yellow}Speed:${dls}${Normal}" && sleep 0.2 |
| 150 | + echo -ne "\r${Yellow}Progress ${Green}[=======|>${Cyan}COMPLETED${Green}<|======] ${Yellow}Speed:${dls}${Normal}" && sleep 0.2 |
| 151 | + echo |
| 152 | + |
| 153 | + tput cnorm |
| 154 | +} |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | +# Below function is copied from - https://gist.github.com/jaytaylor/5a90c49e0976aadfe0726a847ce58736 |
| 159 | +# Credit to @jkishner for https://gist.github.com/jkishner/2fccb24640a27c2d7ac9 |
| 160 | +function url_encode() { |
| 161 | + echo "$@" \ |
| 162 | + | sed \ |
| 163 | + -e 's/%/%25/g' \ |
| 164 | + -e 's/ /%20/g' \ |
| 165 | + -e 's/!/%21/g' \ |
| 166 | + -e 's/"/%22/g' \ |
| 167 | + -e "s/'/%27/g" \ |
| 168 | + -e 's/#/%23/g' \ |
| 169 | + -e 's/(/%28/g' \ |
| 170 | + -e 's/)/%29/g' \ |
| 171 | + -e 's/+/%2b/g' \ |
| 172 | + -e 's/,/%2c/g' \ |
| 173 | + -e 's/-/%2d/g' \ |
| 174 | + -e 's/:/%3a/g' \ |
| 175 | + -e 's/;/%3b/g' \ |
| 176 | + -e 's/?/%3f/g' \ |
| 177 | + -e 's/@/%40/g' \ |
| 178 | + -e 's/\$/%24/g' \ |
| 179 | + -e 's/\&/%26/g' \ |
| 180 | + -e 's/\*/%2a/g' \ |
| 181 | + -e 's/\./%2e/g' \ |
| 182 | + -e 's/\//%2f/g' \ |
| 183 | + -e 's/\[/%5b/g' \ |
| 184 | + -e 's/\\/%5c/g' \ |
| 185 | + -e 's/\]/%5d/g' \ |
| 186 | + -e 's/\^/%5e/g' \ |
| 187 | + -e 's/_/%5f/g' \ |
| 188 | + -e 's/`/%60/g' \ |
| 189 | + -e 's/{/%7b/g' \ |
| 190 | + -e 's/|/%7c/g' \ |
| 191 | + -e 's/}/%7d/g' \ |
| 192 | + -e 's/~/%7e/g' |
| 193 | +} |
| 194 | + |
| 195 | +upload () { |
| 196 | + echo "Initializing process, might take up to 10 seconds..." |
| 197 | + rclone_progress_bar |
| 198 | + wait |
| 199 | + if [ -f "$status_dir/failed" ]; then |
| 200 | + echo -e "\rUpload Failed .......\n" |
| 201 | + exit 1 |
| 202 | + fi |
| 203 | + end_animation |
| 204 | + u_file=$(basename "${file}") |
| 205 | + url_file=$(url_encode "$u_file") |
| 206 | + url_folder=$(jq -rn --arg x "${u_folder}" '$x|@uri') |
| 207 | + echo " Upload Completed " |
| 208 | + echo " Download link - ${lightgreen}https://index.sauraj.eu.org/${url_folder}/${url_file}${normal} " |
96 | 209 | }
|
97 | 210 |
|
98 | 211 | version () {
|
99 |
| - echo "${orange}Version - 1.4.1 (Gamma-termux) ${normal}" |
| 212 | + echo "${orange}Version - 1.4.2 (Alpha-termux) ${normal}" |
100 | 213 | }
|
101 | 214 |
|
102 | 215 | if [[ $1 == "upload" ]]; then
|
|
0 commit comments