annotate mkinstalldirs @ 4844:aed7b7a97932

Functions were declared that are only used in specific situations. Move a code block up a bit and #ifdef appropriately.
author Tony Vroon <chainsaw@gentoo.org>
date Mon, 13 Apr 2009 00:19:52 +0100
parents 7a4fcf84a34f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 #! /bin/sh
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 # mkinstalldirs --- make directory hierarchy
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 # Author: Noah Friedman <friedman@prep.ai.mit.edu>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 # Created: 1993-05-16
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 # Public domain
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 errstatus=0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 dirmode=""
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 usage="\
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 # process command line arguments
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 while test $# -gt 0 ; do
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 case $1 in
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 -h | --help | --h*) # -h for help
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 echo "$usage" 1>&2
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 exit 0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 ;;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 -m) # -m PERM arg
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 shift
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 dirmode=$1
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 shift
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 ;;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 --) # stop option processing
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 shift
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 break
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 ;;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 -*) # unknown option
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 echo "$usage" 1>&2
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 exit 1
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 ;;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 *) # first non-opt arg
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 break
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 ;;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 esac
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 done
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 for file
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 do
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 if test -d "$file"; then
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 shift
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 break
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 fi
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 done
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 case $# in
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 0) exit 0 ;;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 esac
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 case $dirmode in
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 '')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 if mkdir -p -- . 2>/dev/null; then
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 echo "mkdir -p -- $*"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 exec mkdir -p -- "$@"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 fi
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 ;;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 *)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 echo "mkdir -m $dirmode -p -- $*"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 exec mkdir -m "$dirmode" -p -- "$@"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 fi
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 ;;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 esac
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 for file
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 do
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 shift
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 pathcomp=
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 for d
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 do
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 pathcomp="$pathcomp$d"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 case $pathcomp in
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 -*) pathcomp=./$pathcomp ;;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 esac
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 if test ! -d "$pathcomp"; then
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 echo "mkdir $pathcomp"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 mkdir "$pathcomp" || lasterr=$?
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 if test ! -d "$pathcomp"; then
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 errstatus=$lasterr
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 if test ! -z "$dirmode"; then
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 echo "chmod $dirmode $pathcomp"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 lasterr=""
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 chmod "$dirmode" "$pathcomp" || lasterr=$?
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 if test ! -z "$lasterr"; then
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 errstatus=$lasterr
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 fi
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 fi
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 fi
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 fi
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 pathcomp="$pathcomp/"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 done
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 done
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 exit $errstatus
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 # Local Variables:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 # mode: shell-script
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 # sh-indentation: 2
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 # End:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 # mkinstalldirs ends here