Debian Codegraph @

brltty-mkuser

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/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 set -e
21 . "`dirnamescip-shell system . . dirname. "${0}"`/brltty-prologue.sh"
22 . "${programDirectory}/brltty-config.sh"
23
24 showProgramUsagePurposescip-shell shell brltty 6.9.1-1 showProgramUsagePurpose().() {
25 catscip-shell system . . cat. <<END_OF_PROGRAM_USAGE_PURPOSE
26 Simplify the job of Creating and making changes to BRLTTY's unprivileged user.
27 END_OF_PROGRAM_USAGE_PURPOSE
28 }
29
30 declare -A privilegeParameters
31 parseParameterString privilegeParameters "${BRLTTY_PRIVILEGE_PARAMETERS}" lx
32
33 readonly defaultUserName="${privilegeParameters["USER"]}"
34 readonly defaultUserInformation="Braille Device Daemon"
35 readonly defaultHomeDirectory="${BRLTTY_UPDATABLE_DIRECTORY}"
36 readonly defaultLoginShell="/sbin/nologinscip-shell filesystem . . `/sbin/nologin`."
37
38 showProgramUsageNotesscip-shell shell brltty 6.9.1-1 showProgramUsageNotes().() {
39 catscip-shell system . . cat. <<END_OF_PROGRAM_USAGE_NOTES
40 When creating a new user, these options have the following defaults:
41 -d ${defaultHomeDirectory:-the home directory is not defined}
42 -g a new group with the same name as the user
43 -i ${defaultUserInformation}
44 -l ${defaultLoginShell}
45 These defaults don't apply when making changes to an existing user.
46 END_OF_PROGRAM_USAGE_NOTES
47 }
48
49 executeCommandscip-shell shell brltty 6.9.1-1 executeCommand().() {
50 "${useSudo}" && set -- sudo -- "${@}"
51
52 if "${testMode}"
53 then
54 echoscip-shell system . . echo. "${*}"
55 else
56 "${@}"
57 fi
58 }
59
60 groupList=()
61 addGroupsscip-shell shell brltty 6.9.1-1 addGroups().() {
62 while [scip-shell system . . `[`. "${#}" -gt 0 ]
63 do
64 local group="${1}"
65 shift 1
66 [scip-shell system . . `[`. -n "${group}" ] || continue
67
68 [scip-shell system . . `[`. "${group#*/}" = "${group}" ] || {
69 [scip-shell system . . `[`. -e "${group}" ] || continue
70 group="$(statscip-shell system . . stat. -c "%G" "${group}")" || :
71 [scip-shell system . . `[`. -n "${group}" ] || continue
72 }
73
74 local g
75 for g in "${groupList[@]}"
76 do
77 [scip-shell system . . `[`. "${g}" = "${group}" ] && {
78 group=""
79 break
80 }
81 done
82
83 [scip-shell system . . `[`. -n "${group}" ] && groupList[${#groupList[*]}]="${group}"
84 done
85
86 return 0
87 }
88
89 addProgramOption a flag noALSA "don't allow playing sound via the ALSA framework"
90 addProgramOption b flag noBrlapi "don't allow reading BrlAPI's authorization key file"
91 addProgramOption c flag noConsoles "don't allow access to the virtual consoles"
92 addProgramOption d string.path homeDirectory "set/change the home (login) directory"
93 addProgramOption g string.group primaryGroup "set/change the primary (login) group"
94 addProgramOption i string.text userInformation "set/change the user information (gecos) text"
95 addProgramOption k flag noKeyboards "don't allow keyboard monitoring"
96 addProgramOption l string.path loginShell "set/change the login shell"
97 addProgramOption p flag noPulse "don't allow playing sound via the Pulse Audio server"
98 addProgramOption s flag noSerial "don't allow access to serial devices"
99 addProgramOption u flag noUSB "don't allow access to USB devices"
100 addProgramOption E flag allowChanges "allow changes to an existing user"
101 addProgramOption G flag noGroups "don't set/change the supplementary group list"
102 addProgramOption N flag allowCreate "allow creating a new user"
103 addProgramOption S flag useSudo "use sudo to execute the commands as root"
104 addProgramOption T flag testMode "test mode - show the commands that would be executed"
105 addProgramOption U string.user userName "the user to be created/changed" "${defaultUserName}"
106 parseProgramArguments "${@}"
107
108 [scip-shell system . . `[`. -n "${userName}" ] || userName="${defaultUserName}"
109 [scip-shell system . . `[`. -n "${userName}" ] || syntaxError "unprivileged user not configured - use -U (user) to specify"
110
111 if idscip-shell system . . id. -u "${userName}" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
112 then
113 "${allowChanges}" || semanticError "user already exists: ${userName} - use -E (existing) to allow"
114 command=(usermod)
115 else
116 "${allowCreate}" || semanticError "user doesn't exist: ${userName} - use -N (new) to allow"
117 command=(useradd --system)
118 [scip-shell system . . `[`. -n "${primaryGroup}" ] || command+=(--user-group)
119
120 [scip-shell system . . `[`. -n "${userInformation}" ] || userInformation="${defaultUserInformation}"
121 [scip-shell system . . `[`. -n "${homeDirectory}" ] || homeDirectory="${defaultHomeDirectory}"
122 [scip-shell system . . `[`. -n "${loginShell}" ] || loginShell="${defaultLoginShell}"
123
124 if [scip-shell system . . `[`. -z "${homeDirectory}" ]
125 then
126 createHomeDirectory=false
127 elif [scip-shell system . . `[`. -e "${homeDirectory}" ]
128 then
129 [scip-shell system . . `[`. -d "${homeDirectory}" ] || semanticError "not a directory: ${homeDirectory}"
130 createHomeDirectory=false
131 else
132 createHomeDirectory=true
133 fi
134
135 if "${createHomeDirectory}"
136 then
137 command+=(--create-home)
138 else
139 command+=(--no-create-home)
140 fi
141 fi
142
143 [scip-shell system . . `[`. -n "${homeDirectory}" ] && command+=(--home "${homeDirectory}")
144 [scip-shell system . . `[`. -n "${primaryGroup}" ] && command+=(--gid "${primaryGroup}")
145 [scip-shell system . . `[`. -n "${userInformation}" ] && command+=(--comment "${userInformation}")
146 [scip-shell system . . `[`. -n "${loginShell}" ] && command+=(--shell "${loginShell}")
147
148 "${noGroups}" || {
149 "${noALSA}" || addGroupsscip-shell shell brltty 6.9.1-1 addGroups(). audio
150 "${noBrlapi}" || addGroupsscip-shell shell brltty 6.9.1-1 addGroups(). "${BRLAPI_KEY_FILE}"
151 "${noConsoles}" || addGroupsscip-shell shell brltty 6.9.1-1 addGroups(). tty /dev/vcs1scip-shell filesystem . . `/dev/vcs1`. /dev/tty1scip-shell filesystem . . `/dev/tty1`.
152 "${noKeyboards}" || addGroupsscip-shell shell brltty 6.9.1-1 addGroups(). input
153 "${noPulse}" || addGroupsscip-shell shell brltty 6.9.1-1 addGroups(). pulse-access
154 "${noSerial}" || addGroupsscip-shell shell brltty 6.9.1-1 addGroups(). /dev/ttyS0scip-shell filesystem . . `/dev/ttyS0`.
155 "${noUSB}" || addGroupsscip-shell shell brltty 6.9.1-1 addGroups(). /dev/bus/usbscip-shell filesystem . . `/dev/bus/usb`.
156
157 groupsOperand="${groupList[*]}"
158 groupsOperand="${groupsOperand// /,}"
159 command+=(--groups "${groupsOperand}")
160 }
161
162 "${testMode}" || {
163 if "${useSudo}"
164 then
165 sudoscip-shell system . . sudo. -v
166 elif [scip-shell system . . `[`. "$(idscip-shell system . . id. -u)" -ne 0 ]
167 then
168 semanticError "not executing as root"
169 fi
170 }
171
172 command+=(-- "${userName}")
173 executeCommandscip-shell shell brltty 6.9.1-1 executeCommand(). "${command[@]}"
174 exit 0