#!/bin/sh
|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# Filename: lib/misc/hunter.sh
|
|
# Copyright (C) 2006 - 2008 The OpenSDE Project
|
|
#
|
|
# More information can be found in the files COPYING and README.
|
|
#
|
|
# This program 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; version 2 of the License. A copy of the
|
|
# GNU General Public License can be found in the file COPYING.
|
|
# --- SDE-COPYRIGHT-NOTE-END ---
|
|
|
|
|
|
function usage() {
|
|
echo "Usage: $0 [-cfg <config:-default>] [-<stage>] [-dot|-tsort] [packages...]"
|
|
exit $1
|
|
}
|
|
|
|
stage=
|
|
config=default
|
|
mode=tsort
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
-[0-9]) stage=${1:1:1}; ;;
|
|
-cfg) config="$2"; shift; ;;
|
|
-dot) mode=dot ;;
|
|
-tsort) mode=tsort ;;
|
|
-*) usage 1 ;;
|
|
*) break ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if [ ! -r "config/$config/packages" ]; then
|
|
usage 2
|
|
fi
|
|
|
|
if [ -n "$stage" ]; then
|
|
sed -n -e "s,^X [^ ]*$stage[^ ]* [^ ]* [^ ]* \([^ ]*\) .*,\1,p" "config/$config/packages"
|
|
exit 0
|
|
elif [ $# -eq 0 ]; then
|
|
exit 0
|
|
fi
|
|
|
|
if [ $# -eq 1 ]; then
|
|
pattern="$1"
|
|
else
|
|
pattern="$@"
|
|
pattern="(${pattern// /|})"
|
|
fi
|
|
|
|
rm -f hunter.$mode
|
|
|
|
case "$mode" in
|
|
tsort) ;;
|
|
dot) echo "digraph G {" ;;
|
|
esac >> hunter.$mode
|
|
|
|
for pkg; do
|
|
cachefile=$( ls -1 package/*/$pkg/$pkg.cache 2> /dev/null )
|
|
if [ -z "$cachefile" ]; then
|
|
echo "No Information for '$pkg' found." 1>&2
|
|
case "$mode" in
|
|
tsort) echo "$pkg $pkg" ;;
|
|
dot) echo " $pkg ;" ;;
|
|
esac >> hunter.$mode
|
|
else
|
|
case "$mode" in
|
|
tsort) echo "$pkg $pkg" ;;
|
|
dot) echo " $pkg ;" ;;
|
|
esac >> hunter.$mode
|
|
|
|
for dep in `grep -E " $pattern\$" "$cachefile" | cut -d' ' -f2`; do
|
|
case "$mode" in
|
|
tsort) echo "$dep $pkg" ;;
|
|
dot) echo " $dep -> $pkg;" ;;
|
|
esac >> hunter.$mode
|
|
done
|
|
fi
|
|
done
|
|
|
|
case "$mode" in
|
|
tsort) ;;
|
|
dot) echo "}" ;;
|
|
esac >> hunter.$mode
|