Debian Codegraph @

acdir/install-sh

raw
1 #!/bin/sh
2 ###############################################################################
3 # BRLTTY - A background process providing access to the console screen (when in
4 # text mode) for a blind person using a refreshable braille display.
5 #
6 # Copyright (C) 1995-2026 by The BRLTTY Developers.
7 #
8 # BRLTTY comes with ABSOLUTELY NO WARRANTY.
9 #
10 # This is free software, placed under the terms of the
11 # GNU Lesser General Public License, as published by the Free Software
12 # Foundation; either version 2.1 of the License, or (at your option) any
13 # later version. Please see the file LICENSE-LGPL for details.
14 #
15 # Web Page: http://brltty.app/
16 #
17 # This software is maintained by Dave Mielke <[email protected]>.
18 ###############################################################################
19
20 umask 077
21
22 programName="`echo "${0}" | sed -e 's%^.*/%%'`"
23 programMessage() {
24 echo >&2 "${programName}: ${1}"
25 }
26
27 syntaxError() {
28 programMessage "${1}"
29 exit 2
30 }
31
32 defaultMode="0755"
33 defaultStripCommand="strip"
34
35 copyCommand="cp"
36 directoryCommand="mkdir -p"
37 groupCommand="chgrp"
38 modeCommand="chmod"
39 ownerCommand="chown"
40 stripCommand="${defaultStripCommand}"
41
42 createDirectories=false
43 newGroup=""
44 newMode="${defaultMode}"
45 newOwner=""
46 showActions=false
47 showUsage=false
48 stripSymbols=false
49
50 while [ "${#}" -gt 0 ]
51 do
52 option="${1}"
53 operand=""
54
55 case "${option}"
56 in
57 -c) ;;
58 -d|--directory) createDirectories=true;;
59 -g|--group) operand=newGroup;;
60 -h|--help) showUsage=true;;
61 -m|--mode) operand=newMode;;
62 -o|--owner) operand=newOwner;;
63 -s|--strip) stripSymbols=true;;
64 --strip-program) operand=stripCommand;;
65 -v|--verbose) showActions=true;;
66 -*) syntaxError "unknown option: ${option}";;
67 *) break;;
68 esac
69
70 shift
71 [ -z "${operand}" ] && continue
72 [ "${#}" -eq 0 ] && syntaxError "missing operand: ${option}"
73 eval "${operand}"'="${1}"'
74 shift
75 done
76
77 "${showUsage}" && {
78 cat <<END_OF_USAGE
79 Usage:
80 ${programName} [-option ...] source destination
81 ${programName} [-option ...] source ... destination-directory
82 ${programName} -d [-option ...] new-directory ...
83
84 Options:
85 -c ignored (for backward compatibility)
86 -d|--directory create all components of specified directories
87 -g|--group group set owning group
88 -h|--help display usage summary (this text), and then exit
89 -m|--mode mode set permission mode (default is ${defaultMode})
90 -o|--owner owner set owning user
91 -s|--strip strip symbols from executables
92 --strip-program set symbol stripping command (default is ${defaultStripCommand})
93 -v|--verbose re[prt each successful action
94 END_OF_USAGE
95
96 exit 0
97 }
98
99 changeAttributes='
100 [ "${newMode}" != "" ] && {
101 ${modeCommand} "${newMode}" "${path}" || exit 3
102 "${showActions}" && programMessage "mode changed: ${path}"
103 }
104
105 [ "${newGroup}" != "" ] && {
106 ${groupCommand} "${newGroup}" "${path}" || exit 3
107 "${showActions}" && programMessage "group changed: ${path}"
108 }
109
110 [ "${newOwner}" != "" ] && {
111 ${ownerCommand} "${newOwner}" "${path}" || exit 3
112 "${showActions}" && programMessage "owner changed: ${path}"
113 }
114 '
115
116 "${createDirectories}" && {
117 "${stripSymbols}" && syntaxError "cannot strip a directory."
118 [ "${#}" -eq 0 ] && syntaxError "directory not specified."
119
120 for destination
121 do
122 [ "${destination}" = "" ] && {
123 programMessage "null directory."
124 continue
125 }
126
127 directory=""
128 paths=""
129 for component in `echo "${destination}" | sed -e 's%/% %g' -e 's%^ %/ %' -e 's% *$%%' -e 's% *% %g'`
130 do
131 directory="${directory}${component}"
132 [ "${component}" = "/" ] || directory="${directory}/"
133
134 [ -d "${directory}" ] || {
135 ${directoryCommand} "${directory}" || exit 3
136 "${showActions}" && programMessage "directory created: ${directory}"
137 paths="${directory} ${paths}"
138 }
139 done
140
141 [ -n "${paths}" ] && {
142 for path in $paths
143 do
144 eval "${changeAttributes}"
145 done
146 }
147 done
148
149 exit 0
150 }
151
152 [ "${#}" -eq 0 ] && syntaxError "source not specified."
153 [ "${#}" -eq 1 ] && syntaxError "destination not specified."
154
155 count="`expr "${#}" - 1`"
156 destination="`( shift "${count}"; echo "${1}" )`"
157
158 if [ -d "${destination}" ]
159 then
160 toDirectory=true
161 else
162 [ "${#}" -eq 2 ] || syntaxError "more than one source - destination not a directory: ${destination}"
163 toDirectory=false
164 fi
165
166 while [ "${#}" -gt 1 ]
167 do
168 source="${1}"
169 shift
170
171 if [ -f "${source}" ]
172 then
173 type=file
174 else
175 syntaxError "source not a file: ${source}"
176 fi
177
178 path="${destination}"
179 "${toDirectory}" && path="${path}/`basename ${source}`"
180 ${copyCommand} "${source}" "${path}" || exit 3
181 "${showActions}" && programMessage "${type} copied: ${source} -> ${path}"
182
183 "${stripSymbols}" && {
184 ${stripCommand} "${path}" || exit 3
185 "${showActions}" && programMessage "symbols stripped: ${path}"
186 }
187
188 eval "${changeAttributes}"
189 done
190
191 exit 0