[Buildroot] [PATCH 1/1] support/download/smb: Add basic support for smb download.

Guillaume Chaye guillaume.chaye at zeetim.com
Tue Apr 15 14:22:08 UTC 2025


This method requires samba to be installed on the host machine since it uses smbget command to fetch remote files.
Curl also support basic smb download but currently the curl script does not support -u option.

Signed-off-by: Guillaume Chaye <guillaume.chaye at zeetim.com>
---
 Config.in                   |  4 +++
 package/pkg-download.mk     |  1 +
 support/download/dl-wrapper |  2 +-
 support/download/smb        | 51 +++++++++++++++++++++++++++++++++++++
 4 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100755 support/download/smb

diff --git a/Config.in b/Config.in
index a543091d4f..c562310c2b 100644
--- a/Config.in
+++ b/Config.in
@@ -144,6 +144,10 @@ config BR2_SCP
 	string "Secure copy (scp) command"
 	default "scp -o ConnectTimeout=10"
 
+config BR2_SMBGET
+	string "Server Message Block (smbget) command"
+	default "smbget"
+
 config BR2_SFTP
 	string "Secure file transfer (sftp) command"
 	default "sftp -o ConnectTimeout=10"
diff --git a/package/pkg-download.mk b/package/pkg-download.mk
index cf5959ea95..e1f64eb392 100644
--- a/package/pkg-download.mk
+++ b/package/pkg-download.mk
@@ -114,6 +114,7 @@ define DOWNLOAD
 	LOCALFILES="$(call qstrip,$(BR2_LOCALFILES))" \
 	SCP="$(call qstrip,$(BR2_SCP))" \
 	SFTP="$(call qstrip,$(BR2_SFTP))" \
+	SMBGET="$(call qstrip,$(BR2_SMBGET))" \
 	SVN="$(call qstrip,$(BR2_SVN))" \
 	WGET="$(call qstrip,$(BR2_WGET))" \
 	BR_NO_CHECK_HASH_FOR="$(if $(BR2_DOWNLOAD_FORCE_CHECK_HASHES),,$(BR_NO_CHECK_HASH_FOR))" \
diff --git a/support/download/dl-wrapper b/support/download/dl-wrapper
index 5445aad5a7..f7aa82fb9f 100755
--- a/support/download/dl-wrapper
+++ b/support/download/dl-wrapper
@@ -95,7 +95,7 @@ main() {
         backend_urlencode="${uri%%+*}"
         backend="${backend_urlencode%|*}"
         case "${backend}" in
-            git|svn|cvs|bzr|file|scp|hg|sftp) ;;
+            git|svn|cvs|bzr|file|scp|hg|sftp|smb) ;;
             ftp|ftps) backend="curl" ;;
             *) backend="wget" ;;
         esac
diff --git a/support/download/smb b/support/download/smb
new file mode 100755
index 0000000000..98136081d6
--- /dev/null
+++ b/support/download/smb
@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+
+# We want to catch any unexpected failure, and exit immediately
+set -e
+
+# Download helper for smbget, to be called from the download wrapper script
+#
+# Options:
+#   -q          Be quiet.
+#   -o FILE     Save into file FILE.
+#   -f FILENAME The filename of the tarball to get at URL.
+#   -u URL      Download file at URL (up to the directory).
+#
+# Environment:
+#   SMBGET   : the smbget command to call (default: smbget)
+#   SMBUSER  : the SMB username (default: guest)
+#   SMBPASS  : the SMB password (default: empty)
+
+quiet=
+while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
+    case "${OPT}" in
+    q)  quiet=-q;;
+    o)  output="${OPTARG}";;
+    f)  filename="${OPTARG}";;
+    u)  url="${OPTARG}";;
+    :)  printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
+    \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
+    esac
+done
+
+shift $((OPTIND-1)) # Get rid of our options
+
+SMBUSER="${SMBUSER:-guest}"
+SMBPASS="${SMBPASS:-}"
+
+_smbget() {
+    if [ -z "${quiet}" ]; then
+        printf '%s ' "${SMBGET}" -U "${SMBUSER}%***" -o "${output}" "${url%/}/${filename}"
+        printf '\n'
+    fi
+    _plain_smbget "$@"
+}
+
+_plain_smbget() {
+    full_url="${url%/}/${filename}"
+
+    # shellcheck disable=SC2086
+    eval ${SMBGET} ${quiet} -U "'${SMBUSER}%${SMBPASS}'" -o "'${output}'" "'${full_url}'"
+}
+
+_smbget "$@"
-- 
2.39.5



More information about the buildroot mailing list