Salome HOME
Increment version: 7.7.0
[modules/yacs.git] / mkinstalldirs
1 #! /bin/sh
2 # Copyright (C) 2006-2015  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, or (at your option) any later version.
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
21 # mkinstalldirs --- make directory hierarchy
22 # Author: Noah Friedman <friedman@prep.ai.mit.edu>
23 # Created: 1993-05-16
24 # Public domain
25
26 errstatus=0
27 dirmode=""
28
29 usage="\
30 Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
31
32 # process command line arguments
33 while test $# -gt 0 ; do
34    case "${1}" in
35      -h | --help | --h* )                       # -h for help
36         echo "${usage}" 1>&2; exit 0 ;;
37      -m )                                       # -m PERM arg
38         shift
39         test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
40         dirmode="${1}"
41         shift ;;
42      -- ) shift; break ;;                       # stop option processing
43      -* ) echo "${usage}" 1>&2; exit 1 ;;       # unknown option
44      * )  break ;;                              # first non-opt arg
45    esac
46 done
47
48 for file
49 do
50   if test -d "$file"; then
51     shift
52   else
53     break
54   fi
55 done
56
57 case $# in
58 0) exit 0 ;;
59 esac
60
61 case $dirmode in
62 '')
63   if mkdir -p -- . 2>/dev/null; then
64     echo "mkdir -p -- $*"
65     exec mkdir -p -- "$@"
66   fi ;;
67 *)
68   if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
69     echo "mkdir -m $dirmode -p -- $*"
70     exec mkdir -m "$dirmode" -p -- "$@"
71   fi ;;
72 esac
73
74 for file
75 do
76    set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
77    shift
78
79    pathcomp=
80    for d
81    do
82      pathcomp="$pathcomp$d"
83      case "$pathcomp" in
84        -* ) pathcomp=./$pathcomp ;;
85      esac
86
87      if test ! -d "$pathcomp"; then
88         echo "mkdir $pathcomp"
89
90         mkdir "$pathcomp" || lasterr=$?
91
92         if test ! -d "$pathcomp"; then
93           errstatus=$lasterr
94         else
95           if test ! -z "$dirmode"; then
96              echo "chmod $dirmode $pathcomp"
97
98              lasterr=""
99              chmod "$dirmode" "$pathcomp" || lasterr=$?
100
101              if test ! -z "$lasterr"; then
102                errstatus=$lasterr
103              fi
104           fi
105         fi
106      fi
107
108      pathcomp="$pathcomp/"
109    done
110 done
111
112 exit $errstatus
113
114 # Local Variables:
115 # mode: shell-script
116 # sh-indentation: 3
117 # End:
118 # mkinstalldirs ends here