From 8f3a2e53d2c56cbdad71d03281af5315f1edeb51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Drahn=C3=ADk?= Date: Fri, 6 Oct 2023 19:31:33 +0200 Subject: [PATCH] WIP --- README.md | 7 +++++ asus_touchpad.X11.service | 1 - asus_touchpad.X11.user.service | 19 ++++++++++++ install.sh | 51 ++++++++++++++++++++++++++++---- uninstall.sh | 54 +++++++++++++++++++++++++--------- 5 files changed, 112 insertions(+), 20 deletions(-) create mode 100644 asus_touchpad.X11.user.service diff --git a/README.md b/README.md index 3430912..cfcd8e7 100644 --- a/README.md +++ b/README.md @@ -338,6 +338,13 @@ $ rm /home/ldrahnik/.Xauthority $ reboot ``` +**Read environment variables for systemctl service** + +``` +$ systemctl status .service # read PID +$ sudo strings /proc//environ +``` + ## Configuration ### Keyboard layout diff --git a/asus_touchpad.X11.service b/asus_touchpad.X11.service index e3e7950..96f6e76 100644 --- a/asus_touchpad.X11.service +++ b/asus_touchpad.X11.service @@ -1,6 +1,5 @@ [Unit] Description=Asus Touchpad to Numpad Handler for %i -After=display-manager.service [Service] User=%i diff --git a/asus_touchpad.X11.user.service b/asus_touchpad.X11.user.service new file mode 100644 index 0000000..0293f95 --- /dev/null +++ b/asus_touchpad.X11.user.service @@ -0,0 +1,19 @@ +[Unit] +Description=Asus Touchpad to Numpad Handler for %i + +[Service] +User=%i +Type=idle +ExecStart=/usr/bin/env python3 /usr/share/asus_touchpad_numpad-driver/asus_touchpad.py $LAYOUT $CONFIG_FILE_DIR +StandardInput=tty-force +StandardOutput=append:/var/log/asus_touchpad_numpad-driver/error.log +StandardError=append:/var/log/asus_touchpad_numpad-driver/error.log +TimeoutSec=5 +Restart=on-failure +Environment="DISPLAY=$XDISPLAY" +Environment="XAUTHORITY=$XAUTHORITY" +Environment="DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" +Environment="XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR" + +[Install] +WantedBy=default.target \ No newline at end of file diff --git a/install.sh b/install.sh index 786ed74..90e2c0a 100755 --- a/install.sh +++ b/install.sh @@ -224,17 +224,42 @@ if [ "$wayland_or_x11" = "x11" ]; then xauthority=$(/usr/bin/xauth info | grep Authority | awk '{print $3}') xdisplay=$(echo $DISPLAY) + echo "DISPLAY: $xdisplay" echo "AUTHORITY: $xauthority" - cat asus_touchpad.X11.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model XDISPLAY=$xdisplay XAUTHORITY=$xauthority envsubst '$LAYOUT $XAUTHORITY $XDISPLAY $CONFIG_FILE_DIR' > /etc/systemd/system/asus_touchpad_numpad@.service + + if [ "$1" = "--user" ]; then + + uid=$(id -u $RUN_UNDER_USER) + xdg_runtime_dir="/run/user/$uid" + dbus_session_bus_address="unix:path=$xdg_runtime_dir/bus" + + echo "UID: $uid" + echo "XDG_RUNTIME_DIR: $xdg_runtime_dir" + echo "DBUS_SESSION_BUS_ADDRESS: $dbus_session_bus_address" + + cat asus_touchpad.X11.user.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model XDISPLAY=$xdisplay XAUTHORITY=$xauthority XDG_RUNTIME_DIR=$xdg_runtime_dir DBUS_SESSION_BUS_ADDRESS=$dbus_session_bus_address envsubst '$LAYOUT $XAUTHORITY $XDISPLAY $CONFIG_FILE_DIR $XDG_RUNTIME_DIR $DBUS_SESSION_BUS_ADDRESS' > /usr/lib/systemd/asus_touchpad_numpad@.service + cat asus_touchpad.X11.user.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model XDISPLAY=$xdisplay XAUTHORITY=$xauthority XDG_RUNTIME_DIR=$xdg_runtime_dir DBUS_SESSION_BUS_ADDRESS=$dbus_session_bus_address envsubst '$LAYOUT $XAUTHORITY $XDISPLAY $CONFIG_FILE_DIR $XDG_RUNTIME_DIR $DBUS_SESSION_BUS_ADDRESS' > /etc/systemd/system/asus_touchpad_numpad@.service + cat asus_touchpad.X11.user.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model XDISPLAY=$xdisplay XAUTHORITY=$xauthority XDG_RUNTIME_DIR=$xdg_runtime_dir DBUS_SESSION_BUS_ADDRESS=$dbus_session_bus_address envsubst '$LAYOUT $XAUTHORITY $XDISPLAY $CONFIG_FILE_DIR $XDG_RUNTIME_DIR $DBUS_SESSION_BUS_ADDRESS' > /etc/systemd/user/asus_touchpad_numpad@.service + else + cat asus_touchpad.X11.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model XDISPLAY=$xdisplay XAUTHORITY=$xauthority envsubst '$LAYOUT $XAUTHORITY $XDISPLAY $CONFIG_FILE_DIR' > /etc/systemd/system/asus_touchpad_numpad@.service + fi elif [ "$wayland_or_x11" = "wayland" ]; then echo "Wayland is detected, unfortunatelly you will not be able use feature: Disabling Touchpad (e.g. Fn+special key) disables NumberPad aswell, at this moment is supported only X11" - cat asus_touchpad.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model envsubst '$LAYOUT $CONFIG_FILE_DIR' > /etc/systemd/system/asus_touchpad_numpad@.service + if [ "$1" = "--user" ]; then + cat asus_touchpad.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model envsubst '$LAYOUT $CONFIG_FILE_DIR' > /etc/systemd/user/asus_touchpad_numpad@.service + else + cat asus_touchpad.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model envsubst '$LAYOUT $CONFIG_FILE_DIR' > /etc/systemd/system/asus_touchpad_numpad@.service + fi else echo "Wayland or X11 is not detected" - cat asus_touchpad.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model envsubst '$LAYOUT $CONFIG_FILE_DIR' > /etc/systemd/system/asus_touchpad_numpad@.service + if [ "$1" = "--user" ]; then + cat asus_touchpad.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model envsubst '$LAYOUT $CONFIG_FILE_DIR' > /etc/systemd/user/asus_touchpad_numpad@.service + else + cat asus_touchpad.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model envsubst '$LAYOUT $CONFIG_FILE_DIR' > /etc/systemd/system/asus_touchpad_numpad@.service + fi fi @@ -394,7 +419,11 @@ else echo "Automatic installing of toggling script for XF86Calculator key failed. Please create an issue (https://github.com/asus-linux-drivers/asus-numberpad-driver/issues)." fi -systemctl daemon-reload +if [ "$1" = "--user" ]; then + systemctl --user daemon-reload +else + systemctl daemon-reload +fi if [[ $? != 0 ]]; then echo "Something went wrong when was called systemctl daemon reload" @@ -405,7 +434,19 @@ fi read -r -p "Do you want start the driver automatically at boot using systemd service? [y/N] (result might be black screen which will prevent login, systemd service is not designed to be started at boot with using X11, is recommended start driver on every startup by other way)" response case "$response" in [yY][eE][sS]|[yY]) - systemctl enable asus_touchpad_numpad@$RUN_UNDER_USER.service + + if [ "$1" = "--user" ]; then + # --user search /etc/systemd/user/ + + # systemctl enable --user asus_touchpad_numpad@ldrahnik.service + # Created symlink /home/ldrahnik/.config/systemd/user/default.target.wants/asus_touchpad_numpad@ldrahnik.service → /etc/xdg/systemd/user/asus_touchpad_numpad@.service. + + systemctl enable --user asus_touchpad_numpad@$RUN_UNDER_USER.service + else + # --global search /etc/systemd/system/ + systemctl enable --global asus_touchpad_numpad@$RUN_UNDER_USER.service + fi + if [[ $? != 0 ]]; then echo "Something went wrong when enabling the asus_touchpad_numpad.service" exit 1 diff --git a/uninstall.sh b/uninstall.sh index 24c051e..dc90b4f 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -24,22 +24,44 @@ echo $RUN_UNDER_USER source remove_previous_implementation_of_service.sh -systemctl stop asus_touchpad_numpad@$RUN_UNDER_USER.service -if [[ $? != 0 ]] +if [ "$1" = "--user" ] then - echo "asus_touchpad_numpad.service cannot be stopped correctly..." -fi -systemctl disable asus_touchpad_numpad@$RUN_UNDER_USER.service -if [[ $? != 0 ]] -then - echo "asus_touchpad_numpad.service cannot be disabled correctly..." -fi + systemctl --user stop asus_touchpad_numpad@$RUN_UNDER_USER.service + if [[ $? != 0 ]] + then + echo "asus_touchpad_numpad.service cannot be stopped correctly..." + fi -rm -f /etc/systemd/system/asus_touchpad_numpad@.service -if [[ $? != 0 ]] -then - echo "/etc/systemd/system/asus_touchpad_numpad.service cannot be removed correctly..." + systemctl --user disable asus_touchpad_numpad@$RUN_UNDER_USER.service + if [[ $? != 0 ]] + then + echo "asus_touchpad_numpad.service cannot be disabled correctly..." + fi + + rm -f /etc/systemd/user/asus_touchpad_numpad@.service + if [[ $? != 0 ]] + then + echo "/etc/systemd/user/asus_touchpad_numpad.service cannot be removed correctly..." + fi +else + systemctl --global stop asus_touchpad_numpad@$RUN_UNDER_USER.service + if [[ $? != 0 ]] + then + echo "asus_touchpad_numpad.service cannot be stopped correctly..." + fi + + systemctl --global disable asus_touchpad_numpad@$RUN_UNDER_USER.service + if [[ $? != 0 ]] + then + echo "asus_touchpad_numpad.service cannot be disabled correctly..." + fi + + rm -f /etc/systemd/system/asus_touchpad_numpad@.service + if [[ $? != 0 ]] + then + echo "/etc/systemd/system/asus_touchpad_numpad.service cannot be removed correctly..." + fi fi @@ -136,7 +158,11 @@ then echo "/usr/lib/udev/rules.d/90-numberpad-external-keyboard.rules cannot be removed correctly..." fi -systemctl daemon-reload +if [ "$1" = "--user" ]; then + systemctl --user daemon-reload +else + systemctl --global daemon-reload +fi if [[ $? != 0 ]]; then echo "Something went wrong when was called systemctl daemon reload"