Skip to content

Commit

Permalink
#12 reverted sudo back
Browse files Browse the repository at this point in the history
  • Loading branch information
ldrahnik committed Feb 29, 2024
1 parent 4e87e6b commit bc0586d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
"justMyCode": true,
"sudo": true
}
]
}
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ If you find the project useful, do not forget to give project a [![GitHub stars]

## Features

- Driver is installed for the current user (does not run under `$ sudo`)
- Allowed listen to events not only from devices `Asus keyboard` or `Asus WMI hotkeys`
- Allowed to send custom commands (e.g. `xinput enable 19`)
- Allowed to fix any stateful binary switches (e.g. `switch lid state`, `switch tablet-mode state`)
Expand All @@ -23,12 +22,6 @@ If you find the project useful, do not forget to give project a [![GitHub stars]
## Requirements

- (Optionally for LEDs without kernel modules yet) have mounted `debugfs` to `/sys/kernel/debug/asus-nb-wmi` from kernel modules `asus-wmi, asus-nb-wmi`
- (Optionally for LEDs with kernel module support) have granted permissions for the current user:

```
$ sudo chown :$USER /sys/class/leds/platform::micmute/brightness
$ sudo chmod ug+rw /sys/class/leds/platform::micmute/brightness
```

## Installation

Expand Down
6 changes: 3 additions & 3 deletions asus_wmi_hotkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def handle_events(device, udev):
if value == 0:
new_value = 1

cmd = "echo " + str(new_value) + "| tee -a '" + file_path + "' >/dev/null"
cmd = "echo " + str(new_value) + "| sudo tee -a '" + file_path + "' >/dev/null"
log.debug(cmd)

subprocess.call(cmd, shell=True)
Expand All @@ -209,7 +209,7 @@ def handle_events(device, udev):
# Access to specific device led id
dev_id = hex(find_custom_key_mapping[0][1])

cmd = "echo " + str(dev_id) + "| tee '/sys/kernel/debug/asus-nb-wmi/dev_id' >/dev/null"
cmd = "echo " + str(dev_id) + "| sudo tee '/sys/kernel/debug/asus-nb-wmi/dev_id' >/dev/null"
log.debug(cmd)

subprocess.call(cmd, shell=True)
Expand All @@ -229,7 +229,7 @@ def handle_events(device, udev):
if led_state_hex == led_state_on_hex:
new_led_state = hex(0)

cmd = "echo " + str(new_led_state) + " | tee '/sys/kernel/debug/asus-nb-wmi/ctrl_param' >/dev/null"
cmd = "echo " + str(new_led_state) + " | sudo tee '/sys/kernel/debug/asus-nb-wmi/ctrl_param' >/dev/null"
log.debug(cmd)

subprocess.call(cmd, shell=True)
Expand Down
10 changes: 5 additions & 5 deletions install_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ case "$RESPONSE" in [yY][eE][sS]|[yY])
SERVICE_BASE_NAME=asus_wmi_hotkeys_driver
SERVICE_FILE_PATH=$SERVICE_BASE_NAME.service
SERVICE_X11_FILE_PATH=$SERVICE_BASE_NAME.x11.service
SERVICE_INSTALL_FILE_NAME="asus_wmi_hotkeys_driver@.service"
SERVICE_INSTALL_DIR_PATH="/usr/lib/systemd/user"
SERVICE_INSTALL_FILE_NAME="asus_wmi_hotkeys_driver.service"
SERVICE_INSTALL_DIR_PATH="/lib/systemd/system"

XDG_RUNTIME_DIR=$(echo $XDG_RUNTIME_DIR)
DBUS_SESSION_BUS_ADDRESS=$(echo $DBUS_SESSION_BUS_ADDRESS)
Expand Down Expand Up @@ -50,7 +50,7 @@ case "$RESPONSE" in [yY][eE][sS]|[yY])
cat "$SERVICE_FILE_PATH" | CONFIG_FILE_DIR_PATH="$CONFIG_FILE_DIR_PATH/" DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ERROR_LOG_FILE_PATH=$ERROR_LOG_FILE_PATH envsubst '$CONFIG_FILE_DIR_PATH $DISPLAY $XAUTHORITY $XDG_RUNTIME_DIR $DBUS_SESSION_BUS_ADDRESS $ERROR_LOG_FILE_PATH' | sudo tee "$SERVICE_INSTALL_DIR_PATH/$SERVICE_INSTALL_FILE_NAME" >/dev/null
fi

