Skip to content

Commit 1cdac1e

Browse files
committed
ksau: Add new argument handler to rename file with random sting
1 parent 62d53c7 commit 1cdac1e

File tree

2 files changed

+47
-21
lines changed

2 files changed

+47
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
log

ksau

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Cyan='\033[0;36m' # Cyan
1616
White='\033[0;37m' # White
1717

1818
set -o pipefail
19-
readonly file="$2"
20-
readonly u_folder="$3"
19+
#readonly file="$2"
20+
#readonly u_folder="$3"
2121
readonly status_dir="$(mktemp -d)"
2222

2323
trap "rm -rf $status_dir" EXIT
@@ -31,11 +31,11 @@ sudo curl https://rclone.org/install.sh 2>/dev/null | sudo bash > /dev/null 2>&1
3131
echo ""
3232
echo "${orange}Please install jq manually, No script found"
3333
echo "Possibly with
34-
${aqua}sudo apt-get install jq ${normal}OR
35-
${aqua}sudo pacman -S jq ${normal}OR
34+
${aqua}sudo apt-get install jq ${normal}OR
35+
${aqua}sudo pacman -S jq ${normal}OR
3636
${aqua}sudo dnf install jq ${normal}OR
3737
${aqua}sudo zypper install jq ${normal}OR
38-
${aqua}apk add jq ${normal}OR
38+
${aqua}apk add jq ${normal}OR
3939
${aqua}pkg install jq${normal}"
4040
echo ''
4141
}
@@ -61,19 +61,31 @@ setup () {
6161
then
6262
echo "${aqua}Dependencies not found. Make sure to proceed with the command 'ksau dependencies'"
6363
echo "${aqua}Please install jq manually, No script found"
64-
echo "Possibly with
65-
${aqua}sudo apt-get install jq ${normal}OR
66-
${aqua}sudo pacman -S jq ${normal}OR
64+
echo "Possibly with
65+
${aqua}sudo apt-get install jq ${normal}OR
66+
${aqua}sudo pacman -S jq ${normal}OR
6767
${aqua}sudo dnf install jq ${normal}OR
6868
${aqua}sudo zypper install jq ${normal}OR
69-
${aqua}apk add jq ${normal}OR
69+
${aqua}apk add jq ${normal}OR
7070
${aqua}pkg install jq${normal}"
7171
exit
7272
fi
7373
fi
7474
echo "Setup Completed"
7575
}
7676

77+
add_random_string() {
78+
local filename="$1"
79+
local extension="${filename##*.}"
80+
local name="${filename%.*}"
81+
local random_string="$(date +%s | sha256sum | base64 | head -c 8)"
82+
if [ "$extension" == "$filename" ]; then
83+
new_filename="$name-$random_string"
84+
else
85+
new_filename="$name-$random_string.$extension"
86+
fi
87+
}
88+
7789
progress_bar() {
7890
if [ "$(tput cols)" -lt 84 ]; then
7991
[ -z $1 ] && set -- "(Starting)" "..." "..." "..."
@@ -111,7 +123,8 @@ rclone_progress_bar() {
111123
echo "Starting download..."
112124
rm -f log
113125
touch log
114-
rclone -P --checkers=32 --onedrive-chunk-size 60M copy "$file" oned:/"${u_folder}" | tee log >/dev/null || touch "$status_dir/failed" &
126+
if [ -z "$new_filename" ]; then new_filename=$(basename "$file"); fi
127+
rclone -P --checkers=32 --onedrive-chunk-size 60M copyto "$file" oned:/"${u_folder}"/"$new_filename" | tee log >/dev/null || touch "$status_dir/failed" &
115128
until [ -z "$(jobs -r)" ]; do
116129
if [ -f "$status_dir/failed" ]; then
117130
echo
@@ -203,9 +216,8 @@ upload () {
203216
exit 1
204217
fi
205218
end_animation
206-
u_file=$(basename "${file}")
207-
url_file=$(url_encode "$u_file")
208-
url_folder=$(jq -rn --arg x "${u_folder}" '$x|@uri')
219+
url_file=$(url_encode "${new_filename}")
220+
url_folder=$(jq -rn --arg x "${u_folder%/}" '$x|@uri')
209221
echo " Upload Completed "
210222
echo " Download link - ${lightgreen}https://index.sauraj.eu.org/${url_folder}/${url_file}${normal} "
211223
}
@@ -242,22 +254,35 @@ update () {
242254
}
243255

244256
version () {
245-
echo "${orange}Version - 1.4.2 (Stable) ${normal}"
257+
echo "${orange}Version - 1.5 (Stable) ${normal}"
246258
}
247259

248260
if [[ $1 == "upload" ]]; then
249-
upload
261+
if [[ $2 == "-r" ]]; then
262+
shift
263+
readonly file="$2"
264+
readonly u_folder="$3"
265+
add_random_string $(basename "$file")
266+
upload
267+
else
268+
readonly file="$2"
269+
readonly u_folder="$3"
270+
upload
271+
fi
250272
elif [[ $1 == "setup" ]]; then
251-
setup
273+
setup
252274
elif [[ $1 == "dependencies" ]]; then
253-
dependencies
275+
dependencies
254276
elif [[ $1 == "update" ]]; then
255-
update
277+
update
256278
elif [[ $1 == "version" ]]; then
257-
version
279+
version
258280
elif [[ $1 == "help" ]]; then
259-
help
281+
help
260282
elif [[ $1 == "" ]]; then
261-
help
283+
help
284+
else
285+
echo "Unknown Argument passed."
286+
help
262287
fi
263288

0 commit comments

Comments
 (0)