| 1 |
#!/bin/bash -p |
| 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 |
set -e |
| 21 |
readonly defaultPath="/etc/brltty.conf" |
| 22 |
|
| 23 |
readonly programPrefix="brltty-" |
| 24 |
programName="${0##*/}" |
| 25 |
[ "${programName#${programPrefix}}" = "${programName}" ] && programName="${programPrefix}${programName}" |
| 26 |
readonly programName |
| 27 |
|
| 28 |
programMessage() { |
| 29 |
local message="${1}" |
| 30 |
local level="${2}" |
| 31 |
|
| 32 |
logger -p "daemon.${level:-info}" -t "${programName}" -- "${1}" && |
| 33 |
[ ! -t 2 ] || |
| 34 |
echo >&2 "${programName}: ${message}" |
| 35 |
} |
| 36 |
|
| 37 |
errorMessage() { |
| 38 |
local message="${1}" |
| 39 |
local code="${2}" |
| 40 |
|
| 41 |
programMessage "${message}" err |
| 42 |
exit "${code:-1}" |
| 43 |
} |
| 44 |
|
| 45 |
syntaxError() { |
| 46 |
local message="${1}" |
| 47 |
|
| 48 |
errorMessage "${message}" 2 |
| 49 |
} |
| 50 |
|
| 51 |
semanticError() { |
| 52 |
local message="${1}" |
| 53 |
|
| 54 |
errorMessage "${message}" 3 |
| 55 |
} |
| 56 |
|
| 57 |
instancePath="${BRLTTY_SYSTEMD_INSTANCE:-${defaultPath}}" |
| 58 |
[ "${instancePath#/}" = "${instancePath}" ] && instancePath="/${instancePath}" |
| 59 |
readonly instancePath |
| 60 |
|
| 61 |
if [ "${instancePath#/sys/}" != "${instancePath}" ] |
| 62 |
then |
| 63 |
isDeviceInstance=true |
| 64 |
udevOption="path" |
| 65 |
elif [ -c "${instancePath}" ] |
| 66 |
then |
| 67 |
isDeviceInstance=true |
| 68 |
udevOption="name" |
| 69 |
elif [ -f "${instancePath}" ] |
| 70 |
then |
| 71 |
isDeviceInstance=false |
| 72 |
elif [ -e "${instancePath}" ] |
| 73 |
then |
| 74 |
semanticError "unsupported instance path: ${instancePath}" |
| 75 |
else |
| 76 |
semanticError "instance path not found: ${instancePath}" |
| 77 |
fi |
| 78 |
|
| 79 |
if "${isDeviceInstance}" |
| 80 |
then |
| 81 |
isUdevManaged=false |
| 82 |
|
| 83 |
while read line |
| 84 |
do |
| 85 |
if [[ "${line}" =~ ^'N: ' ]] |
| 86 |
then |
| 87 |
isUdevManaged=true |
| 88 |
elif [[ "${line}" =~ ^'E: '([^ =]+)=(.*) ]] |
| 89 |
then |
| 90 |
name="${BASH_REMATCH[1]}" |
| 91 |
value="${BASH_REMATCH[2]}" |
| 92 |
|
| 93 |
[[ "${name}" =~ ^'BRLTTY_' ]] || continue |
| 94 |
[ -z "${!name}" ] || continue |
| 95 |
|
| 96 |
export "${name}=${value}" |
| 97 |
fi |
| 98 |
done < <((udevadm info --"${udevOption}"="${instancePath}" --export 2>/dev/null)) |
| 99 |
|
| 100 |
"${isUdevManaged}" || semanticError "instance path not managed by udev: ${instancePath}" |
| 101 |
else |
| 102 |
export BRLTTY_CONFIGURATION_FILE="${instancePath}" |
| 103 |
fi |
| 104 |
|
| 105 |
set -- "${BRLTTY_EXECUTABLE_PATH:-brltty}" -E ${BRLTTY_EXECUTABLE_ARGUMENTS} "${@}" |
| 106 |
programMessage "executing command: ${*}" info |
| 107 |
exec "${@}" |
| 108 |
exit "${?}" |