#!/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" get_pkginfo "$file" | grep '^'"$field"'' | awk -F' = ' '{print $2}' } function die_usage() { echo "Syntax: introspect.sh [options]" echo "" echo "Valid actions:" echo "all " echo "field " echo "files " exit 1 } assert_le 2 $# "Not enough arguments" case "$1" in "all") assert_eq 2 $# get_pkginfo $2 ;; "field") assert_eq 3 $# get_pkginfo_field $2 $3 ;; "files") assert_eq 2 $# echo Files not implemented exit 1 ;; *) echo "Unknown action \"$1\"" die_usage ;; esac