forked from brltty/brltty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrltty-term
executable file
·120 lines (95 loc) · 3.97 KB
/
brltty-term
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
#!/usr/bin/env bash
###############################################################################
# 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-2022 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 <[email protected]>.
###############################################################################
. "$(dirname "${0}")/brltty-prologue.sh"
usageSummary="\
Run a shell or terminal manager via the brltty-pty terminal emulator
and brltty using its Terminal Emulator screen driver.
Syntax: ${programName} [shell] [-option ...]
This script is especially useful on platforms that don't support a native screen driver.
This newer method may (should) be used in preference to the older method of
running brltty in conjunction with its provided patch to the screen program.
All of the arguments to this script are interpreted as brltty options,
with the following exceptions:
* If the first argument is -h then this usage summary is displayed.
* If the first argument doesn't begin with - (i.e. it isn't an option)
then it's interpreted as the shell to run, and the rest of the arguments
are interpreted as brltty options.
The shell may be specified via either its name or its path. It's also okay
to specify a terminal manager rather than a shell. For example:
* ${programName} screen
* ${programName} tmux
If the shell isn't specified on the command line then, in decreasing
precedence, one of the following is used:
1: If set, the \$BRLTTY_TERM_SHELL environment variable.
2: If set, the \$SHELL environment variable.
3: The default shell (sh).
Brltty is run as root so that it can access the braille device. If its
set-user-id bit is set and/or if this script is already running as root
then it's run directly. If neither, it's run via sudo. In this case, you
may wish to consider configuring sudo so that it won't prompt for the
user's password since the braille device wouldn't be operational yet.
If the copy of this script in its installed location is used then the
installed brltty is run. If, however, the copy in the top-level directory
of the source tree is used then brltty in the build tree (which needn't
be installed) is run.
"
shellCommand=""
[ "${#}" -eq 0 ] || {
argument="${1}"
[ "${argument}" = "-h" ] && {
echo -n "${usageSummary}"
exit 0
}
[ "${#argument}" -eq 0 ] || {
[ "${argument:0:1}" = "-" ] || {
shellCommand="${argument}"
shift 1
}
}
}
[ -t 0 ] || semanticError "standard input isn't a terminal"
[ -t 1 ] || semanticError "standard output isn't a terminal"
findSiblingCommand brlttyPath brltty run-brltty || {
semanticError "brltty not found"
}
[ -n "${shellCommand}" ] || shellCommand="${BRLTTY_TERM_SHELL}"
[ -n "${shellCommand}" ] || shellCommand="${SHELL}"
[ -n "${shellCommand}" ] || shellCommand="sh"
findHostCommand shellPath "${shellCommand}" || {
semanticError "shell not found: ${shellCommand}"
}
driverParameters=()
driverCode="em"
addDriverParameter() {
local name="${1}"
local value="${2}"
driverParameters+=("-X${driverCode}:${name}=${value}")
}
currentUser="$(id -u)"
currentGroup="$(id -g)"
addDriverParameter shell "${shellPath}"
addDriverParameter user "${currentUser}"
addDriverParameter group "${currentGroup}"
addDriverParameter directory "${PWD}"
addDriverParameter home "${HOME}"
SUDO="sudo --bell --preserve-env --preserve-env=USER,LOGNAME --"
[ -u "${brlttyPath}" ] && SUDO=""
[ "${currentUser}" -eq 0 ] && SUDO=""
exec ${SUDO} "${brlttyPath}" -n -z -x"${driverCode}" "${driverParameters[@]}" "${@}"
exit "${?}"