diff options
Diffstat (limited to 'bin/swr.mi5')
-rw-r--r-- | bin/swr.mi5 | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/bin/swr.mi5 b/bin/swr.mi5 new file mode 100644 index 00000000..9b73b6d6 --- /dev/null +++ b/bin/swr.mi5 @@ -0,0 +1,52 @@ +# Transparently wrap scp(1) targets to read (not write) on the command line +self=swr + +<% +include(`include/mktd.m4') +%> + +# Set a flag to manage resetting the positional parameters at the start of the +# loop +n=1 +for arg ; do + + # If this is our first iteration, reset the shell parameters + case $n in + 1) set -- ;; + esac + + # Test whether this argument looks like a remote file + if ( + + # Test it contains a colon + case $arg in + *:*) ;; + *) exit 1 ;; + esac + + # Test the part before the first colon has at least one character and + # only hostname characters + case ${arg%%:*} in + '') exit 1 ;; + *[!a-zA-Z0-9-.]*) exit 1 ;; + esac + + ) ; then + + # Looks like a remote file request; try to copy it into the temporary + # directory, bail out completely if we can't + dst=$td/$n + scp -q -- "$arg" "$dst" || exit + set -- "$@" "$dst" + + else + # Just a plain old argument; stack it up + set -- "$@" "$arg" + fi + + # Bump n + n=$((n+1)) +done + +# Run the command with the processed arguments +exec "$@" |