| 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 |
processExtraProgramParameters() { |
| 23 |
requiredPackageNames=( "${@}" ) |
| 24 |
} |
| 25 |
|
| 26 |
addProgramOption i flag installNeededPackages "install the needed packages" |
| 27 |
addProgramOption l flag listNeededPackages "list the needed packages" |
| 28 |
optionalProgramParameters |
| 29 |
parseProgramArguments "${@}" |
| 30 |
|
| 31 |
set -e |
| 32 |
. "${programDirectory}/packages.sh" |
| 33 |
|
| 34 |
[ "${#requiredPackageNames[@]}" -gt 0 ] || { |
| 35 |
loadRequiredPackageNames() { |
| 36 |
local file="${programDirectory}/${programName}.d/${platformName}" |
| 37 |
[ -e "${file}" ] || semanticError "platform package list not found: ${file}" |
| 38 |
[ -f "${file}" ] || semanticError "not a file: ${file}" |
| 39 |
[ -r "${file}" ] || semanticError "platform package list not readable: ${file}" |
| 40 |
|
| 41 |
local name |
| 42 |
while read name |
| 43 |
do |
| 44 |
[ -n "${name}" ] || continue |
| 45 |
[ "${name:0:1}" = "#" ] && continue |
| 46 |
requiredPackageNames[${#requiredPackageNames[*]}]="${name}" |
| 47 |
done < <(cat "${file}") |
| 48 |
|
| 49 |
[ "${#requiredPackageNames[@]}" -gt 0 ] || semanticError "empty package list" |
| 50 |
} |
| 51 |
|
| 52 |
case "${packageManager}" |
| 53 |
in |
| 54 |
apk) |
| 55 |
platformName="alpine" |
| 56 |
;; |
| 57 |
|
| 58 |
apt) |
| 59 |
if [ "$(uname -s)" = "GNU" ] |
| 60 |
then |
| 61 |
platformName="hurd" |
| 62 |
else |
| 63 |
platformName="debian" |
| 64 |
fi |
| 65 |
;; |
| 66 |
|
| 67 |
brew) |
| 68 |
platformName="darwin" |
| 69 |
;; |
| 70 |
|
| 71 |
dnf) |
| 72 |
platformName="fedora" |
| 73 |
;; |
| 74 |
|
| 75 |
pacman) |
| 76 |
platformName="arch" |
| 77 |
;; |
| 78 |
|
| 79 |
pkg) |
| 80 |
platformName="freebsd" |
| 81 |
;; |
| 82 |
|
| 83 |
pkg_info) |
| 84 |
platformName="openbsd" |
| 85 |
;; |
| 86 |
|
| 87 |
xbps) |
| 88 |
platformName="void" |
| 89 |
;; |
| 90 |
|
| 91 |
zypper) |
| 92 |
platformName="opensuse" |
| 93 |
;; |
| 94 |
|
| 95 |
*) semanticError "unknown host platform: ${packageManager}";; |
| 96 |
esac |
| 97 |
|
| 98 |
logNote "platform name: ${platformName}" |
| 99 |
loadRequiredPackageNames |
| 100 |
} |
| 101 |
|
| 102 |
listRequiredPackages() { |
| 103 |
local name |
| 104 |
|
| 105 |
for name in "${requiredPackageNames[@]}" |
| 106 |
do |
| 107 |
echo "${name}" |
| 108 |
done |
| 109 |
} |
| 110 |
|
| 111 |
neededPackages=( |
| 112 |
$( |
| 113 |
diff <(listInstalledPackages | normalizePackageList) \ |
| 114 |
<(listRequiredPackages | normalizePackageList) | |
| 115 |
sed -n -e ' |
| 116 |
/^--- /b |
| 117 |
/^+++ /b |
| 118 |
s/^+/> / |
| 119 |
s/^> //p |
| 120 |
' |
| 121 |
) |
| 122 |
) |
| 123 |
|
| 124 |
if [ "${#neededPackages[@]}" -gt 0 ] |
| 125 |
then |
| 126 |
logTask "packages needed: ${#neededPackages[@]}" |
| 127 |
|
| 128 |
"${listNeededPackages}" && { |
| 129 |
for package in "${neededPackages[@]}" |
| 130 |
do |
| 131 |
echo "${package}" |
| 132 |
done |
| 133 |
} |
| 134 |
|
| 135 |
"${installNeededPackages}" && { |
| 136 |
installPackages "${neededPackages[@]}" |
| 137 |
} |
| 138 |
else |
| 139 |
logTask "no needed packages" |
| 140 |
fi |
| 141 |
|
| 142 |
exit 0 |