#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG  				#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2017 Christopher Bratusek		#
#							#
#########################################################

if ! which aapt; then
	echo -e "aapt not found, apkdump won't work."
	exit 1
fi

opt=${1}
shift

case ${opt} in

	name )
		aapt dump badging "${1}" 2>/dev/null | gawk -F \' '/^package: name/{print $2}'
	;;

	version )
		aapt dump badging "${1}" 2>/dev/null | gawk -F \' '/^package: name/{print $6}'
	;;

	versioncode )
		aapt dump badging "${1}" 2>/dev/null | gawk -F \' '/^package: name/{print $4}'
	;;

	perms )
		aapt dump badging "${1}" 2>/dev/null | gawk -F \' '/^uses-permission:/{print $2}'
	;;

	*)
		bashstyle-help -a "Christopher Roy Bratusek" -e "nano@jpberlin.de" -h "http://www.nanolx.org/"\
			-l "GNU GPL v3" -n "apkdump" -s "grab apk infos using aapt" -v "${BSNG_VERSION}" -y "${BSNG_YEAR}"\
			-o "name:apk|get package name of apk"\
			-o "version:apk|get human-readable version of apk"\
			-o "versioncode:apk|get version code of apk"\
			-o "perms:apk|get list of requested permissions"
	;;

esac
