From 2855d77e300732ab9670f4e01fa8abc5356c7086 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Fri, 18 Sep 2020 16:39:20 -0700 Subject: [PATCH] allow terms and selection to be specified on the command line... This allows you to run: sh snapaid.sh find amd64 vmdk CURRENT xz 1 and it will automatically d/l the latest vm image that is vmdk, xz compressed for the amd64 architecture. --- snapaid.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/snapaid.sh b/snapaid.sh index ab9a905..b059292 100755 --- a/snapaid.sh +++ b/snapaid.sh @@ -313,6 +313,7 @@ if [ x"$1" = x"verify" ]; then verifyfile "$vermid" "$i" done elif [ x"$1" = x"find" ]; then + shift fetch "$currenturl" tmpdir=$(mktemp -d -t snapaid) @@ -320,11 +321,12 @@ elif [ x"$1" = x"find" ]; then trap "rm -r $tmpdir" 0 ( cd "$tmpdir"; - xzcat "$STOREDIR"/snapshot.idx.xz | sort -r -k 5 > selection; + xzcat "$STOREDIR"/snapshot.idx.xz | sort -r -k 5 -k 2 > selection; while :; do - # display current list cnt=$(wc -l < selection) - awk ' + if [ x"$1" = x"" ]; then + # display current list + awk ' BEGIN { # xzcat snapshot.complete.idx.xz | ./maxcol.awk # xzcat snapshot.complete.idx.xz | awk "{ print $3}" | sort -u @@ -347,9 +349,15 @@ BEGIN { cnt += 1 } - ' selection + ' selection + fi - read -p 'Select image #, enter search term, reset, or quit: ' sel + if [ x"$1" != x"" ]; then + sel="$1" + shift + else + read -p 'Select image #, enter search term, reset, or quit: ' sel + fi if [ x"$sel" = x"reset" ]; then xzcat "$STOREDIR"/snapshot.idx.xz | sort -r -k 5 > selection; continue @@ -491,7 +499,7 @@ else fi echo "Usage:" echo " $0 verify file ..." - echo " $0 find" + echo " $0 find [ termselection ... ]" echo "" echo "The verify option will attempt to verify each file specified." echo ""