annotate mkinstalldirs @ 11836:86cdfd6b32a6

[gaim-migrate @ 14127] A note! committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Wed, 26 Oct 2005 05:22:26 +0000
parents a0b7b72e278d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9002
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
1 #! /bin/sh
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
2 # mkinstalldirs --- make directory hierarchy
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
3
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
4 scriptversion=2004-02-15.20
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
5
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
6 # Original author: Noah Friedman <friedman@prep.ai.mit.edu>
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
7 # Created: 1993-05-16
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
8 # Public domain.
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
9 #
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
10 # This file is maintained in Automake, please report
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
11 # bugs to <bug-automake@gnu.org> or send patches to
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
12 # <automake-patches@gnu.org>.
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
13
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
14 errstatus=0
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
15 dirmode=""
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
16
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
17 usage="\
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
18 Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
19
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
20 Create each directory DIR (with mode MODE, if specified), including all
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
21 leading file name components.
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
22
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
23 Report bugs to <bug-automake@gnu.org>."
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
24
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
25 # process command line arguments
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
26 while test $# -gt 0 ; do
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
27 case $1 in
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
28 -h | --help | --h*) # -h for help
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
29 echo "$usage"
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
30 exit 0
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
31 ;;
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
32 -m) # -m PERM arg
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
33 shift
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
34 test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
35 dirmode=$1
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
36 shift
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
37 ;;
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
38 --version)
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
39 echo "$0 $scriptversion"
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
40 exit 0
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
41 ;;
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
42 --) # stop option processing
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
43 shift
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
44 break
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
45 ;;
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
46 -*) # unknown option
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
47 echo "$usage" 1>&2
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
48 exit 1
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
49 ;;
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
50 *) # first non-opt arg
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
51 break
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
52 ;;
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
53 esac
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
54 done
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
55
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
56 for file
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
57 do
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
58 if test -d "$file"; then
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
59 shift
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
60 else
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
61 break
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
62 fi
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
63 done
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
64
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
65 case $# in
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
66 0) exit 0 ;;
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
67 esac
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
68
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
69 # Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
70 # mkdir -p a/c at the same time, both will detect that a is missing,
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
71 # one will create a, then the other will try to create a and die with
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
72 # a "File exists" error. This is a problem when calling mkinstalldirs
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
73 # from a parallel make. We use --version in the probe to restrict
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
74 # ourselves to GNU mkdir, which is thread-safe.
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
75 case $dirmode in
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
76 '')
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
77 if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
78 echo "mkdir -p -- $*"
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
79 exec mkdir -p -- "$@"
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
80 else
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
81 # On NextStep and OpenStep, the `mkdir' command does not
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
82 # recognize any option. It will interpret all options as
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
83 # directories to create, and then abort because `.' already
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
84 # exists.
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
85 test -d ./-p && rmdir ./-p
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
86 test -d ./--version && rmdir ./--version
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
87 fi
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
88 ;;
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
89 *)
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
90 if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
91 test ! -d ./--version; then
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
92 echo "mkdir -m $dirmode -p -- $*"
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
93 exec mkdir -m "$dirmode" -p -- "$@"
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
94 else
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
95 # Clean up after NextStep and OpenStep mkdir.
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
96 for d in ./-m ./-p ./--version "./$dirmode";
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
97 do
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
98 test -d $d && rmdir $d
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
99 done
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
100 fi
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
101 ;;
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
102 esac
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
103
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
104 for file
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
105 do
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
106 set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
107 shift
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
108
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
109 pathcomp=
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
110 for d
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
111 do
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
112 pathcomp="$pathcomp$d"
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
113 case $pathcomp in
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
114 -*) pathcomp=./$pathcomp ;;
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
115 esac
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
116
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
117 if test ! -d "$pathcomp"; then
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
118 echo "mkdir $pathcomp"
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
119
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
120 mkdir "$pathcomp" || lasterr=$?
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
121
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
122 if test ! -d "$pathcomp"; then
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
123 errstatus=$lasterr
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
124 else
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
125 if test ! -z "$dirmode"; then
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
126 echo "chmod $dirmode $pathcomp"
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
127 lasterr=""
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
128 chmod "$dirmode" "$pathcomp" || lasterr=$?
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
129
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
130 if test ! -z "$lasterr"; then
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
131 errstatus=$lasterr
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
132 fi
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
133 fi
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
134 fi
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
135 fi
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
136
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
137 pathcomp="$pathcomp/"
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
138 done
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
139 done
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
140
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
141 exit $errstatus
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
142
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
143 # Local Variables:
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
144 # mode: shell-script
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
145 # sh-indentation: 2
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
146 # eval: (add-hook 'write-file-hooks 'time-stamp)
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
147 # time-stamp-start: "scriptversion="
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
148 # time-stamp-format: "%:y-%02m-%02d.%02H"
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
149 # time-stamp-end: "$"
a0b7b72e278d [gaim-migrate @ 9777]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
150 # End: