1#! /bin/sh
2#
3# @configure_input@
4#
5PERMS=755
6usage() {
7	cat <<EOF
8
9$0
10	makes all the usual ./bin, ./sbin, ./etc, ./lib, ./include, ./info
11	and BSD-style ./man/\* directories
12	if the first option is "-c" it will clean out any empty directories
13	of same.
14	It also sets the permissions to $PERMS on the directories
15	unless overridden by the -p option.
16usage:	$0 [-p|--perms XXX] [-m|--make] [-c|--clean]
17	-p XXX	permissions for directories in chmod suitable format
18	-m	make directories in the current directory
19	-c	clean out empty directories
20
21	Note common man directory conventions
22	'1' - user commands 
23        '3' - library functions 
24        '5' - file formats and conventions 
25        '7' - macro packages and conventions 
26        '8' - administrative commands 
27        'l' - local commands
28
29	by R.K.Owen,Ph.D.
30	version '$Revision: 1.1.1.1.28.1 $	$Date: 2010/11/11 18:23:18 $'
31
32EOF
33}
34
35if [ $# -eq 0 ]
36then
37	usage
38	exit 1
39fi
40
41while [ $# -gt 0 ]
42do
43	case $1 in
44	-p|-perms|--p|--perms)
45		shift
46		PERMS=$1
47		shift
48		continue
49		;;
50	-c|-clean|--c|--clean)
51		if [ ! -s ./man/whatis ]; then
52			rm ./man/whatis
53		else
54			echo ./man/whatis is not empty
55		fi
56		for m in 1 2 3 4 5 6 7 8 n p l
57		do
58			if [ -d ./man/man$m ]; then if [ `ls ./man/man$m|wc -l` -eq 0 ]; then
59				rmdir ./man/man$m
60				if [ -d ./man/cat$m ]; then if [ `ls ./man/cat$m|wc -l` -eq 0 ]; then
61					rmdir ./man/cat$m
62				else
63					echo ./man/cat$m is not empty
64				fi;fi
65			else
66				echo ./man/man$m is not empty
67			fi;fi
68		done
69		for d in bin sbin etc lib include info man
70		do
71			if [ -d ./$d ]; then if [ `ls ./$d|wc -l` -eq 0 ]; then
72				rmdir ./$d
73			else
74				echo ./$d is not empty
75			fi;fi
76		done
77		exit
78		;;
79	-m|-make|--m|--make)
80		for d in bin sbin etc lib include info man
81		do
82			mkdir ./$d ; chmod $PERMS ./$d
83		done
84		touch ./man/whatis ; chmod $PERMS ./man/whatis
85		for m in 1 2 3 4 5 6 7 8 n p l
86		do
87			mkdir ./man/man$m ; chmod $PERMS ./man/man$m
88			mkdir ./man/cat$m ; chmod $PERMS ./man/cat$m
89		done
90		exit
91		;;
92	*)
93		usage
94		exit 2
95		;;
96	esac
97done
98
99exit
100