-
Notifications
You must be signed in to change notification settings - Fork 202
Fix multiple bugs, add perf optimizations, and update docs (v1.11.0) #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| #!/bin/bash | ||
| # | ||
| # apt-fast v1.10.0 | ||
| # apt-fast v1.11.0 | ||
| # Use this just like aptitude or apt-get for faster package downloading. | ||
| # | ||
| # Copyright: 2008-2012 Matt Parnell, http://www.mattparnell.com | ||
| # Copyright: 2008-2012 Matt Parnell | ||
| # Improvements, maintenance, revisions - 2012, 2017-2019 Dominique Lasserre | ||
| # | ||
| # You may distribute this file under the terms of the GNU General | ||
|
|
@@ -55,7 +55,8 @@ for argument in "$@"; do | |
| option="source" | ||
| root=0 | ||
| ;; | ||
| changelog | list | show | help | --help | -h) | ||
| changelog | list | show | search | help | --help | -h) | ||
| option="readonly" | ||
| root=0 | ||
| ;; | ||
| esac | ||
|
|
@@ -227,10 +228,12 @@ msg_already_running() | |
| msg "Verify that all apt-fast processes are finished then remove $LCK_FILE.lock and try again." "hint" | ||
| } | ||
|
|
||
| # Check if a lock file exists. | ||
| if [ -f "$LCK_FILE.lock" ]; then | ||
| msg_already_running | ||
| exit 1 | ||
| # Check if a lock file exists (skip for read-only commands). | ||
| if [ "$option" != "readonly" ]; then | ||
| if [ -f "$LCK_FILE.lock" ]; then | ||
| msg_already_running | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
|
|
||
|
|
@@ -281,13 +284,6 @@ exit_cleanup_state() | |
| exit $CLEANUP_STATE | ||
| } | ||
|
|
||
| # decode url string | ||
| # translates %xx but must not convert '+' in spaces | ||
| urldecode() | ||
| { | ||
| printf '%b' "${1//%/\\x}" | ||
| } | ||
|
|
||
| # Check if mirrors are available. And if so add all mirrors to download list. | ||
| get_mirrors(){ | ||
| # Check all mirror lists. | ||
|
|
@@ -337,15 +333,16 @@ prepare_auth(){ | |
| AUTH_INFO_PARSED+=("$machine $login $password") | ||
| done <<< "$auth_info" | ||
| done | ||
| if [ "${#AUTH_INFO_PARSED[@]}" -eq 0 ]; then | ||
| # acts as if auth is disabled when no auth info is provided to improve performance | ||
| APT_FAST_APT_AUTH=0 | ||
| fi | ||
| } | ||
|
|
||
| # Gets URI as parameter and tries to add basic http credentials. Will fail on | ||
| # credentials that contain characters that need URL-encoding. | ||
| # Caller is responsible for checking APT_FAST_APT_AUTH before calling this function. | ||
| get_auth(){ | ||
| if [ "$APT_FAST_APT_AUTH" -eq 0 ]; then | ||
| echo "$1" | ||
| return | ||
| fi | ||
| for auth_info in "${AUTH_INFO_PARSED[@]}"; do | ||
| # convert to array, don't escape variable here | ||
| auth_info_arr=($auth_info) | ||
|
|
@@ -405,14 +402,21 @@ get_uris(){ | |
| while IFS=' ' read -r uri filename filesize checksum_string _ | ||
| do | ||
| [ -z "$uri" ] && continue | ||
| uri="$(get_auth "${uri//"'"/}")" | ||
| uri="${uri//"'"/}" | ||
| [ "$APT_FAST_APT_AUTH" -ne 0 ] && uri="$(get_auth "$uri")" | ||
| IFS=':' read -r hash_algo checksum _ <<<"$checksum_string" | ||
|
|
||
| filename_decoded="$(urldecode "$filename")" | ||
| if [[ "$filename" == *%* ]]; then | ||
| # decode url string | ||
| # translates %xx but must not convert '+' in spaces | ||
| filename_decoded="$(printf '%b' "${filename//%/\\x}")" | ||
| else | ||
| # most filenames do not contain %, so skip decoding to improve performance | ||
| filename_decoded="$filename" | ||
| fi | ||
| IFS='_' read -r pkg_name_decoded pkg_version_decoded _ <<<"$filename_decoded" | ||
| DOWNLOAD_DISPLAY="${DOWNLOAD_DISPLAY}$pkg_name_decoded $pkg_version_decoded" | ||
| DOWNLOAD_DISPLAY="${DOWNLOAD_DISPLAY} $(echo "$filesize" | numfmt --to=iec-i --suffix=B)\n" | ||
| DOWNLOAD_SIZE=$((DOWNLOAD_SIZE + filesize)) | ||
| DOWNLOAD_DISPLAY+="$pkg_name_decoded $pkg_version_decoded $filesize\n" | ||
| ((DOWNLOAD_SIZE += filesize)) | ||
|
|
||
| ## whole uri comes encoded (urlencoded). Filename must NOT be decoded because | ||
| # plain aptitude do not decode it when download and install it. Therefore, we | ||
|
|
@@ -494,20 +498,24 @@ display_downloadfile(){ | |
| DISPLAY_SORT_OPTIONS=(-k 1,1) | ||
| # Sort output after package download size (decreasing): | ||
| #DISPLAY_SORT_OPTIONS=(-k 3,3 -hr) | ||
| DISPLAY_NUMFMT_OPTIONS=(--to=iec-i --suffix=B) | ||
| while IFS=' ' read -r pkg ver size _; do | ||
| [ -z "$pkg" ] && continue | ||
| printf '%s%-40s %-20s %10s\n' "$aptfast_prefix" "$pkg" "$ver" "$size" | ||
| done <<<"$(echo -e "$DOWNLOAD_DISPLAY" | sort "${DISPLAY_SORT_OPTIONS[@]}")" | ||
| done <<<"$(echo -e "$DOWNLOAD_DISPLAY" | sort "${DISPLAY_SORT_OPTIONS[@]}" | numfmt "${DISPLAY_NUMFMT_OPTIONS[@]}" --field=3)" | ||
| fi | ||
| msg "Download size: $(echo "$DOWNLOAD_SIZE" | numfmt --to=iec-i --suffix=B)" "normal" | ||
| } | ||
|
|
||
| # Create and insert a PID number to lockfile. | ||
| _create_lock | ||
| # Create and insert a PID number to lockfile (skip for read-only commands). | ||
| if [ "$option" != "readonly" ]; then | ||
| _create_lock | ||
| fi | ||
|
|
||
| # Make sure aria2c (in general first parameter from _DOWNLOADER) is available. | ||
| # Read-only commands don't use the downloader. | ||
| CMD="$(echo "$_DOWNLOADER" | sed 's/^\s*\([^ ]\+\).*$/\1/')" | ||
| if [ ! "$(command -v "$CMD")" ]; then | ||
| if [ "$option" != "readonly" ] && [ ! "$(command -v "$CMD")" ]; then | ||
| msg "Command not found: $CMD" "normal" "err" | ||
| msg "You must configure $CONFFILE to use aria2c or another supported download manager" "normal" "err" | ||
| CLEANUP_STATE=1 | ||
|
|
@@ -534,7 +542,7 @@ SHA256_SUPPORTED= | |
| SHA1_SUPPORTED= | ||
| MD5sum_SUPPORTED= | ||
| HASH_SUPPORTED= | ||
| if [ "$CMD" == "aria2c" ]; then | ||
| if [ "$option" != "readonly" ] && [ "$CMD" == "aria2c" ]; then | ||
| for supported_hash in $(LC_ALL=C aria2c -v | sed '/^Hash Algorithms:/!d; s/\(^Hash Algorithms: \|,\)\+//g'); do | ||
| case "$supported_hash" in | ||
| sha-512) SHA512_SUPPORTED=y; HASH_SUPPORTED=y ;; | ||
|
|
@@ -584,16 +592,19 @@ done | |
| # Export the variables to make them available in subshells (aka the | ||
| # downloader command). | ||
| eval "$(apt-config shell ftp_proxy Acquire::ftp::proxy)" | ||
| export ftp_proxy | ||
| eval "$(apt-config shell http_proxy Acquire::http::proxy)" | ||
| export http_proxy | ||
| eval "$(apt-config shell https_proxy Acquire::https::proxy)" | ||
| export https_proxy | ||
| # Only export proxy variables if they are non-empty; exporting empty proxy | ||
| # variables can confuse tools like apt-listbugs with "unsupported proxy ''" errors. | ||
| [ -n "$ftp_proxy" ] && export ftp_proxy || unset ftp_proxy | ||
| [ -n "$http_proxy" ] && export http_proxy || unset http_proxy | ||
| [ -n "$https_proxy" ] && export https_proxy || unset https_proxy | ||
|
|
||
| # aria2 has no socks support (see https://github.com/aria2/aria2/issues/153) | ||
| if echo "$http_proxy" | grep -q "^socks5h://" || echo "$https_proxy" | grep -q "^socks5h://"; then | ||
| msg "Socks proxy detected. Falling back to ${_APTMGR}" "hint" | ||
| "${_APTMGR}" "${APT_SCRIPT_WARNING[@]}" "$@" | ||
| CLEANUP_STATE=$? | ||
| exit | ||
| fi | ||
|
Comment on lines
603
to
609
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proxy handling now uses
unset ftp_proxy/http_proxy/https_proxywhen the value is empty. This loses the script’s earlier distinction between “set but empty” vs “unset” (preserved across sudo) and can change behavior for tools that fall back toHTTP_PROXY/HTTPS_PROXYwhen the lowercase vars are unset. To avoid exporting empty proxies while keeping semantics stable, prefer removing the export attribute (e.g.,export -n var) or otherwise keep the shell variable defined but unexported when empty.