]> rtime.felk.cvut.cz Git - orte.git/blob - admin/mkinstalldirs
OCERA SF CVS tree of ORTE framework updated to
[orte.git] / admin / mkinstalldirs
1 #! /bin/sh
2 # mkinstalldirs --- make directory hierarchy
3 # Original author: Noah Friedman <friedman@prep.ai.mit.edu>
4 # Created: 1993-05-16
5 # Public domain.
6
7 scriptversion=2003-09-26.19
8
9 errstatus=0
10 dirmode=""
11
12 usage="\
13 Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
14
15 Create each directory DIR (with mode MODE, if specified), including all
16 leading file name components.
17 "
18
19 # process command line arguments
20 while test $# -gt 0 ; do
21   case $1 in
22     -h | --help | --h*)         # -h for help
23       echo "$usage"
24       exit 0
25       ;;
26     -m)                         # -m PERM arg
27       shift
28       test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
29       dirmode=$1
30       shift
31       ;;
32     --version)
33       echo "$0 $scriptversion"
34       exit 0
35       ;;
36     --)                         # stop option processing
37       shift
38       break
39       ;;
40     -*)                         # unknown option
41       echo "$usage" 1>&2
42       exit 1
43       ;;
44     *)                          # first non-opt arg
45       break
46       ;;
47   esac
48 done
49
50 for file
51 do
52   if test -d "$file"; then
53     shift
54   else
55     break
56   fi
57 done
58
59 case $# in
60   0) exit 0 ;;
61 esac
62
63 case $dirmode in
64   '')
65     if mkdir -p -- . 2>/dev/null; then
66       echo "mkdir -p -- $*"
67       exec mkdir -p -- "$@"
68     else
69       # On NextStep and OpenStep, the `mkdir' command does not
70       # recognize any option.  It will interpret all options as
71       # directories to create, and then abort because `.' already
72       # exists.
73       test -d ./-p && rmdir ./-p
74       test -d ./-- && rmdir ./--
75     fi
76     ;;
77   *)
78     if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
79       echo "mkdir -m $dirmode -p -- $*"
80       exec mkdir -m "$dirmode" -p -- "$@"
81     else
82       # Clean up after NextStep and OpenStep mkdir.
83       for d in ./-m ./-p ./-- "./$dirmode";
84       do
85         test -d $d && rmdir $d
86       done
87     fi
88     ;;
89 esac
90
91 for file
92 do
93   set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
94   shift
95
96   pathcomp=
97   for d
98   do
99     pathcomp="$pathcomp$d"
100     case $pathcomp in
101       -*) pathcomp=./$pathcomp ;;
102     esac
103
104     if test ! -d "$pathcomp"; then
105       echo "mkdir $pathcomp"
106
107       mkdir "$pathcomp" || lasterr=$?
108
109       if test ! -d "$pathcomp"; then
110         errstatus=$lasterr
111       else
112         if test ! -z "$dirmode"; then
113           echo "chmod $dirmode $pathcomp"
114           lasterr=""
115           chmod "$dirmode" "$pathcomp" || lasterr=$?
116
117           if test ! -z "$lasterr"; then
118             errstatus=$lasterr
119           fi
120         fi
121       fi
122     fi
123
124     pathcomp="$pathcomp/"
125   done
126 done
127
128 exit $errstatus
129
130 # Local Variables:
131 # mode: shell-script
132 # sh-indentation: 2
133 # eval: (add-hook 'write-file-hooks 'time-stamp)
134 # time-stamp-start: "scriptversion="
135 # time-stamp-format: "%:y-%02m-%02d.%02H"
136 # time-stamp-end: "$"
137 # End: