summaryrefslogtreecommitdiffstats
path: root/bin/catpkgtree
blob: 846655caad27edd09da5f83e0465c378c397d1e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh

PROG=catpkgtree

findnode()
{
	for f in *
	do
		[ "$f" = '*' ] && break
		[ -f "$f" ] || continue
		case f in
		[0-9][0-9]-*)
			n=`echo "$f" | sed 's/^...//'`
			if [ "$n" = "$1" ]
			then
				echo "$f"
				return 0
			fi
		esac
	done
	return 1
}

if [ $# -ne 1 ]
then
	echo "usage: $PROG [tree path] < [text to append]" 1>&2
	exit 2
fi

if ! cd PKGTREE
then
	echo "$PROG: PKGTREE dir must be present in current dir" 1>&2
	exit 100
fi

IFS=/ set -- "$1"
if [ $# -lt 2 ]
then
	echo "$PROG: path to tree node must be separated by forward slashes" 1>&2
	exit 101
fi

if ! cd "$1"
then
	echo "$PROG: $1 is not a valid package file" 1>&2
	exit 102
fi
shift

while [ $# -gt 1 ]
do
	f=`findnode $1`
	if [ $? -ne 0 ] || ! cd "$f"
	then
		echo "$PROG: $1 is not a valid node name" >1&2
		exit 102
	fi
	shift
done

f=`findnode $1`
if [ $? -ne 0 ] || [ ! -f "$f" ]
then
	echo "$PROG: $f is not a valid final node" 1>&2
	exit 102
fi
cat >> "$f"