Sophie

Sophie

distrib > Altlinux > 4.1 > i586 > by-pkgid > 04b7f1b4038b16bbd79f841c0df46b39 > files > 2

rpm-build-mozilla.org-1.1-alt0.M41.2.src.rpm

#!/bin/sh -efu
#
# Copyright (C) 2008  Alexey Gladkov <gladkov.alexey@gmail.com>
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
# http://developer.mozilla.org/en/docs/install.rdf
# http://developer.mozilla.org/en/docs/Toolkit_version_format
# http://developer.mozilla.org/en/docs/Enhanced_Extension_Installation
# http://kb.mozillazine.org/Install.rdf
#

. shell-args
. shell-error
. shell-quote

. @datadir@/mozilla-sh-functions

show_help() {
	cat <<-EOF
	Usage: $PROG [Options] install.rdf

	Options:

	  -q, --query=STRING      query value in install.rdf info;
	  -t, --target[=STRING]   show product rpm requires;
	  -i, --info              show common info from the install.rdf;
	  -H, --human             show product name instead UID;
	  -f, --force             ignore errors;
	  -v, --verbose           print a message for each action;
	  -V, --version           print program version and exit;
	  -h, --help              show this text and exit.

	Report bugs to gladkov.alexey@gmail.com

EOF
	exit
}

print_version() {
	cat <<EOF
$PROG version $PROG_VERSION
Written by Alexey Gladkov <gladkov.alexey@gmail.com>

Copyright (C) 2008  Alexey Gladkov <gladkov.alexey@gmail.com>
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
	exit
}


TEMP=`getopt -n $PROG -o H,q:,t:,f,i,v,V,h -l human,force,info,target::,query:,verbose,version,help -- "$@"` ||
	show_usage
eval set -- "$TEMP"

param=
mode=
force=
show_human=

while :; do
	case "$1" in
	    -q|--query) shift
		param="$1"
		mode='query'
		;;
	    -t|--target) shift
		param="$1"
		show_human=1
		mode='target'
		;;
	    -i|--info) mode='info'
		;;
	    -f|--force) force=1
		;;
	    -H|--human) show_human=1
		;;
	    -v|--verbose) verbose=-v
		;;
	    -V|--version) print_version
		;;
	    -h|--help) show_help
		;;
	    --) shift; break
		;;
	    *) fatal "Unrecognized option: $1"
		;;
	esac
	shift
done

if [ "$#" -eq 0 ]; then
	fatal 'Not enough arguments.'
elif [ "$#" -gt 1 ]; then
	fatal 'Too many arguments.'
fi

installrdf="$(readlink -ev "$1")"
rappercmd='rapper -i rdfxml -o ntriples -r -q'

if ! out="$($rappercmd "$installrdf" 2>/dev/null)"; then
	out=
	$rappercmd "$installrdf" 1>/dev/null ||:

	[ -z "$force" ] ||
		out="$($rappercmd -e "$installrdf" 2>/dev/null)"
fi

[ -n "$out" ] ||
	fatal "$installrdf: Unable to parse file"

urn='<urn:mozilla:install-manifest>'
url='http://www.mozilla.org/2004/em-rdf'

targetapp="$(quote_sed_regexp "$urn <$url#targetApplication>")"
app="$(quote_sed_regexp "$urn <$url")"

rdf_query() {
	local value
	value="$(quote_sed_regexp "$1")"
	printf '%s\n' "$out" |
		sed -n -e "s@^$app#$value> \"\([^\"]\+\)\" \.@\1@p"
}

human_type() {
	case "$1" in
		2)  echo 'Extension' ;;
		4)  echo 'Theme' ;;
		8)  echo 'Locale' ;;
		32) echo 'Multiple Item Package' ;;
	esac
}

rdf_info() {
	printf '%s\n' "$out" |
		sed -n -e "s@^$app#\(id\|version\|type\|name\|description\|creator\|contributor\|developer\|translator\|homepageURL\|updateInfoURL\)> \"\([^\"]\+\)\" \.@\1 \2@p" |
	while read -r param value; do
		if [ "$param" = 'type' ]; then
			[ -n "$show_human" ] &&
				printf '%s\t%s\n' "$param" "`human_type $value`" ||
				printf '%s\t%s\n' "$param" "$value"
		else
			printf '%s\t%s\n' "$param" "$value"
		fi
	done
}

rdf_target() {
	local uid
	[ -z "${1-}" ] ||
		uid="`name2uid "$1"`"

	printf '%s\n' "$out" |
		sed -n -e "s@^$targetapp \([^ ]\+\) \.@\1@p" |
	while read -r id; do
		id="$(quote_sed_regexp "$id")"

		printf '%s\n' "$out" |
			sed -n -e "s@^$id <$url#\(id\|minVersion\|maxVersion\)> \"\([^\"]\+\)\" \.@\1 \2@p" |
		while read -r param value; do
			case "$param" in
				id)
					id="$value"
					[ -n "$show_human" ] &&
						p="`uid2name "$id"`" ||
						p="$id"
					;;
				minVersion) min="$value" ;;
				maxVersion) max="$value" ;;
			esac

			if [ -n "${p-}" -a -n "${min-}" -a -n "${max-}" ]; then
				if [ -n "$uid" -a "$uid" != "$id" ]; then
					p= id= min= max=
					continue
				fi
				show_requires
				p= id= min= max=
			fi
		done
	done
}

case "$mode" in
	info)   rdf_info ;;
	target) rdf_target "$param" ;;
	query)  rdf_query "$param" ;;
esac