blob: 8ab885ec92d9e1ce51e4bca32745b24c2bf0a596 [file] [log] [blame]
Daniel Veillard01791d51998-07-24 19:24:09 +00001#! /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
Daniel Veillard01791d51998-07-24 19:24:09 +00007errstatus=0
Daniel Veillard536fad52003-09-18 10:05:56 +00008dirmode=""
9
10usage="\
11Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
12
13# process command line arguments
14while test $# -gt 0 ; do
15 case "${1}" in
16 -h | --help | --h* ) # -h for help
17 echo "${usage}" 1>&2; exit 0 ;;
18 -m ) # -m PERM arg
19 shift
20 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
21 dirmode="${1}"
22 shift ;;
23 -- ) shift; break ;; # stop option processing
24 -* ) echo "${usage}" 1>&2; exit 1 ;; # unknown option
25 * ) break ;; # first non-opt arg
26 esac
27done
28
29for file
30do
31 if test -d "$file"; then
32 shift
33 else
34 break
35 fi
36done
37
38case $# in
390) exit 0 ;;
40esac
41
42case $dirmode in
43'')
44 if mkdir -p -- . 2>/dev/null; then
45 echo "mkdir -p -- $*"
46 exec mkdir -p -- "$@"
47 fi ;;
48*)
49 if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
50 echo "mkdir -m $dirmode -p -- $*"
51 exec mkdir -m "$dirmode" -p -- "$@"
52 fi ;;
53esac
Daniel Veillard01791d51998-07-24 19:24:09 +000054
55for file
56do
57 set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
58 shift
59
60 pathcomp=
61 for d
62 do
63 pathcomp="$pathcomp$d"
64 case "$pathcomp" in
65 -* ) pathcomp=./$pathcomp ;;
66 esac
67
68 if test ! -d "$pathcomp"; then
Daniel Veillard536fad52003-09-18 10:05:56 +000069 echo "mkdir $pathcomp"
Daniel Veillard01791d51998-07-24 19:24:09 +000070
Daniel Veillard536fad52003-09-18 10:05:56 +000071 mkdir "$pathcomp" || lasterr=$?
Daniel Veillard01791d51998-07-24 19:24:09 +000072
Daniel Veillard536fad52003-09-18 10:05:56 +000073 if test ! -d "$pathcomp"; then
74 errstatus=$lasterr
75 else
76 if test ! -z "$dirmode"; then
77 echo "chmod $dirmode $pathcomp"
78
79 lasterr=""
80 chmod "$dirmode" "$pathcomp" || lasterr=$?
81
82 if test ! -z "$lasterr"; then
83 errstatus=$lasterr
84 fi
85 fi
86 fi
Daniel Veillard01791d51998-07-24 19:24:09 +000087 fi
88
89 pathcomp="$pathcomp/"
90 done
91done
92
93exit $errstatus
94
Daniel Veillard536fad52003-09-18 10:05:56 +000095# Local Variables:
96# mode: shell-script
97# sh-indentation: 3
98# End:
Daniel Veillard01791d51998-07-24 19:24:09 +000099# mkinstalldirs ends here