summaryrefslogtreecommitdiffstats
path: root/bin/initpkgtree
blob: 77d8e47c22fd5922b5c42a57daaa0008b81e3815 (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
#!/bin/sh
# Initializes files and their sections in a package tree directory structure.
# Assumes we are already inside of a package tree's root directory.

prog=initpkgtree

if [ $# -eq 0 ]
then
	echo "usage: $prog [filename] [section 1] [section 2] [...]" 1>&2
	exit 2
fi

if [ -d "$1" ]
then
	echo "$prog: a file named $1 already exists in the package tree" 1>&2
	exit 101
fi

dups=`for sect; do echo "$sect"; done | awk '
{ dups[$1]++ } END { for(d in dups) if(dups[d] > 1) printf d " " }'
`
if [ "$dups" ]
then
	echo "$prog: duplicate sections not permitted: $dups" 1>&2
	exit 102
fi

mkdir "$1"
cd "$1"
shift

for sect
do
	d="$sect"
	mkdir "$d"
	for f in beg body end
	do
		touch "$d/$f"
	done
done