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