From 76be69713e7cb2bf068a909b17ebd0a978c88016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Drahn=C3=ADk?= Date: Wed, 11 Oct 2023 13:38:59 +0200 Subject: [PATCH] Changed to install only for current user via systemctl --user service + refactored install/uninstall scripts + finished renaming to asus-numberpad-driver --- .gitignore | 2 +- .vscode/launch.json | 1 - README.md | 170 +++--- asus_numberpad_driver.service | 15 + asus_numberpad_driver.x11.service | 17 + asus_touchpad.X11.service | 18 - asus_touchpad.service | 15 - install.sh | 504 ++++-------------- install_calc_toggle.sh | 127 +++++ install_device_check.sh | 33 ++ install_external_keyboard_toggle.sh | 71 +++ install_layout_auto_suggestion.sh | 91 ++++ install_layout_select.sh | 50 ++ install_logs.sh | 23 + install_service.sh | 89 ++++ install_user_groups.sh | 24 + ...numpad_layouts => laptop_numberpad_layouts | 0 {numpad_layouts => layouts}/b7402-unicode.py | 0 {numpad_layouts => layouts}/b7402.py | 0 {numpad_layouts => layouts}/e210ma-unicode.py | 0 {numpad_layouts => layouts}/e210ma.py | 0 {numpad_layouts => layouts}/g513-unicode.py | 0 {numpad_layouts => layouts}/g513.py | 0 {numpad_layouts => layouts}/g533-unicode.py | 0 {numpad_layouts => layouts}/g533.py | 0 {numpad_layouts => layouts}/gx551-unicode.py | 0 {numpad_layouts => layouts}/gx551.py | 0 {numpad_layouts => layouts}/gx701-unicode.py | 0 {numpad_layouts => layouts}/gx701.py | 0 {numpad_layouts => layouts}/up5401ea-3145.py | 0 {numpad_layouts => layouts}/up5401ea-31B9.py | 0 .../up5401ea-unicode-3145.py | 0 .../up5401ea-unicode-31B9.py | 0 .../up5401ea-unicode.py | 0 {numpad_layouts => layouts}/up5401ea.py | 0 .../ux433fa-unicode.py | 0 {numpad_layouts => layouts}/ux433fa.py | 0 {numpad_layouts => layouts}/ux581l-unicode.py | 0 {numpad_layouts => layouts}/ux581l.py | 0 non_sudo_check.sh | 5 + asus_touchpad.py => numberpad.py | 18 +- remove_previous_implementation_of_service.sh | 20 - udev/90-numberpad-external-keyboard.rules | 4 +- udev/external_keyboard_is_connected.sh | 4 +- udev/external_keyboard_is_disconnected.sh | 4 +- uninstall.sh | 274 ++++------ uninstall_calc_toggle.sh | 39 ++ uninstall_external_keyboard_toggle.sh | 17 + uninstall_service.sh | 38 ++ uninstall_user_groups.sh | 19 + 50 files changed, 980 insertions(+), 712 deletions(-) create mode 100644 asus_numberpad_driver.service create mode 100644 asus_numberpad_driver.x11.service delete mode 100644 asus_touchpad.X11.service delete mode 100644 asus_touchpad.service create mode 100644 install_calc_toggle.sh create mode 100644 install_device_check.sh create mode 100644 install_external_keyboard_toggle.sh create mode 100644 install_layout_auto_suggestion.sh create mode 100644 install_layout_select.sh create mode 100644 install_logs.sh create mode 100644 install_service.sh create mode 100644 install_user_groups.sh rename laptop_numpad_layouts => laptop_numberpad_layouts (100%) rename {numpad_layouts => layouts}/b7402-unicode.py (100%) rename {numpad_layouts => layouts}/b7402.py (100%) rename {numpad_layouts => layouts}/e210ma-unicode.py (100%) rename {numpad_layouts => layouts}/e210ma.py (100%) rename {numpad_layouts => layouts}/g513-unicode.py (100%) rename {numpad_layouts => layouts}/g513.py (100%) rename {numpad_layouts => layouts}/g533-unicode.py (100%) rename {numpad_layouts => layouts}/g533.py (100%) rename {numpad_layouts => layouts}/gx551-unicode.py (100%) rename {numpad_layouts => layouts}/gx551.py (100%) rename {numpad_layouts => layouts}/gx701-unicode.py (100%) rename {numpad_layouts => layouts}/gx701.py (100%) rename {numpad_layouts => layouts}/up5401ea-3145.py (100%) rename {numpad_layouts => layouts}/up5401ea-31B9.py (100%) rename {numpad_layouts => layouts}/up5401ea-unicode-3145.py (100%) rename {numpad_layouts => layouts}/up5401ea-unicode-31B9.py (100%) rename {numpad_layouts => layouts}/up5401ea-unicode.py (100%) rename {numpad_layouts => layouts}/up5401ea.py (100%) rename {numpad_layouts => layouts}/ux433fa-unicode.py (100%) rename {numpad_layouts => layouts}/ux433fa.py (100%) rename {numpad_layouts => layouts}/ux581l-unicode.py (100%) rename {numpad_layouts => layouts}/ux581l.py (100%) create mode 100644 non_sudo_check.sh rename asus_touchpad.py => numberpad.py (99%) delete mode 100644 remove_previous_implementation_of_service.sh create mode 100644 uninstall_calc_toggle.sh create mode 100644 uninstall_external_keyboard_toggle.sh create mode 100644 uninstall_service.sh create mode 100644 uninstall_user_groups.sh diff --git a/.gitignore b/.gitignore index db2429a..785d7ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ __pycache__ *~ -asus_touchpad_numpad_dev \ No newline at end of file +numberpad_dev \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 0f73946..85f7c54 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,6 @@ "program": "${file}", "console": "integratedTerminal", "justMyCode": true, - "sudo": true, "args": ["up5401ea-unicode-31B9", ""] } ] diff --git a/README.md b/README.md index 3430912..b668864 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,9 @@ If you find this project useful, do not forget to give it a [![GitHub stars](htt ## Features +- Driver is installed for current user and does not run under `$ sudo` - Multiple pre-created [NumberPad layouts](https://github.com/asus-linux-drivers/asus-numberpad-driver#layouts) with possibility [create custom one or improve existing](https://github.com/asus-linux-drivers/asus-numberpad-driver#keyboard-layout) (keys, sizes, paddings..) -- Customization through 2-way sync [configuration file](https://github.com/asus-linux-drivers/asus-numberpad-driver#configuration-file) (when is run `sudo bash ./install.sh` changes done in config file may not be overwritten, the same when is run `sudo bash ./uninstall.sh` and when config file or part of does not exist is automatically created/completed with default values) +- Customization through 2-way sync [configuration file](https://github.com/asus-linux-drivers/asus-numberpad-driver#configuration-file) (when is run `$ bash ./install.sh` changes done in config file may not be overwritten, the same when is run `$ bash ./uninstall.sh` and when config file or part of does not exist is automatically created/completed with default values) - Automatic NumberPad model detection via [list of used NumberPad layouts for laptops](https://github.com/asus-linux-drivers/asus-numberpad-driver/blob/master/laptop_numpad_layouts) and when is available a connection via finding all other laptops on [linux-hardware.org](https://linux-hardware.org) which use the same version of NumberPad to which might be already in mentioned list associated proper layout - Activation/deactivation of NumberPad via holding top right icon or every spot with key `KEY_NUMLOCK` (activation time by default 1s) - Fast activation/deactivation of NumberPad via slide gesture beginning on top right icon (by default is required end slide after at least 30% of touchpad width and height) @@ -43,6 +44,90 @@ If you find this project useful, do not forget to give it a [![GitHub stars](htt - Disabling Touchpad (e.g. Fn+special key) disables by default NumberPad as well (*this functionality supports atm only `xinput` from `xorg` and `gnome` via `gsettings`*, can be disabled) - Is recognized when is connected external keyboard and automatically is changed [configuration](https://github.com/asus-linux-drivers/asus-numberpad-driver#external-keyboard-configuration) +## Installation + +Get latest dev version using `git` + +```bash +$ git clone https://github.com/asus-linux-drivers/asus-numberpad-driver +$ cd asus-numberpad-driver +``` + +or download latest release (stable version) from [release page](https://github.com/asus-linux-drivers/asus-numberpad-driver/releases), extract and install like this for current user only or for all users + +```bash +# try found touchpad with numberpad +$ bash install_device_check.sh +``` + +```bash +# install for current user +$ bash install.sh +``` + +or run separately parts of install script + +- add user to newly created `numberpad` group which owns `/var/log/asus-numberpad-driver` + +```bash +$ install_logs.sh +``` + +- add user to groups `i2c,input,uinput` + +```bash +$ bash install_user_groups.sh +``` + +- install predefined rule for change configuration when is external keyboard connected/disconnected + +```bash +$ export INSTALL_DIR_PATH="/usr/share/asus-numberpad-driver" +$ export CONFIG_FILE_DIR_PATH="$INSTALL_DIR_PATH" +$ export CONFIG_FILE_NAME="numberpad_dev" +$ export CONFIG_FILE_PATH="$CONFIG_FILE_DIR_PATH/$CONFIG_FILE_NAME" + +$ bash install_external_keyboard_toggle.sh +``` + +- run driver now and every time when user log in (do NOT run as `$ sudo`, works via `systemctl --user`) + +```bash +$ export CONFIG_FILE_DIR_PATH="/usr/share/asus-numberpad-driver" +$ export LAYOUT_NAME="up5401ea" + +$ bash install_service.sh +``` + +- make work top left corner slide gesture as function for show/disable calculator app (script below supports `io.elementary.calculator` and `gnome-calculator` via `gsettings`) + +```bash +$ bash install_calc_toggle.sh +``` + +or is available package for arch on AUR [here](https://aur.archlinux.org/packages?O=0&SeB=nd&K=asus-numberpad-driver&outdated=&SB=p&SO=d&PP=50&submit=Go) (replace model with available models, e.g. `asus-numberpad-driver-ux433fa-git`) + +```bash +$ paru -S asus-numberpad-driver-${model}-git +``` + +## Uninstallation + +And to uninstall run + +```bash +bash uninstall.sh +``` + +or run separately parts of uninstall script + +```bash +bash uninstall_calc_toggle.sh +bash uninstall_external_keyboard_toggle.sh +bash uninstall_external_service.sh +bash uninstall_user_groups.sh +``` + ## Layouts | Model/Layout | Description | Image | @@ -112,72 +197,31 @@ B: MSC=20 [Link](touchpad_product_id_info.md) -## Installation - -Install latest dev version using `git` - -```bash -git clone https://github.com/asus-linux-drivers/asus-numberpad-driver -cd asus-numberpad-driver -# install under current user (highly recommended) -sudo bash ./install.sh --user -# install as root -sudo bash ./install.sh -``` - -or download latest release (stable version) from [release page](https://github.com/asus-linux-drivers/asus-numberpad-driver/releases), extract and run: - -```bash -# install as root -sudo bash ./install.sh -# install under current user (highly recommended) -sudo bash ./install.sh --user -``` - -or is available package for arch on AUR [here](https://aur.archlinux.org/packages?O=0&SeB=nd&K=asus-numberpad-driver&outdated=&SB=p&SO=d&PP=50&submit=Go) (replace model with available models, e.g. `asus-numberpad-driver-ux433fa-git`) - -```bash -paru -S asus-numberpad-driver-${model}-git -``` - -## Uninstallation - -And to uninstall, just run: - -```bash -sudo bash ./uninstall.sh -# stop driver and uninstall for current user -sudo bash ./uninstall.sh --user -``` - ### Dependencies -**Everything is included in install script `sudo bash ./install.sh`** +**Everything is included in install scripts** To see the exact commands for your package manager look [here](./install.sh) (for python dependencies take a look at [requirements.txt](./requirements.txt)) ## Troubleshooting - **Start point [x:0,y:0] of touchpad is on the left top!** -- **Before debugging make sure you have disabled the asus_touchpad_numpad@.service service** +- **Before debugging make sure you have disabled the asus_numberpad_driver@.service** ```bash -# when installed for running under root (`sudo bash ./install.sh`) -sudo systemctl stop asus_touchpad_numpad@root.service -# when installed for running under current user (`sudo bash ./install.sh --user`) -sudo systemctl stop asus_touchpad_numpad@.service +$ systemctl stop --user asus_numberpad_driver@<$USER>.service ``` - To show debug logs run this command in terminal (**Do not forget specify numpad layout and which config do you want to use**): ```bash -# LOG=DEBUG sudo -E ./asus_touchpad.py +# LOG=DEBUG ./numberpad.py cd asus-numberpad-driver -LOG=DEBUG sudo -E ./asus_touchpad.py "up5401ea" "" # now driver use root of repository as directory for config file named asus_touchpad_numpad_dev +LOG=DEBUG ./numberpad.py "up5401ea" "" # now driver use root of repository as directory for config file named numberpad_dev which if does not exist will be autocreated with default values cd asus-numberpad-driver -LOG=DEBUG sudo -E ./asus_touchpad.py "up5401ea" "/usr/share/asus_touchpad_numpad-driver/" # now driver use installed config +LOG=DEBUG ./numberpad.py "up5401ea" "/usr/share/asus-numberpad-driver/" # now driver use installed config ``` - To show pressed keys: @@ -203,14 +247,12 @@ xdotool key XF86Calculator - directly just change `enabled` in appropriate config file: ``` -# when is installed under current user (--user) sudo is not required - # enabling NumberPad via command line -sudo sed -i "s/enabled = 0/enabled = 1/g" asus_touchpad_numpad_dev -sudo sed -i "s/enabled = 0/enabled = 1/g" /usr/share/asus_touchpad_numpad-driver/asus_touchpad_numpad_dev +sed -i "s/enabled = 0/enabled = 1/g" numberpad_dev +sed -i "s/enabled = 0/enabled = 1/g" /usr/share/asus-numberpad-driver/numberpad_dev # disabling -sudo sed -i "s/enabled = 1/enabled = 0/g" asus_touchpad_numpad_dev -sudo sed -i "s/enabled = 1/enabled = 0/g" /usr/share/asus_touchpad_numpad-driver/asus_touchpad_numpad_dev +sed -i "s/enabled = 1/enabled = 0/g" numberpad_dev +sed -i "s/enabled = 1/enabled = 0/g" /usr/share/asus-numberpad-driver/numberpad_dev ``` **Is any key from NumberPad not send properly?** @@ -284,7 +326,7 @@ $ sudo install dconf-editor $ gsettings set org.gnome.settings-daemon.plugins.media-keys calculator [\'\'] $ gsettings set org.gnome.settings-daemon.plugins.media-keys calculator-static [\'\'] ``` -- Whether script works can be tested via `bash /usr/share/asus_touchpad_numpad-driver/scripts/calculator_toggle.sh` +- Whether script works can be tested via `bash /usr/share/asus-numberpad-driver/scripts/calculator_toggle.sh` - Whether keybinding works can be tested via slide gesture from NumberPad or via simulating `XF86Calculator` key `xdotool key XF86Calculator` @@ -338,14 +380,21 @@ $ rm /home/ldrahnik/.Xauthority $ reboot ``` +**Read environment variables for systemctl service** + +``` +$ systemctl status .service # read PID +$ sudo strings /proc//environ +``` + ## Configuration ### Keyboard layout -During the install process `sudo bash ./install.sh`, you're required to select your keyboard layout: +During the install process `bash ./install.sh`, you're required to select your keyboard layout: ``` -Select models keypad layout: +... 1) b7402.py 2) e210ma.py 3) g533.py @@ -356,11 +405,12 @@ Select models keypad layout: 8) ux581l.py 9) Quit Please enter your choice +... ``` Each key layout (`g533.py`, `gx701.py`, ..) chosen during the install process corresponds to the specific file. To change any layout depending settings you need to locally edit the selected layout file and change the value of the corresponding variable from the first table below. -Example: If you want to set the size of top right icon to bigger and you have chosen the layout `up5401ea.py` during the install process. You need to change the corresponding variables (`top_right_icon_width = 400`,`top_right_icon_height = 400`) in the layout file (`asus-numberpad-driver/numpad_layouts/up5401ea.py`) and install the layout again. +Example: If you want to set the size of top right icon to bigger and you have chosen the layout `up5401ea.py` during the install process. You need to change the corresponding variables (`top_right_icon_width = 400`,`top_right_icon_height = 400`) in the layout file (`asus-numberpad-driver/layouts/up5401ea.py`) and install the layout again. | Option | Required | Default | Description | | --------------------------------------------- | -------- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | @@ -386,7 +436,7 @@ Example: If you want to set the size of top right icon to bigger and you have ch ### Configuration file -What is not depending on specific keyboard of Numpad is mentioned in table below and can be changed in config file `asus_touchpad_numpad_dev` (dev as device interface because is here saved even status enabled of NumberPad, latest used brightness) in installed driver location `/usr/share/asus_touchpad_numpad-driver/asus_touchpad_numpad_dev`. Example default one: +What is not depending on specific keyboard of Numpad is mentioned in table below and can be changed in config file `numberpad_dev` (dev as device interface because is here saved even status enabled of NumberPad, latest used brightness) in installed driver location `/usr/share/asus-numberpad-driver/numberpad_dev`. Example default one: ``` [main] @@ -498,4 +548,4 @@ Is preferred [ko-fi.com/ldrahnik](https://ko-fi.com/ldrahnik) instead of [buymea [![Ko-fi supporters](images/kofi.png)](https://ko-fi.com/ldrahnik) -[![Buy me a coffee supporters](images/buymeacoffee.png)](https://buymeacoffee.com/ldrahnik) +[![Buy me a coffee supporters](images/buymeacoffee.png)](https://buymeacoffee.com/ldrahnik) \ No newline at end of file diff --git a/asus_numberpad_driver.service b/asus_numberpad_driver.service new file mode 100644 index 0000000..d212411 --- /dev/null +++ b/asus_numberpad_driver.service @@ -0,0 +1,15 @@ +[Unit] +Description=Asus NumberPad Driver + +[Service] +Type=simple +ExecStart=/usr/bin/env python3 /usr/share/asus-numberpad-driver/numberpad.py $LAYOUT_NAME $CONFIG_FILE_DIR_PATH +StandardOutput=append:$ERROR_LOG_FILE_PATH +StandardError=append:$ERROR_LOG_FILE_PATH +TimeoutSec=5 +Restart=on-failure +Environment="DISPLAY=$DISPLAY" +Environment="DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" + +[Install] +WantedBy=default.target \ No newline at end of file diff --git a/asus_numberpad_driver.x11.service b/asus_numberpad_driver.x11.service new file mode 100644 index 0000000..20b06b5 --- /dev/null +++ b/asus_numberpad_driver.x11.service @@ -0,0 +1,17 @@ +[Unit] +Description=Asus NumberPad Driver + +[Service] +Type=simple +ExecStart=/usr/bin/env python3 /usr/share/asus-numberpad-driver/numberpad.py $LAYOUT_NAME $CONFIG_FILE_DIR_PATH +StandardOutput=append:$ERROR_LOG_FILE_PATH +StandardError=append:$ERROR_LOG_FILE_PATH +TimeoutSec=5 +Restart=on-failure +Environment="DISPLAY=$DISPLAY" +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/asus_touchpad.X11.service b/asus_touchpad.X11.service deleted file mode 100644 index 6f5c111..0000000 --- a/asus_touchpad.X11.service +++ /dev/null @@ -1,18 +0,0 @@ -[Unit] -Description=Asus Touchpad to Numpad Handler -After=display-manager.service - -[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" - -[Install] -WantedBy=graphical.target \ No newline at end of file diff --git a/asus_touchpad.service b/asus_touchpad.service deleted file mode 100644 index 1f176a1..0000000 --- a/asus_touchpad.service +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description=Asus Touchpad to Numpad Handler - -[Service] -User=%i -Type=simple -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 - -[Install] -WantedBy=default.target \ No newline at end of file diff --git a/install.sh b/install.sh index 786ed74..7c5e0b3 100755 --- a/install.sh +++ b/install.sh @@ -1,446 +1,136 @@ #!/bin/bash -# Checking if the script is runned as root (via sudo or other) -if [[ $(id -u) != 0 ]]; then - echo "Please run the installation script as root (using sudo for example)" - exit 1 -fi - -logout_requested=false - -# "root" by default or when is used --user it is "current user" -RUN_UNDER_USER=$USER - -if [ "$1" = "--user" ]; then - groupadd "input" - groupadd "uinput" - groupadd "i2c" - echo 'KERNEL=="uinput", GROUP="uinput", MODE:="0660"' | sudo tee /etc/udev/rules.d/99-input.rules - RUN_UNDER_USER=$SUDO_USER - usermod -a -G "i2c,input,uinput" $RUN_UNDER_USER - logout_requested=true -fi - -echo "driver will run under user $RUN_UNDER_USER" - -parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) - -# this works because sudo sets the environment variable SUDO_USER to the original username -session_id=$(loginctl | grep $SUDO_USER | head -1 | awk '{print $1}') -wayland_or_x11=$(loginctl show-session $session_id -p Type --value) - -echo "$wayland_or_x11 is DETECTED" -if [[ $(apt-get install 2>/dev/null) ]]; then - echo 'apt is here' && apt-get -y install ibus libevdev2 curl i2c-tools python3-dev python3-libevdev python3-numpy python3-xlib python3-pyinotify - if [ "$wayland_or_x11" = "x11" ]; then - apt-get -y install xinput - fi -elif [[ $(pacman -h 2>/dev/null) ]]; then - # arch does not have header packages (python3-dev), headers are shipped with base? python package should contains almost latest version python3.* - echo 'pacman is here' && pacman --noconfirm --needed -S ibus libevdev curl i2c-tools python python-libevdev python-numpy python-pyinotify python-xlib - if [ "$wayland_or_x11" = "x11" ]; then - pacman --noconfirm --needed -S xorg-xinput - fi -elif [[ $(dnf help 2>/dev/null) ]]; then - echo 'dnf is here' && dnf -y install ibus libevdev curl i2c-tools python3-devel python3-libevdev python3-numpy python3-inotify python3-xlib - if [ "$wayland_or_x11" = "x11" ]; then - dnf -y install xinput - fi -elif [[ $(yum help 2>/dev/null) ]]; then - # yum was replaced with newer dnf above - echo 'yum is here' && yum --y install ibus libevdev curl i2c-tools python3-devel python3-libevdev python3-numpy python3-inotify python3-xlib - if [ "$wayland_or_x11" = "x11" ]; then - yum --y install xinput - fi -else - echo "Not detected package manager. Required packages have not been installed so driver may not work properly. Please create an issue (https://github.com/asus-linux-drivers/asus-numberpad-driver/issues)." -fi - -modprobe i2c-dev - -# Checking if the i2c-dev module is successfuly loaded -if [[ $? != 0 ]]; then - echo "i2c-dev module cannot be loaded correctly. Make sure you have installed i2c-tools package" - exit 1 -fi - -interfaces=$(for i in $(i2cdetect -l | grep DesignWare | sed -r "s/^(i2c\-[0-9]+).*/\1/"); do echo $i; done) -if [ -z "$interfaces" ]; then - echo "No i2c interface can be found. Make sure you have installed libevdev packages" - exit 1 -fi - -touchpad_detected=false -for i in $interfaces; do - echo -n "Testing interface $i : " - number=$(echo -n $i | cut -d'-' -f2) - offTouchpadCmd="i2ctransfer -f -y $number w13@0x15 0x05 0x00 0x3d 0x03 0x06 0x00 0x07 0x00 0x0d 0x14 0x03 0x00 0xad" - i2c_test=$($offTouchpadCmd 2>&1) - if [ -z "$i2c_test" ]; then - echo "sucess" - touchpad_detected=true - break +source non_sudo_check.sh + +LOGS_DIR_PATH="/var/log/asus-numberpad-driver" + +source install_logs.sh + +echo + +# log output from every installing attempt aswell +LOGS_INSTALL_LOG_FILE_NAME=install-"$(date +"%d-%m-%Y-%H-%M-%S")".log +LOGS_INSTALL_LOG_FILE_PATH="$LOGS_DIR_PATH/$LOGS_INSTALL_LOG_FILE_NAME" +touch "$LOGS_INSTALL_LOG_FILE_PATH" + +{ + if [[ $(sudo apt-get install 2>/dev/null) ]]; then + sudo apt-get -y install ibus libevdev2 curl xinput i2c-tools python3-dev python3-libevdev python3-numpy python3-xlib python3-pyinotify + elif [[ $(sudo pacman -h 2>/dev/null) ]]; then + # arch does not have header packages (python3-dev), headers are shipped with base? python package should contains almost latest version python3.* + sudo pacman --noconfirm --needed -S ibus libevdev curl xorg-xinput i2c-tools python python-libevdev python-numpy python-pyinotify python-xlib + elif [[ $(sudo dnf help 2>/dev/null) ]]; then + sudo dnf -y install ibus libevdev curl xinput i2c-tools python3-devel python3-libevdev python3-numpy python3-inotify python3-xlib + elif [[ $(sudo yum help 2>/dev/null) ]]; then + # yum was replaced with newer dnf above + sudo yum --y install ibus libevdev curl xinput i2c-tools python3-devel python3-libevdev python3-numpy python3-inotify python3-xlib else - echo "failed" - fi -done - -if [ "$touchpad_detected" = false ]; then - echo 'The detection was not successful. Touchpad not found.' - exit 1 -fi - -if [[ -d numpad_layouts/__pycache__ ]]; then - rm -rf numpad_layouts/__pycache__ -fi - -laptop=$(dmidecode -s system-product-name | rev | cut -d ' ' -f1 | rev | cut -d "_" -f1) -laptop_full=$(dmidecode -s system-product-name) - -echo "Detected laptop: $laptop_full" - -detected_laptop_via_offline_table=$(cat laptop_numpad_layouts | grep $laptop | head -1 | cut -d'=' -f1) -detected_layout_via_offline_table=$(cat laptop_numpad_layouts | grep $laptop | head -1 | cut -d'=' -f2) - -# used below for recommendation of layout & for correct brightness levels -DEVICE_ID=$(cat /proc/bus/input/devices | grep ".*Touchpad\"$" | sort | cut -f 3 -d" " | cut -f 2 -d ":" | head -1) - -if [[ -z "$detected_layout_via_offline_table" || "$detected_layout_via_offline_table" == "none" ]]; then - - #VENDOR_ID="04f3" - VENDOR_ID=$(cat /proc/bus/input/devices | grep ".*Touchpad\"$" | sort | cut -f 3 -d" " | cut -f 1 -d ":" | head -1) - #echo $VENDOR_ID - #DEVICE_ID="31b9" - - # https://github.com/mohamed-badaoui/asus-touchpad-numpad-driver/issues/87 - # https://github.com/asus-linux-drivers/asus-numberpad-driver/issues/95 - # Should return DEVICE_ID: 3101 of 'ELAN1406:00' - # N: Name="ELAN9009:00 04F3:2C23 Touchpad" - # N: Name="ELAN1406:00 04F3:3101 Touchpad" - - #echo $DEVICE_ID - USER_AGENT="user-agent-name-here" - DEVICE_LIST_CURL_URL="https://linux-hardware.org/?view=search&vendorid=$VENDOR_ID&deviceid=$DEVICE_ID&typeid=input%2Fkeyboard" - #echo $CURL_URL - DEVICE_LIST_CURL=$(curl --user-agent "$USER_AGENT" "$DEVICE_LIST_CURL_URL" ) - #echo $RESULT - DEVICE_URL=$(echo $DEVICE_LIST_CURL | xmllint --html --xpath '//td[@class="device"]//a[1]/@href' 2>/dev/null - | cut -f2 -d"\"") - #echo $DEVICE_URL_LIST - LAPTOP_LIST_CURL_URL="https://linux-hardware.org$DEVICE_URL" - #echo $LAPTOP_LIST_CURL_URL - LAPTOP_LIST_CURL=$(curl --user-agent "$USER_AGENT" "$LAPTOP_LIST_CURL_URL" ) - #echo $LAPTOP_LIST_CURL - LAPTOP_LIST=$(echo $LAPTOP_LIST_CURL | xmllint --html --xpath '//table[contains(@class, "computers_list")]//tr/td[3]/span/@title' 2>/dev/null -) - #echo $LAPTOP_LIST - - # create laptop array - # - # [0] = Zenbook UX3402ZA_UX3402ZA - # [1] = Zenbook UM5401QAB_UM5401QA - # ... - # - IFS='\"' read -r -a array <<< $(echo $LAPTOP_LIST) - for index in "${!array[@]}" - do - if [[ "${array[index]}" != " title=" && "${array[index]}" != "title=" ]]; then - LAPTOP_NAME="${array[index]}" - #echo $LAPTOP_NAME - - probe_laptop=$( echo $LAPTOP_NAME | rev | cut -d ' ' -f1 | rev | cut -d "_" -f1) - #echo $probe_laptop - detected_laptop_via_offline_table=$(cat laptop_numpad_layouts | grep $probe_laptop | head -1 | cut -d'=' -f1) - detected_layout_via_offline_table=$(cat laptop_numpad_layouts | grep $probe_laptop | head -1 | cut -d'=' -f2) - - if [[ -z "$detected_layout_via_offline_table" || "$detected_layout_via_offline_table" == "none" ]]; then - continue - else - break - fi - fi - done - - if [[ -z "$detected_layout_via_offline_table" || "$detected_layout_via_offline_table" == "none" ]]; then - echo "Could not automatically detect numpad layout for your laptop. Please create an issue (https://github.com/asus-linux-drivers/asus-numberpad-driver/issues)." - fi -fi - -for option in $(ls numpad_layouts); do - if [ "$option" = "$detected_layout_via_offline_table.py" ]; then - read -r -p "Automatically recommended numpad layout: $detected_layout_via_offline_table (associated to $detected_laptop_via_offline_table). By default exist 2 variants for each laptop numpad layout. Standard one is recommended to use and send keys except percent and hash tag char directly, unfortunately is not resistance to overbinding keys to something else and that is reason why exist second version which send keys via unicode sequence of numbers except backspace and enter via pressing Ctrl+Shift+U+. Answering no, you can select other one from defaults (unicode variant for example) or you are able manually create your custom numpad layout later after installing. When is recommended layout (not a variant) wrong please create an issue (https://github.com/asus-linux-drivers/asus-numberpad-driver/issues). Do you want use recommended numpad layout, standard variant? [y/N]" response - case "$response" in [yY][eE][sS]|[yY]) - model=$detected_layout_via_offline_table - ;; - *) - ;; - esac + echo "Not detected package manager. Driver may not work properly because required packages have not been installed. Please create an issue (https://github.com/asus-linux-drivers/asus-numberpad-driver/issues)." fi -done -if [ -z "$model" ]; then echo - echo "Select your model keypad layout:" - PS3='Please enter your choice ' - options=($(ls numpad_layouts) "Quit") - select selected_opt in "${options[@]}"; do - if [ "$selected_opt" = "Quit" ]; then - exit 0 - fi - - for option in $(ls numpad_layouts); do - if [ "$option" = "$selected_opt" ]; then - model=${selected_opt::-3} - break - fi - done - if [ -z "$model" ]; then - echo "invalid option $REPLY" - else - break - fi - done -fi + sudo modprobe i2c-dev -echo "Selected key layout $model" + # check if the i2c-dev module is successfully loaded + if [[ $? != 0 ]]; then + echo "i2c-dev module cannot be loaded. Make sure you have installed i2c-tools package" + exit 1 + else + echo "i2c-dev module loaded" + fi -SPECIFIC_BRIGHTNESS_VALUES="$model-$DEVICE_ID" -if [ -f "numpad_layouts/$SPECIFIC_BRIGHTNESS_VALUES.py" ]; -then - model=$SPECIFIC_BRIGHTNESS_VALUES + echo "i2c-dev" | sudo tee /etc/modules-load.d/i2c-dev.conf >/dev/null - echo "Selected key layout specified to $model by touchpad ID $DEVICE_ID" -fi + if [[ $? != 0 ]]; then + echo "Something went wrong when adding i2c-dev module to auto loaded modules" + exit 1 + else + echo "i2c-dev module added to auto loaded modules" + fi -echo "Installing asus touchpad service to /etc/systemd/system/" + echo -source remove_previous_implementation_of_service.sh + source install_device_check.sh -CONFIG_FILE_DIR="/usr/share/asus_touchpad_numpad-driver" -CONFIG_FILE_NAME="asus_touchpad_numpad_dev" -CONF_FILE="$CONFIG_FILE_DIR/$CONFIG_FILE_NAME" + echo -if [ "$wayland_or_x11" = "x11" ]; then - echo "X11 is detected" + source install_user_groups.sh - 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 -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" + echo + + # do not install __pycache__ + if [[ -d layouts/__pycache__ ]]; then + rm -rf layouts/__pycache__ + fi - cat asus_touchpad.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model envsubst '$LAYOUT $CONFIG_FILE_DIR' > /etc/systemd/system/asus_touchpad_numpad@.service -else - echo "Wayland or X11 is not detected" + INSTALL_DIR_PATH="/usr/share/asus-numberpad-driver" + CONFIG_FILE_DIR_PATH="$INSTALL_DIR_PATH" + CONFIG_FILE_NAME="numberpad_dev" + CONFIG_FILE_PATH="$CONFIG_FILE_DIR_PATH/$CONFIG_FILE_NAME" + + sudo mkdir -p "$INSTALL_DIR_PATH/layouts" + sudo chown -R $USER "$INSTALL_DIR_PATH" + sudo install numberpad.py "$INSTALL_DIR_PATH" + sudo install -t "$INSTALL_DIR_PATH/layouts" layouts/*.py + + if [[ -f "$CONFIG_FILE_PATH" ]]; then + read -r -p "In system remains config file from previous installation. Do you want replace that config with default config? [y/N]" RESPONSE + case "$RESPONSE" in [yY][eE][sS]|[yY]) + + # default will be autocreated, that is why is removed + sudo rm -f $CONFIG_FILE_PATH + if [[ $? != 0 ]]; then + echo "$CONFIG_FILE_PATH cannot be removed correctly..." + exit 1 + fi + ;; + *) + ;; + esac + else + echo "Default config will be autocreated during the first run and available for futher modifications here:" + echo "$CONFIG_FILE_PATH" + fi - 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 + echo + source install_layout_auto_suggestion.sh -mkdir -p /usr/share/asus_touchpad_numpad-driver/numpad_layouts -chown -R $RUN_UNDER_USER /usr/share/asus_touchpad_numpad-driver -mkdir -p /var/log/asus_touchpad_numpad-driver -install asus_touchpad.py /usr/share/asus_touchpad_numpad-driver/ -install -t /usr/share/asus_touchpad_numpad-driver/numpad_layouts numpad_layouts/*.py + echo -echo "Installing udev rules to /usr/lib/udev/rules.d/" + if [ -z "$LAYOUT_NAME" ]; then -cp udev/90-numberpad-external-keyboard.rules /usr/lib/udev/rules.d/ + source install_layout_select.sh -echo "Added 90-numberpad-external-keyboard.rules" -mkdir -p /usr/share/asus_touchpad_numpad-driver/udev + echo + fi -cat udev/external_keyboard_is_connected.sh | CONFIG_FILE_DIR=$CONFIG_FILE_DIR envsubst '$CONFIG_FILE_DIR' > /usr/share/asus_touchpad_numpad-driver/udev/external_keyboard_is_connected.sh -cat udev/external_keyboard_is_disconnected.sh | CONFIG_FILE_DIR=$CONFIG_FILE_DIR envsubst '$CONFIG_FILE_DIR' > /usr/share/asus_touchpad_numpad-driver/udev/external_keyboard_is_disconnected.sh -chmod +x /usr/share/asus_touchpad_numpad-driver/udev/external_keyboard_is_connected.sh -chmod +x /usr/share/asus_touchpad_numpad-driver/udev/external_keyboard_is_disconnected.sh + source install_service.sh -udevadm control --reload-rules + echo -echo "i2c-dev" | tee /etc/modules-load.d/i2c-dev.conf >/dev/null + source install_external_keyboard_toggle.sh -if [[ -f "$CONF_FILE" ]]; then - read -r -p "In system remains config file from previous installation. Do you want replace this with default config file [y/N]" response - case "$response" in [yY][eE][sS]|[yY]) - # default will be autocreated, so that is why remove - rm -f $CONF_FILE - if [[ $? != 0 ]]; then - echo "$CONF_FILE cannot be removed correctly..." - exit 1 - fi - ;; - *) - ;; - esac -else - echo "Installed default config which can be futher modified here:" - echo "$CONF_FILE" -fi - -if [[ $(type gsettings 2>/dev/null) ]]; then - echo "gsettings is here" - read -r -p "Do you want automatically try install toggling script for XF86Calculator key? Slide from top left icon will then invoke/close detected calculator app. [y/N]" response - case "$response" in [yY][eE][sS]|[yY]) + echo - existing_shortcut_string=$(runuser -u $SUDO_USER gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings) - #echo $existing_shortcut_string - - new_shortcut_index=0 - filtered_existing_shortcut_string="[" - filtered_existing_shortcut_count=0 - - if [[ "$existing_shortcut_string" != "@as []" ]]; then - IFS=', ' read -ra existing_shortcut_array <<< "$existing_shortcut_string" - for shortcut_index in "${!existing_shortcut_array[@]}"; do - shortcut="${existing_shortcut_array[$shortcut_index]}" - shortcut_index=$( echo $shortcut | cut -d/ -f 8 | sed 's/[^0-9]//g') - - # looking for first free highest index (gaps will not be used for sure) - if [[ "$shortcut_index" -gt "$new_shortcut_index" ]]; then - new_shortcut_index=$shortcut_index - #echo $shortcut_index - fi - - # filter out already added the same shortcuts by this driver (can be caused by running install script multiple times so clean and then add only 1 new - we want no duplicates) - command=$(runuser -u $SUDO_USER gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/ 'command') - #echo $command - if [[ "$command" != "'bash /usr/share/asus_touchpad_numpad-driver/scripts/calculator_toggle.sh'" ]]; then - #echo "Found something else on index $shortcut_index" - if [[ "$filtered_existing_shortcut_string" != "[" ]]; then - filtered_existing_shortcut_string="$filtered_existing_shortcut_string"", '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/'" - else - filtered_existing_shortcut_string="$filtered_existing_shortcut_string""'/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/'" - fi - else - echo "Found already existing duplicated shortcut for toggling calculator, will be removed" - ((filtered_existing_shortcut_count=filtered_existing_shortcut_count+1)) - runuser -u $SUDO_USER gsettings reset-recursively org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/ - fi - done - ((new_shortcut_index=new_shortcut_index+1)) - #echo $new_shortcut_index - filtered_existing_shortcut_string="$filtered_existing_shortcut_string"']' - #echo $filtered_existing_shortcut_string - #echo $filtered_existing_shortcut_count - - if [[ $filtered_existing_shortcut_count != 0 ]]; then - new_shortcut_string=${filtered_existing_shortcut_string::-2}", /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$new_shortcut_index']" - else - # after filtering duplicated shortcuts array of shortcuts is completely empty - new_shortcut_string=" ['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0']" - fi - #echo $new_shortcut_string - else - # array of shortcuts is completely empty - new_shortcut_string=" ['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0']" - fi - - IS_INSTALLED_ELEMENTARY_OS_CALCULATOR=$(type io.elementary.calculator &>/dev/null ; echo $? ) - IS_INSTALLED_GNOME_OS_CALCULATOR=$(type gnome-calculator &>/dev/null ; echo $? ) - echo "is installed io.elementary.calculator: $IS_INSTALLED_ELEMENTARY_OS_CALCULATOR" - echo "is installed gnome-calculator: $IS_INSTALLED_GNOME_OS_CALCULATOR" - - if [[ $IS_INSTALLED_ELEMENTARY_OS_CALCULATOR -eq 0 ]]; then - echo "setting up for io.elementary.calculator" - - mkdir -p /usr/share/asus_touchpad_numpad-driver/scripts - cp scripts/io_elementary_calculator_toggle.sh /usr/share/asus_touchpad_numpad-driver/scripts/calculator_toggle.sh - chmod +x /usr/share/asus_touchpad_numpad-driver/scripts/calculator_toggle.sh - - # this has to be empty (no doubled XF86Calculator) - runuser -u $SUDO_USER gsettings set org.gnome.settings-daemon.plugins.media-keys calculator [\'\'] - runuser -u $SUDO_USER gsettings set org.gnome.settings-daemon.plugins.media-keys calculator-static [\'\'] - - runuser -u $SUDO_USER gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "${new_shortcut_string}" - runuser -u $SUDO_USER gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$new_shortcut_index/ "name" "Calculator" - runuser -u $SUDO_USER gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$new_shortcut_index/ "command" "bash /usr/share/asus_touchpad_numpad-driver/scripts/calculator_toggle.sh" - runuser -u $SUDO_USER gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$new_shortcut_index/ "binding" "XF86Calculator" - - existing_shortcut_string=$(runuser -u $SUDO_USER gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings) - #echo $existing_shortcut_string - echo "Toggling script for calculator app io.elementary.calculator has been installed." - - logout_requested=true - elif [[ $IS_INSTALLED_GNOME_OS_CALCULATOR -eq 0 ]]; then - echo "setting up for gnome-calculator" - - mkdir -p /usr/share/asus_touchpad_numpad-driver/scripts - cp scripts/gnome_calculator_toggle.sh /usr/share/asus_touchpad_numpad-driver/scripts/calculator_toggle.sh - chmod +x /usr/share/asus_touchpad_numpad-driver/scripts/calculator_toggle.sh - - # this has to be empty (no doubled XF86Calculator) - runuser -u $SUDO_USER gsettings set org.gnome.settings-daemon.plugins.media-keys calculator [\'\'] - runuser -u $SUDO_USER gsettings set org.gnome.settings-daemon.plugins.media-keys calculator-static [\'\'] - - runuser -u $SUDO_USER gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "${new_shortcut_string}" - runuser -u $SUDO_USER gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$new_shortcut_index/ "name" "Calculator" - runuser -u $SUDO_USER gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$new_shortcut_index/ "command" "bash /usr/share/asus_touchpad_numpad-driver/scripts/calculator_toggle.sh" - runuser -u $SUDO_USER gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$new_shortcut_index/ "binding" "XF86Calculator" - - existing_shortcut_string=$(runuser -u $SUDO_USER gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings) - #echo $existing_shortcut_string - echo "Toggling script for calculator app gnome-calculator has been installed." - - logout_requested=true - 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 - ;; - *) - ;; - esac -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 [[ $? != 0 ]]; then - echo "Something went wrong when was called systemctl daemon reload" - exit 1 -else - echo "Systemctl daemon realod called succesfully" -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 [[ $? != 0 ]]; then - echo "Something went wrong when enabling the asus_touchpad_numpad.service" - exit 1 - else - echo "Asus touchpad numpad service enabled" - fi - ;; - *) - echo "Add this line to startup scripts 'sudo systemctl start asus_touchpad_numpad@$RUN_UNDER_USER.service' or start driver manually with the same line when needed. Now will be service started until first reboot." - ;; -esac + source install_calc_toggle.sh -systemctl restart asus_touchpad_numpad@$RUN_UNDER_USER.service -if [[ $? != 0 ]]; then - echo "Something went wrong when enabling the asus_touchpad_numpad.service" - exit 1 -else - echo "Asus touchpad numpad service started" -fi + echo -if [[ "$logout_requested" = true ]] -then + echo "Installation finished succesfully" - echo "Install process requested to succesfull finish atleast log out or reboot" - echo "Without that driver might not work properly" + echo - read -r -p "Do you want reboot now? [y/N]" response + read -r -p "Reboot is required. Do you want reboot now? [y/N]" response case "$response" in [yY][eE][sS]|[yY]) reboot ;; *) ;; esac -fi -echo "Install finished" + echo -exit 0 + exit 0 +} 2>&1 | sudo tee "$LOGS_INSTALL_LOG_FILE_PATH" \ No newline at end of file diff --git a/install_calc_toggle.sh b/install_calc_toggle.sh new file mode 100644 index 0000000..eb2e0ce --- /dev/null +++ b/install_calc_toggle.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +source non_sudo_check.sh + +# INHERIT VARS +INSTALL_DIR_PATH="/usr/share/asus-numberpad-driver" + +if [ -z "$INSTALL_DIR_PATH" ]; then + INSTALL_DIR_PATH="/usr/share/asus-numberpad-driver" +fi + +echo "Calculator app" +echo + +if [[ $(type gsettings 2>/dev/null) ]]; then + + read -r -p "Do you want try to install toggling script for XF86Calculator key? [y/N]" response + case "$response" in [yY][eE][sS]|[yY]) + + echo + + EXISTING_SHORTCUT_STRING=$(gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings) + + NEW_SHORTCUT_INDEX=0 + filtered_existing_shortcut_string="[" + filtered_existing_shortcut_count=0 + + if [[ "$EXISTING_SHORTCUT_STRING" != "@as []" ]]; then + IFS=', ' read -ra existing_shortcut_array <<< "$EXISTING_SHORTCUT_STRING" + for shortcut_index in "${!existing_shortcut_array[@]}"; do + shortcut="${existing_shortcut_array[$shortcut_index]}" + shortcut_index=$( echo $shortcut | cut -d/ -f 8 | sed 's/[^0-9]//g') + + # looking for first free highest index (gaps will not be used for sure) + if [[ "$shortcut_index" -gt "$NEW_SHORTCUT_INDEX" ]]; then + NEW_SHORTCUT_INDEX=$shortcut_index + fi + + # filter out already added the same shortcuts by this driver (can be caused by running install script multiple times so clean and then add only 1 new - we want no duplicates) + command=$(gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/ 'command') + if [[ "$command" != "'bash /usr/share/asus_touchpad_numpad-driver/scripts/calculator_toggle.sh'" ]]; then + #echo "Found something else on index $shortcut_index" + if [[ "$filtered_existing_shortcut_string" != "[" ]]; then + filtered_existing_shortcut_string="$filtered_existing_shortcut_string"", '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/'" + else + filtered_existing_shortcut_string="$filtered_existing_shortcut_string""'/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/'" + fi + else + echo "Found already existing duplicated shortcut for toggling calculator, will be removed" + ((filtered_existing_shortcut_count=filtered_existing_shortcut_count+1)) + gsettings reset-recursively org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/ + fi + done + ((NEW_SHORTCUT_INDEX=NEW_SHORTCUT_INDEX+1)) + + filtered_existing_shortcut_string="$filtered_existing_shortcut_string"']' + + if [[ $filtered_existing_shortcut_count != 0 ]]; then + new_shortcut_string=${filtered_existing_shortcut_string::-2}", /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$NEW_SHORTCUT_INDEX']" + else + # after filtering duplicated shortcuts array of shortcuts is completely empty + new_shortcut_string=" ['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0']" + fi + else + # array of shortcuts is completely empty + new_shortcut_string=" ['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0']" + fi + + IS_INSTALLED_ELEMENTARY_OS_CALCULATOR=$(type io.elementary.calculator &>/dev/null ; echo $? ) + if [ $IS_INSTALLED_ELEMENTARY_OS_CALCULATOR == "0" ]; then + echo "Detected io.elementary.calculator" + fi + + IS_INSTALLED_GNOME_OS_CALCULATOR=$(type gnome-calculator &>/dev/null ; echo $? ) + if [ $IS_INSTALLED_GNOME_OS_CALCULATOR == "0" ]; then + echo "Detected gnome-calculator" + fi + + if [[ $IS_INSTALLED_ELEMENTARY_OS_CALCULATOR -eq 0 ]]; then + echo "Setting up for io.elementary.calculator" + + mkdir -p $INSTALL_DIR_PATH/scripts + cp scripts/io_elementary_calculator_toggle.sh $INSTALL_DIR_PATH/scripts/calculator_toggle.sh + chmod +x $INSTALL_DIR_PATH/scripts/calculator_toggle.sh + + # this has to be empty (no doubled XF86Calculator) + gsettings set org.gnome.settings-daemon.plugins.media-keys calculator [\'\'] + gsettings set org.gnome.settings-daemon.plugins.media-keys calculator-static [\'\'] + + gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "${new_shortcut_string}" + gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$NEW_SHORTCUT_INDEX/ "name" "Calculator" + gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$NEW_SHORTCUT_INDEX/ "command" "bash $INSTALL_DIR_PATH/scripts/calculator_toggle.sh" + gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$NEW_SHORTCUT_INDEX/ "binding" "XF86Calculator" + + EXISTING_SHORTCUT_STRING=$(gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings) + + echo "Toggling script for calculator app io.elementary.calculator has been installed." + + elif [[ $IS_INSTALLED_GNOME_OS_CALCULATOR -eq 0 ]]; then + echo "Setting up for gnome-calculator" + + mkdir -p /usr/share/asus_touchpad_numpad-driver/scripts + cp scripts/gnome_calculator_toggle.sh /usr/share/asus_touchpad_numpad-driver/scripts/calculator_toggle.sh + chmod +x /usr/share/asus_touchpad_numpad-driver/scripts/calculator_toggle.sh + + # this has to be empty (no doubled XF86Calculator) + gsettings set org.gnome.settings-daemon.plugins.media-keys calculator [\'\'] + gsettings set org.gnome.settings-daemon.plugins.media-keys calculator-static [\'\'] + + gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "${new_shortcut_string}" + gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$NEW_SHORTCUT_INDEX/ "name" "Calculator" + gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$NEW_SHORTCUT_INDEX/ "command" "bash $INSTALL_DIR_PATH/scripts/calculator_toggle.sh" + gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$NEW_SHORTCUT_INDEX/ "binding" "XF86Calculator" + + EXISTING_SHORTCUT_STRING=$(gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings) + + echo "Toggling script for calculator app gnome-calculator has been installed." + 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 + ;; + *) + ;; + esac +else + echo "Automatic installing of toggling script for XF86Calculator key failed. Gsettings was not found." +fi \ No newline at end of file diff --git a/install_device_check.sh b/install_device_check.sh new file mode 100644 index 0000000..547149d --- /dev/null +++ b/install_device_check.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +source non_sudo_check.sh + +INTERFACES=$(for i in $(i2cdetect -l | grep DesignWare | sed -r "s/^(i2c\-[0-9]+).*/\1/"); do echo $i; done) +if [ -z "$INTERFACES" ]; then + echo "No i2c interface can be found. Make sure you have installed libevdev packages" + exit 1 +fi + +TOUCHPAD_WITH_NUMBERPAD_DETECTED=false +for INDEX in $INTERFACES; do + echo -n "Testing interface $INDEX: " + + NUMBER=$(echo -n $INDEX | cut -d'-' -f2) + NUMBERPAD_OFF_CMD="i2ctransfer -f -y $NUMBER w13@0x15 0x05 0x00 0x3d 0x03 0x06 0x00 0x07 0x00 0x0d 0x14 0x03 0x00 0xad" + + I2C_TEST=$($NUMBERPAD_OFF_CMD 2>&1) + if [ -z "$I2C_TEST" ]; then + echo "success" + TOUCHPAD_WITH_NUMBERPAD_DETECTED=true + break + else + echo "failed" + fi +done + +if [ "$TOUCHPAD_WITH_NUMBERPAD_DETECTED" ]; then + echo "The detection was successful. Touchpad with numberpad found: $INDEX" +else + echo "The detection was not successful. Touchpad with numberpad not found" + exit 1 +fi \ No newline at end of file diff --git a/install_external_keyboard_toggle.sh b/install_external_keyboard_toggle.sh new file mode 100644 index 0000000..8103770 --- /dev/null +++ b/install_external_keyboard_toggle.sh @@ -0,0 +1,71 @@ + +#!/bin/bash + +source non_sudo_check.sh + +# INHERIT VARS +#INSTALL_DIR_PATH="/usr/share/asus-numberpad-driver" +#CONFIG_FILE_DIR_PATH="$INSTALL_DIR_PATH" +#CONFIG_FILE_NAME="numberpad_dev" +#CONFIG_FILE_PATH="$CONFIG_FILE_DIR_PATH/$CONFIG_FILE_NAME" + +if [ -z "$INSTALL_DIR_PATH" ]; then + INSTALL_DIR_PATH="/usr/share/asus-numberpad-driver" +fi +if [ -z "$CONFIG_FILE_DIR_PATH" ]; then + CONFIG_FILE_DIR_PATH="$INSTALL_DIR_PATH" +fi +if [ -z "$CONFIG_FILE_NAME" ]; then + CONFIG_FILE_NAME="numberpad_dev" +fi +if [ -z "$CONFIG_FILE_PATH" ]; then + CONFIG_FILE_PATH="$CONFIG_FILE_DIR_PATH/$CONFIG_FILE_NAME" +fi + +echo "External keyboard" +echo +echo "Is predefined rule for change configuration when is external keyboard connected/disconnected." +echo +echo "State connected of external keyboard means these changes:" +echo +echo " - Numlock key does not activate numberpad (config value is sys_numlock_enables_numpad=0)" +echo " - Numberpad does not disable numlock (config value is numpad_disables_sys_numlock=0)" +echo +echo "In summary when is external keyboard connected then is numberpad not linked to numlock state in both ways. Not connected state is the opposite." + +echo + +read -r -p "Do you want install rule for external keyboard? [y/N]" RESPONSE +case "$RESPONSE" in [yY][eE][sS]|[yY]) + + echo + + cat "udev/90-numberpad-external-keyboard.rules" | INSTALL_DIR_PATH=$INSTALL_DIR_PATH envsubst '$INSTALL_DIR_PATH' | sudo tee "/usr/lib/udev/rules.d/90-numberpad-external-keyboard.rules" >/dev/null + + if [[ $? != 0 ]]; then + echo "Something went wrong when moving 90-numberpad-external-keyboard.rules" + exit 1 + else + echo "Rule 90-numberpad-external-keyboard.rules placed" + fi + + sudo mkdir -p "$INSTALL_DIR_PATH/udev" + + cat "udev/external_keyboard_is_connected.sh" | CONFIG_FILE_PATH=$CONFIG_FILE_PATH envsubst '$CONFIG_FILE_PATH' | sudo tee "$INSTALL_DIR_PATH/udev/external_keyboard_is_connected.sh" >/dev/null + cat "udev/external_keyboard_is_disconnected.sh" | CONFIG_FILE_PATH=$CONFIG_FILE_PATH envsubst '$CONFIG_FILE_PATH' | sudo tee "$INSTALL_DIR_PATH/udev/external_keyboard_is_disconnected.sh" >/dev/null + + sudo chmod +x "$INSTALL_DIR_PATH/udev/external_keyboard_is_connected.sh" + sudo chmod +x "$INSTALL_DIR_PATH/udev/external_keyboard_is_disconnected.sh" + + sudo udevadm control --reload-rules + + if [[ $? != 0 ]]; then + echo "Something went wrong when reloading udev rules" + exit 1 + else + echo "Udev rules reloaded" + fi + ;; +*) + ;; +esac \ No newline at end of file diff --git a/install_layout_auto_suggestion.sh b/install_layout_auto_suggestion.sh new file mode 100644 index 0000000..df2fd72 --- /dev/null +++ b/install_layout_auto_suggestion.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +source non_sudo_check.sh + +LAPTOP_NAME=$(sudo dmidecode -s system-product-name | rev | cut -d ' ' -f1 | rev | cut -d "_" -f1) +LAPTOP_NAME_FULL=$(sudo dmidecode -s system-product-name) + +DETECTED_LAPTOP_VIA_OFFLINE_TABLE=$(cat laptop_numberpad_layouts | grep $LAPTOP_NAME | head -1 | cut -d'=' -f1) +DETECTED_LAYOUT_VIA_OFFLINE_TABLE=$(cat laptop_numberpad_layouts | grep $LAPTOP_NAME | head -1 | cut -d'=' -f2) + +DEVICE_ID=$(cat /proc/bus/input/devices | grep ".*Touchpad\"$" | sort | cut -f 3 -d" " | cut -f 2 -d ":" | head -1) + +if [[ -z "$DETECTED_LAYOUT_VIA_OFFLINE_TABLE" || "$DETECTED_LAYOUT_VIA_OFFLINE_TABLE" == "none" ]]; then + + VENDOR_ID=$(cat /proc/bus/input/devices | grep ".*Touchpad\"$" | sort | cut -f 3 -d" " | cut -f 1 -d ":" | head -1) + + # When exist device 9009:00 should return other DEVICE_ID: 3101 of 'ELAN1406:00' + # + # https://github.com/mohamed-badaoui/asus-touchpad-numpad-driver/issues/87 + # https://github.com/asus-linux-drivers/asus-numberpad-driver/issues/95 + # + # N: Name="ELAN9009:00 04F3:2C23 Touchpad" + # N: Name="ELAN1406:00 04F3:3101 Touchpad" + + USER_AGENT="user-agent-name-here" + DEVICE_LIST_CURL_URL="https://linux-hardware.org/?view=search&vendorid=$VENDOR_ID&deviceid=$DEVICE_ID&typeid=input%2Fkeyboard" + DEVICE_LIST_CURL=$(curl --user-agent "$USER_AGENT" "$DEVICE_LIST_CURL_URL" ) + DEVICE_URL=$(echo $DEVICE_LIST_CURL | xmllint --html --xpath '//td[@class="device"]//a[1]/@href' 2>/dev/null - | cut -f2 -d"\"") + LAPTOP_LIST_CURL_URL="https://linux-hardware.org$DEVICE_URL" + LAPTOP_LIST_CURL=$(curl --user-agent "$USER_AGENT" "$LAPTOP_LIST_CURL_URL" ) + LAPTOP_LIST=$(echo $LAPTOP_LIST_CURL | xmllint --html --xpath '//table[contains(@class, "computers_list")]//tr/td[3]/span/@title' 2>/dev/null -) + + # create laptop array + # + # [0] = Zenbook UX3402ZA_UX3402ZA + # [1] = Zenbook UM5401QAB_UM5401QA + # ... + # + IFS='\"' read -r -a array <<< $(echo $LAPTOP_LIST) + for INDEX in "${!array[@]}" + do + if [[ "${array[INDEX]}" != " title=" && "${array[INDEX]}" != "title=" ]]; then + LAPTOP_NAME="${array[INDEX]}" + + PROBE_LAPTOP=$( echo $LAPTOP_NAME | rev | cut -d ' ' -f1 | rev | cut -d "_" -f1) + + DETECTED_LAPTOP_VIA_OFFLINE_TABLE=$(cat laptop_numberpad_layouts | grep $PROBE_LAPTOP | head -1 | cut -d'=' -f1) + DETECTED_LAYOUT_VIA_OFFLINE_TABLE=$(cat laptop_numberpad__layouts | grep $PROBE_LAPTOP | head -1 | cut -d'=' -f2) + + if [[ -z "$DETECTED_LAYOUT_VIA_OFFLINE_TABLE" || "$DETECTED_LAYOUT_VIA_OFFLINE_TABLE" == "none" ]]; then + continue + else + break + fi + fi + done + + if [[ -z "$DETECTED_LAYOUT_VIA_OFFLINE_TABLE" || "$DETECTED_LAYOUT_VIA_OFFLINE_TABLE" == "none" ]]; then + echo "Could not automatically detect numberpad layout for your laptop. Please create an issue (https://github.com/asus-linux-drivers/asus-numberpad-driver/issues)." + fi +fi + +for OPTION in $(ls layouts); do + if [ "$OPTION" = "$DETECTED_LAYOUT_VIA_OFFLINE_TABLE.py" ]; then + echo "NumberPad layout" + echo + echo "Are predefined 2 variants of numberpad layouts for each laptop:" + echo " - Standard is recommended to use, the keys except percent and hash tag are send directly but layout is not resistant to overbinding these keys to something else and that is reason why exist second version" + echo " - Unicode send keys like unicode chars except backspace and enter using shortcut Ctrl+Shift+U+." + echo + read -r -p "Automatically recommended numberpad layout for detected laptop: $LAPTOP_NAME_FULL is standard: $DETECTED_LAYOUT_VIA_OFFLINE_TABLE (associated to $DETECTED_LAPTOP_VIA_OFFLINE_TABLE). Do you want to use? [y/N]" RESPONSE + case "$RESPONSE" in [yY][eE][sS]|[yY]) + + echo + + LAYOUT_NAME=$DETECTED_LAYOUT_VIA_OFFLINE_TABLE + + SPECIFIC_BRIGHTNESS_VALUES="$LAYOUT_NAME-$DEVICE_ID" + if [ -f "layouts/$SPECIFIC_BRIGHTNESS_VALUES.py" ]; + then + LAYOUT_NAME=$SPECIFIC_BRIGHTNESS_VALUES + echo "Selected key layout specified by touchpad ID: $DEVICE_ID" + fi + + echo "Selected key layout: $LAYOUT_NAME" + ;; + *) + ;; + esac + fi +done \ No newline at end of file diff --git a/install_layout_select.sh b/install_layout_select.sh new file mode 100644 index 0000000..be8782a --- /dev/null +++ b/install_layout_select.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +source non_sudo_check.sh + +DEVICE_ID=$(cat /proc/bus/input/devices | grep ".*Touchpad\"$" | sort | cut -f 3 -d" " | cut -f 2 -d ":" | head -1) + +if [ -z "$LAYOUT_NAME" ]; then + echo + echo "Is recommended layout wrong please? Please create an issue (https://github.com/asus-linux-drivers/asus-numberpad-driver/issues)." + echo + echo "NumberPad layout" + echo + echo "Are predefined 2 variants of numberpad layouts for each laptop:" + echo " - Standard is recommended to use, the keys except percent and hash tag are send directly but layout is not resistant to overbinding these keys to something else and that is reason why exist second version" + echo " - Unicode send keys like unicode chars except backspace and enter using shortcut Ctrl+Shift+U+." + echo + echo "Select layout:" + echo + PS3="Please enter your choice " + OPTIONS=($(ls layouts) "Quit") + select SELECTED_OPT in "${OPTIONS[@]}"; do + if [ "$SELECTED_OPT" = "Quit" ]; then + exit 0 + fi + + for OPTION in $(ls layouts); do + if [ "$OPTION" = "$SELECTED_OPT" ]; then + LAYOUT_NAME=${SELECTED_OPT::-3} + break + fi + done + + if [ -z "$LAYOUT_NAME" ]; then + echo "invalid option $REPLY" + else + break + fi + done +fi + +echo + +SPECIFIC_BRIGHTNESS_VALUES="$LAYOUT_NAME-$DEVICE_ID" +if [ -f "layouts/$SPECIFIC_BRIGHTNESS_VALUES.py" ]; +then + LAYOUT_NAME=$SPECIFIC_BRIGHTNESS_VALUES + echo "Selected key layout specified by touchpad ID: $DEVICE_ID" +fi + +echo "Selected key layout: $LAYOUT_NAME" \ No newline at end of file diff --git a/install_logs.sh b/install_logs.sh new file mode 100644 index 0000000..1ce8fa2 --- /dev/null +++ b/install_logs.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +source non_sudo_check.sh + +# INHERIT +if [ -z "$LOGS_DIR_PATH" ]; then + LOGS_DIR_PATH="/var/log/asus-numberpad-driver" +fi + +sudo groupadd "numberpad" + +sudo usermod -a -G "numberpad" $USER + +if [[ $? != 0 ]]; then + echo "Something went wrong when adding the group numberpad to current user" + exit 1 +else + echo "Added group numberpad to current user" +fi + +sudo mkdir -p "$LOGS_DIR_PATH" +sudo chown -R :numberpad "$LOGS_DIR_PATH" +sudo chmod -R g+w "$LOGS_DIR_PATH" \ No newline at end of file diff --git a/install_service.sh b/install_service.sh new file mode 100644 index 0000000..429d676 --- /dev/null +++ b/install_service.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +source non_sudo_check.sh + +# INHERIT VARS +if [ -z "$CONFIG_FILE_DIR_PATH" ]; then + CONFIG_FILE_DIR_PATH="/usr/share/asus-numberpad-driver" +fi +if [ -z "$LAYOUT_NAME" ]; then + LAYOUT_NAME="up5401ea" +fi +if [ -z "$LOGS_DIR_PATH" ]; then + LOGS_DIR_PATH="/var/log/asus-numberpad-driver" +fi + +echo "Systemctl service" +echo + +read -r -p "Do you want install systemctl service? [y/N]" RESPONSE +case "$RESPONSE" in [yY][eE][sS]|[yY]) + + SERVICE_FILE_PATH=asus_numberpad_driver.service + SERVICE_X11_FILE_PATH=asus_numberpad_driver.x11.service + SERVICE_INSTALL_FILE_NAME="asus_numberpad_driver@.service" + SERVICE_INSTALL_DIR_PATH="/usr/lib/systemd/user" + + XDG_RUNTIME_DIR=$(echo $XDG_RUNTIME_DIR) + DBUS_SESSION_BUS_ADDRESS=$(echo $DBUS_SESSION_BUS_ADDRESS) + XAUTHORITY=$(echo $XAUTHORITY) + DISPLAY=$(echo $DISPLAY) + XDG_SESSION_TYPE=$(echo $XDG_SESSION_TYPE) + ERROR_LOG_FILE_PATH="$LOGS_DIR_PATH/error.log" + + echo + echo "LAYOUT_NAME: $LAYOUT_NAME" + echo "CONFIG_FILE_DIR_PATH: $CONFIG_FILE_DIR_PATH" + echo + echo "env var USER: $USER" + echo "env var DISPLAY: $DISPLAY" + echo "env var AUTHORITY: $XAUTHORITY" + echo "env var XDG_RUNTIME_DIR: $XDG_RUNTIME_DIR" + echo "env var DBUS_SESSION_BUS_ADDRESS: $DBUS_SESSION_BUS_ADDRESS" + echo "env var XDG_SESSION_TYPE: $XDG_SESSION_TYPE" + echo + echo "ERROR LOG FILE: $ERROR_LOG_FILE_PATH" + echo + + if [ "$XDG_SESSION_TYPE" = "x11" ]; then + cat "$SERVICE_X11_FILE_PATH" | USER=$USER LAYOUT_NAME=$LAYOUT_NAME 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 '$USER $LAYOUT_NAME $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 + elif [ "$XDG_SESSION_TYPE" = "wayland" ]; then + echo "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 "$SERVICE_FILE_PATH" | USER=$USER LAYOUT_NAME=$LAYOUT_NAME 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 '$USER $LAYOUT_NAME $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 + else + cat "$SERVICE_FILE_PATH" | USER=$USER LAYOUT_NAME=$LAYOUT_NAME 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 '$USER $LAYOUT_NAME $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 + + if [[ $? != 0 ]]; then + echo "Something went wrong when moving the asus_numberpad_driver.service" + exit 1 + else + echo "Asus numberpad driver service placed" + fi + + systemctl --user daemon-reload + + if [[ $? != 0 ]]; then + echo "Something went wrong when was called systemctl daemon reload" + exit 1 + else + echo "Systemctl daemon reloaded" + fi + + systemctl enable --user asus_numberpad_driver@$USER.service + + if [[ $? != 0 ]]; then + echo "Something went wrong when enabling the asus_numberpad_driver.service" + exit 1 + else + echo "Asus numberpad driver service enabled" + fi + + systemctl restart --user asus_numberpad_driver@$USER.service + if [[ $? != 0 ]]; then + echo "Something went wrong when starting the asus_numberpad_driver.service" + exit 1 + else + echo "Asus numberpad driver service started" + fi +esac \ No newline at end of file diff --git a/install_user_groups.sh b/install_user_groups.sh new file mode 100644 index 0000000..7ca8073 --- /dev/null +++ b/install_user_groups.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +source non_sudo_check.sh + +sudo groupadd "input" +sudo groupadd "i2c" +sudo groupadd "uinput" + +sudo usermod -a -G "i2c,input,uinput,numberpad" $USER + +if [[ $? != 0 ]]; then + echo "Something went wrong when adding the groups to current user" + exit 1 +else + echo "Added groups input, i2c, uinput, numberpad to current user" +fi + +echo 'KERNEL=="uinput", GROUP="uinput", MODE:="0660"' | sudo tee /etc/udev/rules.d/99-input.rules >/dev/null + +sudo udevadm control --reload-rules + +if [[ $? != 0 ]]; then + echo "Something went wrong when reloading udev rules" +fi \ No newline at end of file diff --git a/laptop_numpad_layouts b/laptop_numberpad_layouts similarity index 100% rename from laptop_numpad_layouts rename to laptop_numberpad_layouts diff --git a/numpad_layouts/b7402-unicode.py b/layouts/b7402-unicode.py similarity index 100% rename from numpad_layouts/b7402-unicode.py rename to layouts/b7402-unicode.py diff --git a/numpad_layouts/b7402.py b/layouts/b7402.py similarity index 100% rename from numpad_layouts/b7402.py rename to layouts/b7402.py diff --git a/numpad_layouts/e210ma-unicode.py b/layouts/e210ma-unicode.py similarity index 100% rename from numpad_layouts/e210ma-unicode.py rename to layouts/e210ma-unicode.py diff --git a/numpad_layouts/e210ma.py b/layouts/e210ma.py similarity index 100% rename from numpad_layouts/e210ma.py rename to layouts/e210ma.py diff --git a/numpad_layouts/g513-unicode.py b/layouts/g513-unicode.py similarity index 100% rename from numpad_layouts/g513-unicode.py rename to layouts/g513-unicode.py diff --git a/numpad_layouts/g513.py b/layouts/g513.py similarity index 100% rename from numpad_layouts/g513.py rename to layouts/g513.py diff --git a/numpad_layouts/g533-unicode.py b/layouts/g533-unicode.py similarity index 100% rename from numpad_layouts/g533-unicode.py rename to layouts/g533-unicode.py diff --git a/numpad_layouts/g533.py b/layouts/g533.py similarity index 100% rename from numpad_layouts/g533.py rename to layouts/g533.py diff --git a/numpad_layouts/gx551-unicode.py b/layouts/gx551-unicode.py similarity index 100% rename from numpad_layouts/gx551-unicode.py rename to layouts/gx551-unicode.py diff --git a/numpad_layouts/gx551.py b/layouts/gx551.py similarity index 100% rename from numpad_layouts/gx551.py rename to layouts/gx551.py diff --git a/numpad_layouts/gx701-unicode.py b/layouts/gx701-unicode.py similarity index 100% rename from numpad_layouts/gx701-unicode.py rename to layouts/gx701-unicode.py diff --git a/numpad_layouts/gx701.py b/layouts/gx701.py similarity index 100% rename from numpad_layouts/gx701.py rename to layouts/gx701.py diff --git a/numpad_layouts/up5401ea-3145.py b/layouts/up5401ea-3145.py similarity index 100% rename from numpad_layouts/up5401ea-3145.py rename to layouts/up5401ea-3145.py diff --git a/numpad_layouts/up5401ea-31B9.py b/layouts/up5401ea-31B9.py similarity index 100% rename from numpad_layouts/up5401ea-31B9.py rename to layouts/up5401ea-31B9.py diff --git a/numpad_layouts/up5401ea-unicode-3145.py b/layouts/up5401ea-unicode-3145.py similarity index 100% rename from numpad_layouts/up5401ea-unicode-3145.py rename to layouts/up5401ea-unicode-3145.py diff --git a/numpad_layouts/up5401ea-unicode-31B9.py b/layouts/up5401ea-unicode-31B9.py similarity index 100% rename from numpad_layouts/up5401ea-unicode-31B9.py rename to layouts/up5401ea-unicode-31B9.py diff --git a/numpad_layouts/up5401ea-unicode.py b/layouts/up5401ea-unicode.py similarity index 100% rename from numpad_layouts/up5401ea-unicode.py rename to layouts/up5401ea-unicode.py diff --git a/numpad_layouts/up5401ea.py b/layouts/up5401ea.py similarity index 100% rename from numpad_layouts/up5401ea.py rename to layouts/up5401ea.py diff --git a/numpad_layouts/ux433fa-unicode.py b/layouts/ux433fa-unicode.py similarity index 100% rename from numpad_layouts/ux433fa-unicode.py rename to layouts/ux433fa-unicode.py diff --git a/numpad_layouts/ux433fa.py b/layouts/ux433fa.py similarity index 100% rename from numpad_layouts/ux433fa.py rename to layouts/ux433fa.py diff --git a/numpad_layouts/ux581l-unicode.py b/layouts/ux581l-unicode.py similarity index 100% rename from numpad_layouts/ux581l-unicode.py rename to layouts/ux581l-unicode.py diff --git a/numpad_layouts/ux581l.py b/layouts/ux581l.py similarity index 100% rename from numpad_layouts/ux581l.py rename to layouts/ux581l.py diff --git a/non_sudo_check.sh b/non_sudo_check.sh new file mode 100644 index 0000000..a1d31b4 --- /dev/null +++ b/non_sudo_check.sh @@ -0,0 +1,5 @@ + +if [[ $(id -u) == 0 ]]; then + echo "Please run the install and uninstallation scripts as current user" + exit 1 +fi \ No newline at end of file diff --git a/asus_touchpad.py b/numberpad.py similarity index 99% rename from asus_touchpad.py rename to numberpad.py index 47dc180..04f0962 100755 --- a/asus_touchpad.py +++ b/numberpad.py @@ -22,13 +22,11 @@ numlock: bool = False -# Setup logging -# LOG=DEBUG sudo -E ./asus_touchpad.py "up5401ea" # all messages -# LOG=ERROR sudo -E ./asus_touchpad.py "up5401ea" # only error messages -logging.basicConfig() -log = logging.getLogger('asus-touchpad-numpad-driver') -log.setLevel(os.environ.get('LOG', 'INFO')) - +logging.basicConfig( + format='%(asctime)s %(levelname)-8s %(message)s', + level=os.environ.get('LOG', 'INFO') +) +log = logging.getLogger('asus-numberpad-driver') # Constants try_times = 5 @@ -48,9 +46,9 @@ if len(sys.argv) > 1: model = sys.argv[1] try: - model_layout = importlib.import_module('numpad_layouts.' + model) + model_layout = importlib.import_module('layouts.' + model) except: - log.error("Numpad layout *.py from dir numpad_layouts is required as first argument. Re-run install script or add missing first argument (valid value is b7402, e210ma, g533, gx551, gx701, up5401, ..).") + log.error("Numpad layout *.py from dir layouts is required as first argument. Re-run install script or add missing first argument (valid value is b7402, e210ma, g533, gx551, gx701, up5401ea, ..).") sys.exit(1) # Config file dir @@ -82,7 +80,7 @@ # Config -CONFIG_FILE_NAME = "asus_touchpad_numpad_dev" +CONFIG_FILE_NAME = "numberpad_dev" CONFIG_SECTION = "main" CONFIG_ENABLED = "enabled" CONFIG_ENABLED_DEFAULT = False diff --git a/remove_previous_implementation_of_service.sh b/remove_previous_implementation_of_service.sh deleted file mode 100644 index b191982..0000000 --- a/remove_previous_implementation_of_service.sh +++ /dev/null @@ -1,20 +0,0 @@ -# < for removing "old" variant of systemd service of this driver (when was not used user template with @) -echo "Attempt to stop, disable and remove service from previous implementation (without using user templates @)" -systemctl stop asus_touchpad_numpad.service -if [[ $? = 0 ]] -then - systemctl disable asus_touchpad_numpad.service - if [[ $? != 0 ]] - then - echo "asus_touchpad_numpad.service cannot be disabled correctly..." - exit 1 - else - rm -f /etc/systemd/system/asus_touchpad_numpad.service - if [[ $? != 0 ]] - then - echo "/etc/systemd/system/asus_touchpad_numpad.service cannot be removed correctly..." - exit 1 - fi - fi -fi -# /> \ No newline at end of file diff --git a/udev/90-numberpad-external-keyboard.rules b/udev/90-numberpad-external-keyboard.rules index dfe0461..7de24c3 100644 --- a/udev/90-numberpad-external-keyboard.rules +++ b/udev/90-numberpad-external-keyboard.rules @@ -1,2 +1,2 @@ -SUBSYSTEM=="usb", ACTION=="add", ATTRS{removable}=="removable", ATTRS{product}=="*[Kk]eyboard*", RUN+="/usr/share/asus_touchpad_numpad-driver/udev/external_keyboard_is_connected.sh" -SUBSYSTEM=="usb", ACTION=="remove", ATTRS{removable}=="removable", ATTRS{product}=="*[Kk]eyboard*", RUN+="/usr/share/asus_touchpad_numpad-driver/udev/external_keyboard_is_disconnected.sh" \ No newline at end of file +SUBSYSTEM=="usb", ACTION=="add", ATTRS{removable}=="removable", ATTRS{product}=="*[Kk]eyboard*", RUN+="$INSTALL_DIR_PATH/udev/external_keyboard_is_connected.sh" +SUBSYSTEM=="usb", ACTION=="remove", ATTRS{removable}=="removable", ATTRS{product}=="*[Kk]eyboard*", RUN+="$INSTALL_DIR_PATH/udev/external_keyboard_is_disconnected.sh" \ No newline at end of file diff --git a/udev/external_keyboard_is_connected.sh b/udev/external_keyboard_is_connected.sh index 1858153..e0f3667 100644 --- a/udev/external_keyboard_is_connected.sh +++ b/udev/external_keyboard_is_connected.sh @@ -1,4 +1,4 @@ #!/bin/bash -sed -i 's/numpad_disables_sys_numlock.*/numpad_disables_sys_numlock = 0/g' $CONFIG_FILE_DIR/asus_touchpad_numpad_dev -sed -i 's/sys_numlock_enables_numpad.*/sys_numlock_enables_numpad = 0/g' $CONFIG_FILE_DIR/asus_touchpad_numpad_dev \ No newline at end of file +sed -i 's/numpad_disables_sys_numlock.*/numpad_disables_sys_numlock = 0/g' $CONFIG_FILE_PATH +sed -i 's/sys_numlock_enables_numpad.*/sys_numlock_enables_numpad = 0/g' $CONFIG_FILE_PATH \ No newline at end of file diff --git a/udev/external_keyboard_is_disconnected.sh b/udev/external_keyboard_is_disconnected.sh index 46120e0..d6f2e66 100644 --- a/udev/external_keyboard_is_disconnected.sh +++ b/udev/external_keyboard_is_disconnected.sh @@ -1,4 +1,4 @@ #!/bin/bash -sed -i 's/sys_numlock_enables_numpad.*/sys_numlock_enables_numpad = 1/g' $CONFIG_FILE_DIR/asus_touchpad_numpad_dev -sed -i 's/numpad_disables_sys_numlock.*/numpad_disables_sys_numlock = 1/g' $CONFIG_FILE_DIR/asus_touchpad_numpad_dev \ No newline at end of file +sed -i 's/sys_numlock_enables_numpad.*/sys_numlock_enables_numpad = 1/g' $CONFIG_FILE_PATH +sed -i 's/numpad_disables_sys_numlock.*/numpad_disables_sys_numlock = 1/g' $CONFIG_FILE_PATH \ No newline at end of file diff --git a/uninstall.sh b/uninstall.sh index 24c051e..b96d34e 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,203 +1,129 @@ #!/bin/bash -if [[ $(id -u) != 0 ]] -then - echo "Please, run this script as root (using sudo for example)" - exit 1 -fi - -# for `rm` exclude !(xy) -shopt -s extglob - -logout_requested=false - -# "root" by default or when is used --user it is "current user" -RUN_UNDER_USER=$USER - -if [ "$1" = "--user" ] -then - RUN_UNDER_USER=$SUDO_USER -fi - -echo "Driver will be stopped and uninstalled for user" -echo $RUN_UNDER_USER - -source remove_previous_implementation_of_service.sh - -systemctl stop asus_touchpad_numpad@$RUN_UNDER_USER.service -if [[ $? != 0 ]] -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 - -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 - - -NUMPAD_LAYOUTS_DIR="/usr/share/asus_touchpad_numpad-driver/numpad_layouts/" - -NUMPAD_LAYOUTS_DIR_DIFF="" -if test -d "$NUMPAD_LAYOUTS_DIR" -then - NUMPAD_LAYOUTS_DIR_DIFF=$(diff --exclude __pycache__ numpad_layouts $NUMPAD_LAYOUTS_DIR) -fi - -if [ "$NUMPAD_LAYOUTS_DIR_DIFF" != "" ] -then - read -r -p "Installed numpad layouts contain modifications compared to the default ones. Do you want remove them [y/N]" response - case "$response" in [yY][eE][sS]|[yY]) - rm -rf "/usr/share/asus_touchpad_numpad-driver/"!(asus_touchpad_numpad_dev) - if [[ $? != 0 ]] - then - echo "/usr/share/asus_touchpad_numpad-driver/ cannot be removed correctly..." - fi - ;; - *) - rm -rf "/usr/share/asus_touchpad_numpad-driver/"!(numpad_layouts|asus_touchpad_numpad_dev) +source non_sudo_check.sh + +LOGS_DIR_PATH="/var/log/asus-numberpad-driver" + +# log output from every uninstalling attempt aswell +LOGS_UNINSTALL_LOG_FILE_NAME=uninstall-"$(date +"%d-%m-%Y-%H-%M-%S")".log +LOGS_UNINSTALL_LOG_FILE_PATH="$LOGS_DIR_PATH/$LOGS_UNINSTALL_LOG_FILE_NAME" +touch "$LOGS_UNINSTALL_LOG_FILE_PATH" + +{ + # for `rm` exclude !(xy) + shopt -s extglob + + INSTALL_DIR_PATH="/usr/share/asus-numberpad-driver" + CONFIG_FILE_DIR_PATH="$INSTALL_DIR_PATH" + CONFIG_FILE_NAME="numberpad_dev" + CONFIG_FILE_PATH="$CONFIG_FILE_DIR_PATH/$CONFIG_FILE_NAME" + + NUMPAD_LAYOUTS_DIR="$INSTALL_DIR_PATH/numpad_layouts/" + + NUMPAD_LAYOUTS_DIR_DIFF="" + if test -d "$NUMPAD_LAYOUTS_DIR" + then + NUMPAD_LAYOUTS_DIR_DIFF=$(diff --exclude __pycache__ numpad_layouts $NUMPAD_LAYOUTS_DIR) + fi + + if [ "$NUMPAD_LAYOUTS_DIR_DIFF" != "" ] + then + read -r -p "Installed numpad layouts contain modifications compared to the default ones. Do you want remove them [y/N]" response + case "$response" in [yY][eE][sS]|[yY]) + rm -rf "$INSTALL_DIR_PATH/!($CONFIG_FILE_NAME)" + if [[ $? != 0 ]] + then + echo "Something went wrong when removing files from the $INSTALL_DIR_PATH" + fi + ;; + *) + rm -rf "$INSTALL_DIR_PATH/!(numpad_layouts|$CONFIG_FILE_NAME)" + if [[ $? != 0 ]] + then + echo "Something went wrong when removing files from the $INSTALL_DIR_PATH" + fi + + echo + echo "Numpad layouts in $INSTALL_DIR_PATH/numpad_layouts have not been removed and remain in system:" + ls /$INSTALL_DIR_PATH/numpad_layouts + ;; + esac + else + rm -rf "$INSTALL_DIR_PATH/!($CONFIG_FILE_NAME)" if [[ $? != 0 ]] then - echo "/usr/share/asus_touchpad_numpad-driver/ cannot be removed correctly..." + echo "Something went wrong when removing files from the $INSTALL_DIR_PATH" fi - echo "Numpad layouts in /usr/share/asus_touchpad_numpad-driver/conf/ have not been removed and remain in system:" - ls /usr/share/asus_touchpad_numpad-driver/numpad_layouts - ;; - esac -else - rm -rf "/usr/share/asus_touchpad_numpad-driver/"!(asus_touchpad_numpad_dev) - if [[ $? != 0 ]] - then - echo "/usr/share/asus_touchpad_numpad-driver/ cannot be removed correctly..." fi -fi - -CONF_FILE="/usr/share/asus_touchpad_numpad-driver/asus_touchpad_numpad_dev" -CONFIG_FILE_DIFF="" -if test -f "$CONF_FILE" -then - CONFIG_FILE_DIFF=$(diff <(grep -v '^#' asus_touchpad_numpad_dev) <(grep -v '^#' $CONF_FILE)) -fi - -if [ "$CONFIG_FILE_DIFF" != "" ] -then - read -r -p "Config file contains modifications compared to the default one. Do you want remove config file [y/N]" response - case "$response" in [yY][eE][sS]|[yY]) + if [[ -f "$CONF_FILE" ]]; then + + read -r -p "Do you want remove config file [y/N]" RESPONSE + case "$RESPONSE" in [yY][eE][sS]|[yY]) + + if test -d "$NUMPAD_LAYOUTS_DIR" + then + rm -f "$CONFIG_FILE_PATH" + else + rm -rf "$INSTALL_DIR_PATH" + fi + + if [[ $? != 0 ]] + then + echo "Something went wrong when removing files from the $INSTALL_DIR_PATH" + fi + ;; + *) + echo "Config file have not been removed and remain in system:" + echo "$CONFIG_FILE_PATH" + ;; + esac + else if test -d "$NUMPAD_LAYOUTS_DIR" then - rm -f /usr/share/asus_touchpad_numpad-driver/asus_touchpad_numpad_dev + rm -f $CONFIG_FILE_PATH else - rm -rf /usr/share/asus_touchpad_numpad-driver + rm -rf $INSTALL_DIR_PATH fi if [[ $? != 0 ]] then - echo "/usr/share/asus_touchpad_numpad-driver/asus_touchpad_numpad_dev cannot be removed correctly..." + echo "Something went wrong when removing files from the $INSTALL_DIR_PATH" fi - ;; - *) - echo "Config file have not been removed and remain in system:" - echo "/usr/share/asus_touchpad_numpad-driver/asus_touchpad_numpad_dev" - ;; - esac -else - - if test -d "$NUMPAD_LAYOUTS_DIR" - then - rm -f /usr/share/asus_touchpad_numpad-driver/asus_touchpad_numpad_dev - else - rm -rf /usr/share/asus_touchpad_numpad-driver fi - if [[ $? != 0 ]] - then - echo "/usr/share/asus_touchpad_numpad-driver/asus_touchpad_numpad_dev cannot be removed correctly..." - fi -fi - -rm -rf /var/log/asus_touchpad_numpad-driver -if [[ $? != 0 ]] -then - echo "/var/log/asus_touchpad_numpad-driver cannot be removed correctly..." -fi - -rm -f /usr/lib/udev/rules.d/90-numberpad-external-keyboard.rules -if [[ $? != 0 ]] -then - echo "/usr/lib/udev/rules.d/90-numberpad-external-keyboard.rules cannot be removed correctly..." -fi - -systemctl daemon-reload - -if [[ $? != 0 ]]; then - echo "Something went wrong when was called systemctl daemon reload" -else - echo "Systemctl daemon realod called succesfully" -fi - -# remove shortcuts for toggling calculator added by driver - -existing_shortcut_string=$(runuser -u $SUDO_USER gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings) -#echo $existing_shortcut_string - -filtered_existing_shortcut_string="[" -filtered_existing_shortcut_count=0 - -if [[ "$existing_shortcut_string" != "@as []" ]]; then - IFS=', ' read -ra existing_shortcut_array <<< "$existing_shortcut_string" - for shortcut_index in "${!existing_shortcut_array[@]}"; do - shortcut="${existing_shortcut_array[$shortcut_index]}" - shortcut_index=$( echo $shortcut | cut -d/ -f 8 | sed 's/[^0-9]//g') - - command=$(runuser -u $SUDO_USER gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/ 'command') - #echo $command - if [[ "$command" = "'bash /usr/share/asus_touchpad_numpad-driver/scripts/calculator_toggle.sh'" ]]; then - ((filtered_existing_shortcut_count=filtered_existing_shortcut_count+1)) - echo "Removed shortcut added by installation of this driver for toggling calculator" - runuser -u $SUDO_USER gsettings reset-recursively org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/ - else - #echo "Found something else on index $shortcut_index" - if [[ "$filtered_existing_shortcut_string" != "[" ]]; then - filtered_existing_shortcut_string="$filtered_existing_shortcut_string"", '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/'" - else - filtered_existing_shortcut_string="$filtered_existing_shortcut_string""'/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/'" - fi - fi - done + echo "Asus numberpad driver removed" - filtered_existing_shortcut_string="$filtered_existing_shortcut_string"']' - #echo $filtered_existing_shortcut_string - #echo $filtered_existing_shortcut_count + echo - if [[ $filtered_existing_shortcut_count != 0 ]]; then - runuser -u $SUDO_USER gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "${filtered_existing_shortcut_string}" - logout_requested=true - fi -fi + source uninstall_user_groups.sh + + echo + + source uninstall_external_keyboard_toggle.sh + + echo + + source uninstall_calc_toggle.sh + + echo + + source uninstall_service.sh + + echo -if [[ "$logout_requested" = true ]] -then + echo "Uninstallation finished succesfully" - echo "Uninstall process requested to succesfull finish atleast log out or reboot" - echo "Without that reverted changes might not be done" + echo - read -r -p "Do you want reboot now? [y/N]" response - case "$response" in [yY][eE][sS]|[yY]) + read -r -p "Reboot is required. Do you want reboot now? [y/N]" RESPONSE + case "$RESPONSE" in [yY][eE][sS]|[yY]) reboot ;; *) ;; esac -fi -echo "Uninstall finished" -exit 0 \ No newline at end of file + exit 0 +} 2>&1 | sudo tee "$LOGS_UNINSTALL_LOG_FILE_PATH" \ No newline at end of file diff --git a/uninstall_calc_toggle.sh b/uninstall_calc_toggle.sh new file mode 100644 index 0000000..4a40171 --- /dev/null +++ b/uninstall_calc_toggle.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +source non_sudo_check.sh + +# INHERIT VARS +# +# None + +existing_shortcut_string=$(gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings) + +filtered_existing_shortcut_string="[" +filtered_existing_shortcut_count=0 + +if [[ "$existing_shortcut_string" != "@as []" ]]; then + IFS=', ' read -ra existing_shortcut_array <<< "$existing_shortcut_string" + for shortcut_index in "${!existing_shortcut_array[@]}"; do + shortcut="${existing_shortcut_array[$shortcut_index]}" + shortcut_index=$( echo $shortcut | cut -d/ -f 8 | sed 's/[^0-9]//g') + + command=$(gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/ 'command') + if [[ "$command" = "'bash /usr/share/asus_touchpad_numpad-driver/scripts/calculator_toggle.sh'" ]]; then + ((filtered_existing_shortcut_count=filtered_existing_shortcut_count+1)) + echo "Removed shortcut added by installation of this driver for toggling calculator" + gsettings reset-recursively org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/ + else + if [[ "$filtered_existing_shortcut_string" != "[" ]]; then + filtered_existing_shortcut_string="$filtered_existing_shortcut_string"", '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/'" + else + filtered_existing_shortcut_string="$filtered_existing_shortcut_string""'/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$shortcut_index/'" + fi + fi + done + + filtered_existing_shortcut_string="$filtered_existing_shortcut_string"']' + + if [[ $filtered_existing_shortcut_count != 0 ]]; then + gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "${filtered_existing_shortcut_string}" + fi +fi \ No newline at end of file diff --git a/uninstall_external_keyboard_toggle.sh b/uninstall_external_keyboard_toggle.sh new file mode 100644 index 0000000..b49bf10 --- /dev/null +++ b/uninstall_external_keyboard_toggle.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +source non_sudo_check.sh + +# INHERIT VARS +INSTALL_DIR_PATH="/usr/share/asus-numberpad-driver" + +sudo rm -f "$INSTALL_DIR_PATH/udev/external_keyboard_is_connected.sh" +sudo rm -f "$INSTALL_DIR_PATH/udev/external_keyboard_is_disconnected.sh" + +sudo rm -f /usr/lib/udev/rules.d/90-numberpad-external-keyboard.rules +if [[ $? != 0 ]] +then + echo "/usr/lib/udev/rules.d/90-numberpad-external-keyboard.rules cannot be removed" +else + echo "Rule 90-numberpad-external-keyboard.rules removed" +fi \ No newline at end of file diff --git a/uninstall_service.sh b/uninstall_service.sh new file mode 100644 index 0000000..7b53406 --- /dev/null +++ b/uninstall_service.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +source non_sudo_check.sh + +SERVICE_INSTALL_FILE_NAME="asus_numberpad_driver@.service" +SERVICE_INSTANCE_FILE_NAME="asus_numberpad_driver@$USER.service" + +systemctl --user stop "$SERVICE_INSTANCE_FILE_NAME" +if [[ $? != 0 ]] +then + echo "Something went wrong when stopping the $SERVICE_INSTANCE_FILE_NAME" +else + echo "Asus numberpad driver service $SERVICE_INSTANCE_FILE_NAME stopped" +fi + +systemctl --user disable "$SERVICE_INSTANCE_FILE_NAME" +if [[ $? != 0 ]] +then + echo "Something went wrong when disabling the $SERVICE_INSTANCE_FILE_NAME" +else + echo "Asus numberpad driver service $SERVICE_INSTANCE_FILE_NAME disabled" +fi + +sudo rm -f "/usr/lib/systemd/user/$SERVICE_INSTALL_FILE_NAME" +if [[ $? != 0 ]] +then + echo "Something went wrong when removing the $SERVICE_INSTALL_FILE_NAME" +else + echo "Asus numberpad driver service removed" +fi + +systemctl --user daemon-reload + +if [[ $? != 0 ]]; then + echo "Something went wrong when was called systemctl daemon reload" +else + echo "Systemctl daemon reloaded" +fi \ No newline at end of file diff --git a/uninstall_user_groups.sh b/uninstall_user_groups.sh new file mode 100644 index 0000000..d895d36 --- /dev/null +++ b/uninstall_user_groups.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +source non_sudo_check.sh + +sudo rm -f /etc/udev/rules.d/99-input.rules + +if [[ $? != 0 ]]; then + echo "Something went wrong when removing the input udev rule" + exit 1 +fi + +sudo udevadm control --reload-rules + +if [[ $? != 0 ]]; then + echo "Something went wrong when reloading udev rules" + exit 1 +else + echo "Udev rules reloaded" +fi \ No newline at end of file