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