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