Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / mkinstalldirs
1 #! /bin/sh
2 #  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # mkinstalldirs --- make directory hierarchy
21 # Author: Noah Friedman <friedman@prep.ai.mit.edu>
22 # Created: 1993-05-16
23 # Public domain
24
25 errstatus=0
26 dirmode=""
27
28 usage="\
29 Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
30
31 # process command line arguments
32 while test $# -gt 0 ; do
33    case "${1}" in
34      -h | --help | --h* )                       # -h for help
35         echo "${usage}" 1>&2; exit 0 ;;
36      -m )                                       # -m PERM arg
37         shift
38         test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
39         dirmode="${1}"
40         shift ;;
41      -- ) shift; break ;;                       # stop option processing
42      -* ) echo "${usage}" 1>&2; exit 1 ;;       # unknown option
43      * )  break ;;                              # first non-opt arg
44    esac
45 done
46
47 for file
48 do
49   if test -d "$file"; then
50     shift
51   else
52     break
53   fi
54 done
55
56 case $# in
57 0) exit 0 ;;
58 esac
59
60 case $dirmode in
61 '')
62   if mkdir -p -- . 2>/dev/null; then
63     echo "mkdir -p -- $*"
64     exec mkdir -p -- "$@"
65   fi ;;
66 *)
67   if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
68     echo "mkdir -m $dirmode -p -- $*"
69     exec mkdir -m "$dirmode" -p -- "$@"
70   fi ;;
71 esac
72
73 for file
74 do
75    set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
76    shift
77
78    pathcomp=
79    for d
80    do
81      pathcomp="$pathcomp$d"
82      case "$pathcomp" in
83        -* ) pathcomp=./$pathcomp ;;
84      esac
85
86      if test ! -d "$pathcomp"; then
87         echo "mkdir $pathcomp"
88
89         mkdir "$pathcomp" || lasterr=$?
90
91         if test ! -d "$pathcomp"; then
92           errstatus=$lasterr
93         else
94           if test ! -z "$dirmode"; then
95              echo "chmod $dirmode $pathcomp"
96
97              lasterr=""
98              chmod "$dirmode" "$pathcomp" || lasterr=$?
99
100              if test ! -z "$lasterr"; then
101                errstatus=$lasterr
102              fi
103           fi
104         fi
105      fi
106
107      pathcomp="$pathcomp/"
108    done
109 done
110
111 exit $errstatus
112
113 # Local Variables:
114 # mode: shell-script
115 # sh-indentation: 3
116 # End:
117 # mkinstalldirs ends here