[jhalfs] 02/02: Add the possibility to use curl if wget is not present

"Git Owner" ([email protected] via alfs-discuss Mailing List) <[email protected]> Fri, 24 Jan 2025 17:57:13 +0000
Newsgroups gmane.linux.lfs.automated
Message-ID <[email protected]>
This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch trunk
in repository jhalfs.

commit 40e87dacca28c8598dd6a60b54e090ca1bb8b6fc
Author: Pierre Labastie <[email protected]>
AuthorDate: Fri Jan 24 18:52:28 2025 +0100

    Add the possibility to use curl if wget is not present
    
    This is only for LFS. Still require wget if BLFS tools are requested.
    Fix #1744
---
 common/libs/func_check_version.sh | 34 +++++++++++++++++++++++++++-------
 common/libs/func_download_pkgs    | 22 ++++++++++++++++------
 2 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/common/libs/func_check_version.sh b/common/libs/func_check_version.sh
index 1a87fcc..6f89072 100644
--- a/common/libs/func_check_version.sh
+++ b/common/libs/func_check_version.sh
@@ -189,19 +189,39 @@ inline_doc
     exit 1
   fi
 
-  # Check for wget presence (using a dummy version)
+  # Check for wget  or curl presence (using dummy versions)
   # Do this only if we need to download packages
+  # Return the result in a global variable
   if [ "$GETPKG" = y ]; then
+  declare -g DOWNLOADER
+  # First try wget
     WGET_LOC="$(whereis -b wget | cut -d" " -f2)"
     if [ -x $WGET_LOC ]; then
       wgetVer="$(wget --version | head -n1 | cut -d" " -f3)"
-      if echo "$wgetVer" | grep -q '^[[:digit:]]'; then
-        check_version "1.0.0"  "${wgetVer}"      "WGET"
-      else echo Wget detected, but no version found. Continuing anyway.
-      fi
+    fi
+    if echo "$wgetVer" | grep -q '^[[:digit:]]'; then
+      check_version "1.0.0"  "${wgetVer}"      "WGET"
+      DOWNLOADER=wget
     else
-      echo "${nl_}\"${RED}wget${OFF}\" ${BOLD}must be installed on your system for jhalfs to run"
-      exit 1
+    # Stop here if requesting blfs tools.
+      if [ "$BLFS_TOOL" = y ]; then
+        echo "${nl_}\"${RED}wget${OFF}\" ${BOLD}must be"
+        echo "installed on your system for using blfs tools"
+        exit 1
+      fi
+    # Then try curl
+      CURL_LOC="$(whereis -b curl | cut -d" " -f2)"
+      if [ -x $CURL_LOC ]; then
+        curlVer="$(curl --version | head -n1 | cut -d" " -f2)"
+      fi
+      if echo "$curlVer" | grep -q '^[[:digit:]]'; then
+        check_version "1.0.0"  "${curlVer}"      "CURL"
+        DOWNLOADER=curl
+      else
+        echo "${nl_}Either \"${RED}wget${OFF}\" or \"${RED}curl${OFF}\" ${BOLD}must be"
+        echo "installed on your system for retrieving source files"
+        exit 1
+      fi
     fi
   fi
 
diff --git a/common/libs/func_download_pkgs b/common/libs/func_download_pkgs
index a6d9c7e..777b879 100644
--- a/common/libs/func_download_pkgs
+++ b/common/libs/func_download_pkgs
@@ -9,12 +9,22 @@ get_sources() {              # Download file, write name to MISSING_FILES.DMP if
 
   local URL FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE WGETPARAM MAYBEMORE
 
-  WGETPARAM=""
-  if [[ "${RETRYSRCDOWNLOAD}" = "y" ]] ; then
-    WGETPARAM+="--retry-connrefused"
+  DOWNLDPARAM=""
+  if [ "$DOWNLOADER" = "wget" ] ; then
+    if [[ "${RETRYSRCDOWNLOAD}" = "y" ]] ; then
+      DOWNLDPARAM+="--retry-connrefused"
+    fi
+    DOWNLDPARAM+=" --tries ${RETRYDOWNLOADCNT}"
+    DOWNLDPARAM+=" --timeout ${DOWNLOADTIMEOUT}"
+  fi
+  if [ "$DOWNLOADER" = "curl" ] ; then
+    if [[ "${RETRYSRCDOWNLOAD}" = "y" ]] ; then
+      DOWNLDPARAM+="--retry-connrefused"
+    fi
+    DOWNLDPARAM+=" -LO"
+    DOWNLDPARAM+=" --retry ${RETRYDOWNLOADCNT}"
+    DOWNLDPARAM+=" --max-time ${DOWNLOADTIMEOUT}"
   fi
-  WGETPARAM+=" --tries ${RETRYDOWNLOADCNT}"
-  WGETPARAM+=" --timeout ${DOWNLOADTIMEOUT}"
 
   gs_wrt_message(){
     echo "${RED}$1${OFF}"
@@ -59,7 +69,7 @@ get_sources() {              # Download file, write name to MISSING_FILES.DMP if
 	else
 	  echo "${BOLD}${YELLOW}$FILE: not found in ${BUILDDIR}/sources${OFF}"
 	fi
-        if ! wget "$URL" $WGETPARAM; then
+        if ! $DOWNLOADER "$URL" $DOWNLDPARAM; then
           gs_wrt_message "$FILE not found on any server..SKIPPING"
           continue
         fi

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

-- 
http://lists.linuxfromscratch.org/sympa/info/alfs-discuss
Unsubscribe: See the above information page