#!/bin/bash
# upkg-show
#
# show package info and content
#
# Copyright (C) 2004 Raffaele Sandrini, Jürg Billeter
#
# This file is part of Upkg (http://www.upkg.org).
#
# Upkg is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# Upkg 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 Upkg; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Authors:
#   Raffaele Sandrini <rasa at paldo dot org>
#   Jürg Billeter <juerg at paldo dot org>

[ $# -eq 1 ] || { echo "Usage: $0 PACKAGE" ; exit 1 ; }

[ -e /var/lib/upkg/packages/$1 ] || { echo "Package $1 could not be found" ; exit 1 ; }

function upkgcat ()
{
	for f in "$@"; do
		if [ -e "$f.zst" ]; then
			zstdcat "$f.zst"
		elif [ -e "$f.xz" ]; then
			xzcat "$f.xz"
		elif [ -e "$f.bz2" ]; then
			bzcat "$f.bz2"
		elif [ -e "$f.gz" ]; then
			zcat "$f.gz"
		elif [ -e "$f" ]; then
			cat "$f"
		fi
	done
}

echo $(readlink /var/lib/upkg/packages/$1)
echo ----
cat /var/lib/upkg/packages/$(readlink /var/lib/upkg/packages/$1).info
upkgcat /var/lib/upkg/files/$(readlink /var/lib/upkg/packages/$1).{digest,links,config} 2>/dev/null | sed -e 's/  / /' | ( upkgcat /var/lib/upkg/files/$(readlink /var/lib/upkg/packages/$1).dirs 2>/dev/null ; cut -d ' ' -f 2 ) | sort | (
	while read file ; do
		echo "- $file"
	done
)
