| 1 | #!/usr/bin/env bash |
| 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 | . "$(dirname "${0}")/brltty-prologue.sh" |
| 21 | |
| 22 | usageSummary="\ |
| 23 | Run a shell or terminal manager via the brltty-pty terminal emulator |
| 24 | and brltty using its Terminal Emulator screen driver. |
| 25 | |
| 26 | Syntax: ${programName} [shell] [-option ...] |
| 27 | |
| 28 | This script is especially useful on platforms that don't support a native screen driver. |
| 29 | This newer method may (should) be used in preference to the older method of |
| 30 | running brltty in conjunction with its provided patch to the screen program. |
| 31 | |
| 32 | All of the arguments to this script are interpreted as brltty options, |
| 33 | with the following exceptions: |
| 34 | * If the first argument is -h then this usage summary is displayed. |
| 35 | * If the first argument doesn't begin with - (i.e. it isn't an option) |
| 36 | then it's interpreted as the shell to run, and the rest of the arguments |
| 37 | are interpreted as brltty options. |
| 38 | |
| 39 | The shell may be specified via either its name or its path. It's also okay |
| 40 | to specify a terminal manager rather than a shell. For example: |
| 41 | * ${programName} screen |
| 42 | * ${programName} tmux |
| 43 | |
| 44 | If the shell isn't specified on the command line then, in decreasing |
| 45 | precedence, one of the following is used: |
| 46 | 1: If set, the \$BRLTTY_TERM_SHELL environment variable. |
| 47 | 2: If set, the \$SHELL environment variable. |
| 48 | 3: The default shell (sh). |
| 49 | |
| 50 | Brltty is run as root so that it can access the braille device. If its |
| 51 | set-user-id bit is set and/or if this script is already running as root |
| 52 | then it's run directly. If neither, it's run via sudo. In this case, you |
| 53 | may wish to consider configuring sudo so that it won't prompt for the |
| 54 | user's password since the braille device wouldn't be operational yet. |
| 55 | |
| 56 | If the copy of this script in its installed location is used then the |
| 57 | installed brltty is run. If, however, the copy in the top-level directory |
| 58 | of the source tree is used then brltty in the build tree (which needn't |
| 59 | be installed) is run. |
| 60 | |
| 61 | " |
| 62 | |
| 63 | shellCommand="" |
| 64 | |
| 65 | [ "${#}" -eq 0 ] || { |
| 66 | argument="${1}" |
| 67 | |
| 68 | [ "${argument}" = "-h" ] && { |
| 69 | echo -n "${usageSummary}" |
| 70 | exit 0 |
| 71 | } |
| 72 | |
| 73 | [ "${#argument}" -eq 0 ] || { |
| 74 | [ "${argument:0:1}" = "-" ] || { |
| 75 | shellCommand="${argument}" |
| 76 | shift 1 |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | [ -t 0 ] || semanticError "standard input isn't a terminal" |
| 82 | [ -t 1 ] || semanticError "standard output isn't a terminal" |
| 83 | |
| 84 | [ -n "${shellCommand}" ] || shellCommand="${BRLTTY_TERM_SHELL}" |
| 85 | [ -n "${shellCommand}" ] || shellCommand="${SHELL}" |
| 86 | [ -n "${shellCommand}" ] || shellCommand="sh" |
| 87 | |
| 88 | findHostCommand shellPath "${shellCommand}" || { |
| 89 | semanticError "shell not found: ${shellCommand}" |
| 90 | } |
| 91 | |
| 92 | screenDriver="em" |
| 93 | screenParameters=() |
| 94 | |
| 95 | addScreenParameter() { |
| 96 | local name="${1}" |
| 97 | local value="${2}" |
| 98 | |
| 99 | screenParameters+=("-X${screenDriver}:${name}=${value}") |
| 100 | } |
| 101 | |
| 102 | currentUser="$(id -u)" |
| 103 | currentGroup="$(id -g)" |
| 104 | |
| 105 | addScreenParameter shell "${shellPath}" |
| 106 | addScreenParameter user "${currentUser}" |
| 107 | addScreenParameter group "${currentGroup}" |
| 108 | addScreenParameter directory "${PWD}" |
| 109 | addScreenParameter home "${HOME}" |
| 110 | |
| 111 | needSiblingBrltty brlttyPath |
| 112 | SUDO="sudo --bell --preserve-env --preserve-env=USER,LOGNAME --" |
| 113 | [ -u "${brlttyPath}" ] && SUDO="" |
| 114 | [ "${currentUser}" -eq 0 ] && SUDO="" |
| 115 | |
| 116 | exec ${SUDO} "${brlttyPath}" -n -z -x"${screenDriver}" "${screenParameters[@]}" "${@}" |
| 117 | exit "${?}" |