Annotation of src/usr.bin/sudo/mkinstalldirs, Revision 1.5
1.2 millert 1: #! /bin/sh
1.1 millert 2: # mkinstalldirs --- make directory hierarchy
3: # Author: Noah Friedman <friedman@prep.ai.mit.edu>
4: # Created: 1993-05-16
5: # Public domain
6:
1.2 millert 7: umask 022
1.1 millert 8: errstatus=0
1.2 millert 9: dirmode=""
10:
11: usage="\
12: Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
13:
14: # process command line arguments
15: while test $# -gt 0 ; do
1.3 millert 16: case $1 in
17: -h | --help | --h*) # -h for help
18: echo "$usage" 1>&2
19: exit 0
20: ;;
21: -m) # -m PERM arg
22: shift
23: test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
24: dirmode=$1
25: shift
26: ;;
27: --) # stop option processing
28: shift
29: break
30: ;;
31: -*) # unknown option
32: echo "$usage" 1>&2
33: exit 1
34: ;;
35: *) # first non-opt arg
36: break
37: ;;
38: esac
1.2 millert 39: done
1.3 millert 40:
41: for file
42: do
43: set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
44: shift
1.1 millert 45:
1.3 millert 46: pathcomp=
47: for d
48: do
49: pathcomp="$pathcomp$d"
50: case $pathcomp in
51: -*) pathcomp=./$pathcomp ;;
52: esac
53:
54: if test ! -d "$pathcomp"; then
55: echo "mkdir $pathcomp"
56:
57: mkdir "$pathcomp" || lasterr=$?
58:
59: if test ! -d "$pathcomp"; then
60: errstatus=$lasterr
61: else
62: if test ! -z "$dirmode"; then
63: echo "chmod $dirmode $pathcomp"
64: lasterr=""
65: chmod "$dirmode" "$pathcomp" || lasterr=$?
66:
67: if test ! -z "$lasterr"; then
68: errstatus=$lasterr
69: fi
70: fi
71: fi
72: fi
1.1 millert 73:
1.3 millert 74: pathcomp="$pathcomp/"
75: done
1.1 millert 76: done
77:
78: exit $errstatus
79:
1.2 millert 80: # Local Variables:
1.3 millert 81: # mode: shell-script
82: # sh-indentation: 2
1.2 millert 83: # End:
1.3 millert 84: # mkinstalldirs ends here