| 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 |
set -e |
| 21 |
umask 077 |
| 22 |
|
| 23 |
. "`dirname "${0}"`/brltty-prologue.sh" |
| 24 |
. "${programDirectory}/brltty-config.sh" |
| 25 |
defaultKeyFile="${BRLTTY_EXECUTE_ROOT}${BRLAPI_KEY_FILE}" |
| 26 |
|
| 27 |
showProgramUsagePurpose() { |
| 28 |
cat <<END_OF_PROGRAM_USAGE_PURPOSE |
| 29 |
Generate the BrlAPI access key. |
| 30 |
END_OF_PROGRAM_USAGE_PURPOSE |
| 31 |
} |
| 32 |
|
| 33 |
addProgramOption f string.path keyFile "the BrlAPI key file" "${defaultKeyFile}" |
| 34 |
parseProgramArguments "${@}" |
| 35 |
|
| 36 |
try() { |
| 37 |
("${@}"; exit "${?}") 2>/dev/null && { |
| 38 |
logTask "key generated" |
| 39 |
exit 0 |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
[ -n "${keyFile}" ] || keyFile="${defaultKeyFile}" |
| 44 |
|
| 45 |
logNote "trying mcookie" |
| 46 |
try mcookie >"${keyFile}" |
| 47 |
|
| 48 |
for device in "/dev/urandom" "/dev/random" |
| 49 |
do |
| 50 |
[ -c "${device}" -a -r "${device}" ] && { |
| 51 |
logNote "trying ${device}" |
| 52 |
try dd if="${device}" of="${keyFile}" bs=32 count=1 |
| 53 |
} |
| 54 |
done |
| 55 |
|
| 56 |
logNote "trying \$RANDOM" |
| 57 |
key="${RANDOM}" |
| 58 |
[ -n "${key}" ] && try echo >"${keyFile}" "${key}" |
| 59 |
|
| 60 |
rm -f -- "${keyFile}" |
| 61 |
semanticError "no supported mechanism is available" |
| 62 |
exit 3 |