Refactor aria2c and zsync support

If aria2 is installed, it will now be listed in the csv/json
This commit is contained in:
Martin Wimpress 2022-02-21 07:06:06 +00:00
parent 5f26733687
commit 559e2ae886
No known key found for this signature in database
GPG key ID: 61DF940515E06DA3

View file

@ -89,6 +89,7 @@ function list_json() {
function list_csv() { function list_csv() {
local DISPLAY_NAME local DISPLAY_NAME
local DL=""
local DOWNLOADER local DOWNLOADER
local FUNC local FUNC
local OPTION local OPTION
@ -96,16 +97,19 @@ function list_csv() {
local PNG local PNG
local RELEASE local RELEASE
local SVG local SVG
local ZS="" local HAS_ZSYNC=0
local DL=""
# check if we have a zsync installed somewhere # Check if zsync is available
ZS="$(which zsync)" if command -v zsync &>/dev/null; then
if [ -x "${ZS}" ]; then HAS_ZSYNC=1
DL="zsync" fi
else
if command -v aria2c &>/dev/null; then
DL="aria2c"
elif command -v wget &>/dev/null; then
DL="wget" DL="wget"
fi fi
echo "Display Name,OS,Release,Option,Downloader,PNG,SVG" echo "Display Name,OS,Release,Option,Downloader,PNG,SVG"
for OS in $(os_support); do for OS in $(os_support); do
DISPLAY_NAME="$(pretty_name "${OS}")" DISPLAY_NAME="$(pretty_name "${OS}")"
@ -120,12 +124,12 @@ function list_csv() {
for RELEASE in $("releases_${FUNC}"); do for RELEASE in $("releases_${FUNC}"); do
if [ "${OS}" == "macos" ]; then if [ "${OS}" == "macos" ]; then
DOWNLOADER="macrecovery" DOWNLOADER="macrecovery"
elif [ "${OS}" == "ubuntu" ] && [ "${RELEASE}" == "canary" ]; then elif [ "${OS}" == "ubuntu" ] && [ "${RELEASE}" == "canary" ] && [ ${HAS_ZSYNC} -eq 1 ]; then
DOWNLOADER="${DL}" DOWNLOADER="zsync"
elif [[ "${OS}" == *"ubuntu"* ]] && [ "${RELEASE}" == "devel" ]; then elif [[ "${OS}" == *"ubuntu"* ]] && [ "${RELEASE}" == "devel" ] && [ ${HAS_ZSYNC} -eq 1 ]; then
DOWNLOADER="${DL}" DOWNLOADER="zsync"
else else
DOWNLOADER="wget" DOWNLOADER="${DL}"
fi fi
if [ "${OS}" == "windows" ]; then if [ "${OS}" == "windows" ]; then
@ -518,7 +522,7 @@ function web_get() {
exit 1 exit 1
fi fi
if command -v aria2c > /dev/null; then if command -v aria2c &>/dev/null; then
if ! aria2c -x16 --continue=true --summary-interval=0 --download-result=hide --console-log-level=error "${URL}" -o "${DIR}/${FILE}"; then if ! aria2c -x16 --continue=true --summary-interval=0 --download-result=hide --console-log-level=error "${URL}" -o "${DIR}/${FILE}"; then
echo #Necessary as aria2c in suppressed mode does not have new lines echo #Necessary as aria2c in suppressed mode does not have new lines
echo "ERROR! Failed to download ${URL} with aria2c. Try running 'quickget' again." echo "ERROR! Failed to download ${URL} with aria2c. Try running 'quickget' again."
@ -538,12 +542,11 @@ function zsync_get() {
local FILE="" local FILE=""
local OUT="" local OUT=""
local URL="${1}" local URL="${1}"
FILE="${URL##*/}"
local ZS="" local ZS=""
# check if we have a zsync installed somewhere FILE="${URL##*/}"
ZS="$(which zsync)"
if [ -x "${ZS}" ]; then if command -v zsync &>/dev/null; then
if [ -n "${3}" ]; then if [ -n "${3}" ]; then
OUT="${3}" OUT="${3}"
else else
@ -564,7 +567,7 @@ function zsync_get() {
rm "${DIR}/${OUT}.zs-old" rm "${DIR}/${OUT}.zs-old"
fi fi
else else
echo "INFO: zsync not found, falling back to wget" echo "INFO: zsync not found, falling back to wget/aria2c"
web_get "${ISO}" "${DIR}" web_get "${ISO}" "${DIR}"
fi fi
} }