#!/bin/sh
RM=/bin/rm
CAT=/bin/cat
RPM=
DPKG=/usr/bin/dpkg
# -* sh  path added by autoconfiscator      *-
# -* rm  path added by autoconfiscator      *-
# -* cat path added by autoconfiscator      *-
# -* rpm path added by autoconfiscator      *-
#
# Copyright (c) 2001-2002 by Leni Mayo
#
#	This program 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.
#
#	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.
#

addmeta="no"

if [ -r /etc/redhat-release ]; then
	# Redhat system, add some metadata
	addmeta="yes"
	base_os_release=`$CAT /etc/redhat-release`
	if [ -x $RPM ]; then
	  package_owning_rc=`$RPM -qf /etc/rc`
	fi
elif [ -r /etc/debian_version ]; then
	# Debian system, add some metadata
	addmeta="yes"
	base_os_release=`echo -n "Debian GNU/Linux "; $CAT /etc/debian_version`
	if [ -x $DPKG ]; then
	  package_owning_rc_name=`$DPKG --search /etc/init.d/rc`
	  package_owning_rc_name=${package_owning_rc_name%:*}

	  package_owning_rc_version=`$DPKG --status $package_owning_rc_name | grep Version:`
	  package_owning_rc_version=${package_owning_rc_version/*: /}

	  package_owning_rc="$package_owning_rc_name $package_owning_rc_version"
	fi
#
# tests for other OSes and distributions go here...
#
fi

if [ $addmeta = "yes" ]; then
  tmpfile=`mktemp -q /tmp/XXXXXX`
  $CAT <<EOF > $tmpfile
<rdf:Description about="graph2"              
  serel:base_os_release="$base_os_release"
  serel:package_owning_rc="$package_owning_rc"
/>
EOF
  serelc --query graph id graph2 add $tmpfile
  status=$?
  $RM $tmpfile
else
  serelc --query graph 
  status=$?
fi

exit $status
