[Buildroot] [PATCHv4 6/8] support/download/scp: implement source-check

Thomas De Schampheleire patrickdepinguin at gmail.com
Fri Feb 15 21:08:01 UTC 2019


From: Thomas De Schampheleire <thomas.de_schampheleire at nokia.com>

We use 'test -f' rather than 'ls' because 'test' is a mandatory POSIX
utility while 'ls' is not.

Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire at nokia.com>
---
 support/download/scp | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

v4: (feedback Yann E. Morin)
- use true/false as values to 'checkonly'
- replace incorrect 'exit $?' by explicit 'exit 0'
- use 'test -f' instead of 'ls' which is more certain to be present (POSIX
  mandatory utility)

v3: no changes

diff --git a/support/download/scp b/support/download/scp
index 80cf495c4e..52ccf06d6e 100755
--- a/support/download/scp
+++ b/support/download/scp
@@ -7,17 +7,21 @@ set -e
 #
 # Options:
 #   -q          Be quiet.
+#   -C          Only check that the file exists remotely.
 #   -o FILE     Copy to local file FILE.
 #   -f FILE     Copy from remote file FILE.
 #   -u URI      Download file at URI.
 #
 # Environment:
 #   SCP       : the scp command to call
+#   SSH       : the ssh command to use for checkonly
 
 verbose=
+checkonly=false
 while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
     case "${OPT}" in
     q)  verbose=-q;;
+    C)  checkonly=true;;
     o)  output="${OPTARG}";;
     f)  filename="${OPTARG}";;
     u)  uri="${OPTARG}";;
@@ -33,8 +37,19 @@ shift $((OPTIND-1)) # Get rid of our options
 _scp() {
     eval ${SCP} "${@}"
 }
+_ssh() {
+    eval ${SSH} "${@}"
+}
 
 # Remove any scheme prefix
 uri="${uri##scp://}"
 
+if ${checkonly}; then
+    # uri now looks like:  foo.example.org:some/directory
+    domain="${uri%%:*}"
+    path="${uri#*:}/${filename}"
+    _ssh ${verbose} "${@}" "'${domain}'" test -f "'${path}'" > /dev/null
+    exit 0
+fi
+
 _scp ${verbose} "${@}" "'${uri}/${filename}'" "'${output}'"
-- 
2.19.2




More information about the buildroot mailing list