Skip to content

Commit

Permalink
improve curl-download and redirect scurl-download to it
Browse files Browse the repository at this point in the history
  • Loading branch information
nyxnor committed Nov 1, 2022
1 parent ab44442 commit e0f1e3a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
35 changes: 34 additions & 1 deletion usr/bin/curl-download
Expand Up @@ -3,4 +3,37 @@
## Copyright (C) 2012 - 2022 ENCRYPTED SUPPORT LP <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

curl --location --remote-name "$@"
# get options that require arguments
list="$(curl --help all | grep -o "^ .* <" | sed "s/<.*//g" | tr "\n" " " | tr -s " ")"

# default opts [-O|--remote-name]
def_opt="--remote-name"

# loop arguments to set options for URLs or to not set it at all
for res in "$@"; do
# exclude arguments from options
if [ "$skip_next" = "1" ]; then
skip_next=0
opt="$opt \"$res\""
continue
fi
# exclude options that require arguments
if echo "${list}" | tr " " "\n" | grep -q "^${res}$"; then
skip_next=1
if [ "$res" = "--url" ]; then
opt="$opt $def_opt $res"
else
opt="$opt $res"
fi
continue
fi
# exclude options that don't require arguments
if [[ $res == -* ]]; then
opt="$opt $res"
continue
fi
# for sure this is an url
opt="$opt $def_opt $res"
done

echo curl --location $opt
35 changes: 1 addition & 34 deletions usr/bin/scurl-download
Expand Up @@ -3,37 +3,4 @@
## Copyright (C) 2012 - 2022 ENCRYPTED SUPPORT LP <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

# get options that require arguments
list="$(curl --help all | grep -o "^ .* <" | sed "s/<.*//g" | tr "\n" " " | tr -s " ")"

# default opts [-O|--remote-name]
def_opt="--remote-name"

# loop arguments to set options for URLs or to not set it at all
for res in "$@"; do
# exclude arguments from options
if [ "$skip_next" = "1" ]; then
skip_next=0
opt="$opt \"$res\""
continue
fi
# exclude options that require arguments
if echo "${list}" | tr " " "\n" | grep -q "^${res}$"; then
skip_next=1
if [ "$res" = "--url" ]; then
opt="$opt $def_opt $res"
else
opt="$opt $res"
fi
continue
fi
# exclude options that don't require arguments
if [[ $res == -* ]]; then
opt="$opt $res"
continue
fi
# for sure this is an url
opt="$opt $def_opt $res"
done

scurl --location $opt
curl-download --tlsv1.3 --proto =https "$@"

0 comments on commit e0f1e3a

Please sign in to comment.