systemctl --user daemon-reload
sudo systemctl daemon-reload

if [[ $? != 0 ]]; then
echo "Something went wrong when was called systemctl daemon reload"
Expand All @@ -59,7 +59,7 @@ case "$RESPONSE" in [yY][eE][sS]|[yY])
echo "Systemctl daemon reloaded"
fi

systemctl enable --user $SERVICE_BASE_NAME@$USER.service
sudo systemctl enable $SERVICE_BASE_NAME.service

if [[ $? != 0 ]]; then
echo "Something went wrong when enabling the $SERVICE_BASE_NAME"
Expand All @@ -68,7 +68,7 @@ case "$RESPONSE" in [yY][eE][sS]|[yY])
echo "Service $SERVICE_BASE_NAME enabled"
fi

systemctl restart --user $SERVICE_BASE_NAME@$USER.service
sudo systemctl restart $SERVICE_BASE_NAME.service
if [[ $? != 0 ]]; then
echo "Something went wrong when starting the $SERVICE_BASE_NAME"
exit 1
Expand Down
17 changes: 9 additions & 8 deletions uninstall_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,35 @@

source non_sudo_check.sh

SERVICE_INSTALL_FILE_NAME="[email protected]"
SERVICE_INSTANCE_FILE_NAME="asus_wmi_hotkeys_driver@$USER.service"
SERVICE_INSTALL_FILE_NAME="asus_wmi_hotkeys_driver.service"
SERVICE_INSTANCE_FILE_NAME="asus_wmi_hotkeys_driver.service"
SERVICE_INSTALL_DIR_PATH="/lib/systemd/system"

systemctl --user stop "$SERVICE_INSTANCE_FILE_NAME"
sudo systemctl stop "$SERVICE_INSTANCE_FILE_NAME"
if [[ $? != 0 ]]
then
echo "Something went wrong when stopping the $SERVICE_INSTANCE_FILE_NAME"
else
echo "Service $SERVICE_INSTANCE_FILE_NAME stopped"
fi

systemctl --user disable "$SERVICE_INSTANCE_FILE_NAME"
sudo systemctl disable "$SERVICE_INSTANCE_FILE_NAME"
if [[ $? != 0 ]]
then
echo "Something went wrong when disabling the $SERVICE_INSTANCE_FILE_NAME"
else
echo "Service $SERVICE_INSTANCE_FILE_NAME disabled"
fi

sudo rm -f "/usr/lib/systemd/user/$SERVICE_INSTALL_FILE_NAME"
sudo rm -f "$SERVICE_INSTALL_DIR_PATH/$SERVICE_INSTALL_FILE_NAME"
if [[ $? != 0 ]]
then
echo "Something went wrong when removing the $SERVICE_INSTALL_FILE_NAME"
echo "Something went wrong when removing the $SERVICE_INSTALL_DIR_PATH/$SERVICE_INSTALL_FILE_NAME"
else
echo "Service $SERVICE_INSTALL_FILE_NAME removed"
echo "Service $SERVICE_INSTALL_DIR_PATH/$SERVICE_INSTALL_FILE_NAME removed"
fi

systemctl --user daemon-reload
sudo systemctl daemon-reload

if [[ $? != 0 ]]; then
echo "Something went wrong when was called systemctl daemon reload"
Expand Down

0 comments on commit bc0586d

Please sign in to comment.