Imported Upstream version 1.6.6
[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 # $Id: mkinstalldirs,v 1.3 2001/12/31 22:05:23 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; exit 0 ;;
21      -m )                                       # -m PERM arg
22         shift
23         test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
24         dirmode="${1}"
25         shift ;;
26      -- ) shift; break ;;                       # stop option processing
27      -* ) echo "${usage}" 1>&2; exit 1 ;;       # unknown option
28      * )  break ;;                              # first non-opt arg
29    esac
30 done
31
32 for file
33 do
34    set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
35    shift
36
37    pathcomp=
38    for d
39    do
40      pathcomp="$pathcomp$d"
41      case "$pathcomp" in
42        -* ) pathcomp=./$pathcomp ;;
43      esac
44
45      if test ! -d "$pathcomp"; then
46         echo "mkdir $pathcomp"
47
48         mkdir "$pathcomp" || lasterr=$?
49
50         if test ! -d "$pathcomp"; then
51           errstatus=$lasterr
52         else
53           if test ! -z "$dirmode"; then
54              echo "chmod $dirmode $pathcomp"
55
56              lasterr=""
57              chmod $dirmode "$pathcomp" || lasterr=$?
58
59              if test ! -z "$lasterr"; then
60                errstatus=$lasterr
61              fi
62           fi
63         fi
64      fi
65
66      pathcomp="$pathcomp/"
67    done
68 done
69
70 exit $errstatus
71
72 # Local Variables:
73 # mode:shell-script
74 # sh-indentation:3
75 # End: