From e0c6d9110f658d1fb22c07fa398d3f50b23612e3 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Thu, 26 Jul 2018 21:53:18 +1200 Subject: Fill some help holes in --- introspect.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/introspect.sh b/introspect.sh index 9ae80ed..850d03b 100755 --- a/introspect.sh +++ b/introspect.sh @@ -1,32 +1,69 @@ #!/bin/bash +function assert_eq() { + local expected="$1" + local actual="$2" + local message="$3" + if [ "$1" -ne "$2" ] ; then + if [ ! -z "$message" ]; then + echo "$message" + fi + die_usage + fi +} + +function assert_le() { + local expected="$1" + local actual="$2" + local message="$3" + if [ "$1" -gt "$2" ] ; then + if [ ! -z "$message" ]; then + echo "$message" + fi + die_usage + fi +} + +function get_pkginfo() { + local file="$1" + # FIXME remove dep on GNU tar + tar --to-stdout -xf "$file" .PKGINFO +} + function get_pkginfo_field() { local file="$1" local field="$2" - # FIXME remove dep on GNU tar - tar --to-stdout -xf "$file" .PKGINFO | grep '^'"$field"'' | awk -F' = ' '{print $2}' + get_pkginfo "$file" | grep '^'"$field"'' | awk -F' = ' '{print $2}' } function die_usage() { - echo "FIXME" + echo "Syntax: introspect.sh [options]" + echo "" + echo "Valid actions:" + echo "all " + echo "field " + echo "files " + exit 1 } -if [ "$#" -le 2 ]; then - echo Not enough arguments - die_usage -fi +assert_le 2 $# "Not enough arguments" case "$1" in + "all") + assert_eq 2 $# + get_pkginfo $2 + ;; "field") - # FIXME must have two more aguments + assert_eq 3 $# get_pkginfo_field $2 $3 ;; "files") - echo Not implemented + assert_eq 2 $# + echo Files not implemented exit 1 ;; *) - echo "Unknown action \"$2\"" + echo "Unknown action \"$1\"" die_usage ;; esac -- cgit v1.1