Skip to content

Commit

Permalink
Remove sudo from keyboard commands (#159)
Browse files Browse the repository at this point in the history
* Update README, remove sudo from keymap.tcl and virtual-programs

* Add forloop for usermods, avoids errors when certain groups don't exist

* Remove extranous usermod instruction

* Fix esc-restart, remove sudo from keymap

Instead of using `loadkeys` we're now using `kbd_mode -u` to load the
keymap. This is because `loadkeys` requires root permissions and we're
trying to remove the need for `sudo` in the system. I tried removing
`sudo` from the `esc-restart` virtual program but it failed with an
interactive authentication error. I'm not sure how to do this with less
powerful permissions than `sudo` so I'm leaving it as is for now.

* Add kdb to explicit dependnecies to get around need for loadkeys

This is precautionary, in practice kbd is a dependency of console-data
but I could image cases in the future where we swap console-data but
still need kdb.
  • Loading branch information
cwervo authored Jul 10, 2024
1 parent dfd24a5 commit c031409
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ if flashing from a Mac])
If no `folk` user, then:

sudo useradd -m folk; sudo passwd folk;
sudo usermod -a -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,render,netdev,lpadmin,gpio,i2c,spi folk

(If you get errors from usermod like `group 'gpio' does not exist`,
try running again omitting the groups that don't exist from the
command.)
for group in adm dialout cdrom sudo audio video plugdev games users input tty render netdev lpadmin gpio i2c spi; do sudo usermod -a -G $group folk; done; groups folk

1. `sudo apt update`

Expand All @@ -79,7 +75,7 @@ if flashing from a Mac])
1. Install dependencies: `sudo apt install rsync tcl-thread tcl8.6-dev
git libjpeg-dev libpng-dev fbset libdrm-dev pkg-config v4l-utils
mesa-vulkan-drivers vulkan-tools libvulkan-dev libvulkan1 meson
libgbm-dev glslc vulkan-validationlayers console-data`
libgbm-dev glslc vulkan-validationlayers console-data kbd`

(When prompted while installing `console-data` for `Policy for handling keymaps` type `3` (meaning `3. Keep kernel keymap`) and press `Enter`)

Expand Down
6 changes: 3 additions & 3 deletions lib/keymap.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ namespace eval keymap {
}

proc load {name} {
exec sudo loadkeys $name
set keytable [exec sudo dumpkeys -kf]
set unitable [exec sudo dumpkeys -kfn]
exec kbd_mode -u $name
set keytable [exec dumpkeys -kf]
set unitable [exec dumpkeys -kfn]

set ksyms [dict create]
set mods [_fillRange 0-15]
Expand Down
5 changes: 5 additions & 0 deletions virtual-programs/esc-restart.folk
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
When keyboard /k/ claims key Meta_Escape is down with timestamp /any/ {
# When sudo is removed here you get:
#
# Error in virtual-programs/esc-restart.folk, match m10029:6: Failed to restart folk.service: Interactive authentication required.
#
# TODO: Figure out how to do this with less powerful permissions than `sudo`.
exec sudo systemctl restart folk
}
2 changes: 1 addition & 1 deletion virtual-programs/keyboard.folk
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ proc walkInputEventPaths {} {
if {[file readable $device] == 0} {
puts "Device $device is not readable. Attempting to change permissions."
# Attempt to change permissions so that the file can be read
exec sudo chmod +r $device
exec chmod +r $device
}
lappend keyboards $device
}
Expand Down

0 comments on commit c031409

Please sign in to comment.