Skip to content

Commit 6e664f8

Browse files
authored
Merge pull request ksauraj#5 from Hakimi0804/staging
Code Style Improvements
2 parents 3db1b0c + 365c428 commit 6e664f8

File tree

6 files changed

+284
-277
lines changed

6 files changed

+284
-277
lines changed

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
LINT_FILES := setup \
2+
setup-root \
3+
ksau \
4+
termux/setup \
5+
termux/ksau \
6+
7+
lint:
8+
shfmt -i 4 -w $(LINT_FILES)
9+
10+
default: lint

ksau

Lines changed: 104 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -20,71 +20,68 @@ readonly status_dir="$(mktemp -d)"
2020

2121
trap "rm -rf $status_dir" EXIT
2222

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
3232
${aqua}sudo apt-get install jq ${normal}OR
3333
${aqua}sudo pacman -S jq ${normal}OR
3434
${aqua}sudo dnf install jq ${normal}OR
3535
${aqua}sudo zypper install jq ${normal}OR
3636
${aqua}apk add jq ${normal}OR
3737
${aqua}pkg install jq${normal}"
38-
echo ''
38+
echo ''
3939
}
4040

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
6360
${aqua}sudo apt-get install jq ${normal}OR
6461
${aqua}sudo pacman -S jq ${normal}OR
6562
${aqua}sudo dnf install jq ${normal}OR
6663
${aqua}sudo zypper install jq ${normal}OR
6764
${aqua}apk add jq ${normal}OR
6865
${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"
7370
}
7471

7572
# Generates new filename with random strings at last (before extension if present).
7673
# new name for 'myfile.txt' -> 'myfile-78e11b8c.txt'
7774
# new name for 'myfile' -> 'myfile-78e11b8c'
7875
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
8885
}
8986

9087
# Simple progressbar animation.
@@ -128,14 +125,14 @@ rclone_progress_bar() {
128125
rm -f log
129126
touch log
130127
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" &
132129
until [ -z "$(jobs -r)" ]; do
133130
if [ -f "$status_dir/failed" ]; then
134131
echo
135132
echo "${Red}Upload failed!${Normal}"
136133
break
137134
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/^.* //'))
139136
echo -ne "\r$show_bar"
140137
sleep 0.1
141138
done #|| echo -ne "\rDownload Can't be completed, Check download link." && tput cnorm && exit 1
@@ -174,63 +171,61 @@ end_animation() {
174171
tput cnorm
175172
}
176173

177-
178-
179174
# Below function is copied from - https://gist.github.com/jaytaylor/5a90c49e0976aadfe0726a847ce58736
180175
# Credit to @jkishner for https://gist.github.com/jkishner/2fccb24640a27c2d7ac9
181176
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'
214209
}
215210

216211
# 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} "
230225
}
231226

232-
help () {
233-
echo "
227+
help() {
228+
echo "
234229
${aqua}Usage : ksau [OPTION]... [FILE]...${normal}
235230
236231
${aqua}upload [FILE] [FOLDER]${normal} : Uploads the given file to the given folder
@@ -255,22 +250,22 @@ Example : ${lightgreen}ksau upload test.txt Public
255250
256251
${orange}Tool By Sauraj (@Ksauraj)${normal}
257252
"
258-
}
253+
}
259254

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}"
270265
}
271266

272-
version () {
273-
echo "${orange}Version - 1.5.1 (Stable) ${normal}"
267+
version() {
268+
echo "${orange}Version - 1.5.1 (Stable) ${normal}"
274269
}
275270

276271
if [[ $1 == "upload" ]]; then
@@ -301,4 +296,3 @@ else
301296
echo "Unknown Argument passed."
302297
help
303298
fi
304-

setup

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
#!/bin/bash
2-
2+
33
#Define colors
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-
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+
99
echo "Make sure you have sudo privilages"
10-
rm ksau > /dev/null 2>&1
11-
sudo rm /usr/local/bin/ksau > /dev/null 2>&1
12-
curl https://raw.githubusercontent.com/noobyysauraj/global_index_source/master/ksau > ksau 2>/dev/null
10+
rm ksau >/dev/null 2>&1
11+
sudo rm /usr/local/bin/ksau >/dev/null 2>&1
12+
curl https://raw.githubusercontent.com/noobyysauraj/global_index_source/master/ksau >ksau 2>/dev/null
1313
sudo mv ksau /usr/local/bin
1414
chmod +x /usr/local/bin/ksau
15-
16-
if ! command -v ksau &> /dev/null
17-
then
18-
echo "${orange}Installation Failed !!!"
19-
echo "Posssible Solution : Don't run as root or check Root version.${normal}"
20-
exit
21-
else
22-
ksau
23-
fi
15+
16+
if ! command -v ksau &>/dev/null; then
17+
echo "${orange}Installation Failed !!!"
18+
echo "Posssible Solution : Don't run as root or check Root version.${normal}"
19+
exit
20+
else
21+
ksau
22+
fi

setup-root

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
#!/bin/bash
2-
2+
33
#Define colors
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-
9-
rm ksau > /dev/null 2>&1
10-
rm /usr/local/bin/ksau > /dev/null 2>&1
11-
curl https://raw.githubusercontent.com/noobyysauraj/global_index_source/master/ksau > ksau 2>/dev/null
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+
9+
rm ksau >/dev/null 2>&1
10+
rm /usr/local/bin/ksau >/dev/null 2>&1
11+
curl https://raw.githubusercontent.com/noobyysauraj/global_index_source/master/ksau >ksau 2>/dev/null
1212
mv ksau /usr/local/bin
1313
chmod +x /usr/local/bin/ksau
14-
15-
if ! command -v ksau &> /dev/null
16-
then
17-
echo "${orange}Installation Failed !!!"
18-
echo "Posssible Solution : Run as root or check non-root version.${normal}"
19-
exit
20-
else
21-
ksau
22-
fi
14+
15+
if ! command -v ksau &>/dev/null; then
16+
echo "${orange}Installation Failed !!!"
17+
echo "Posssible Solution : Run as root or check non-root version.${normal}"
18+
exit
19+
else
20+
ksau
21+
fi

0 commit comments

Comments
 (0)