From c1914511eeb614bd3d8bc1c1478b3807711c75f4 Mon Sep 17 00:00:00 2001 From: phil Date: Sun, 16 Jul 2023 12:17:59 +0200 Subject: [PATCH 1/6] Add install script Add Minibook configuration Re-Add scripts --- install.sh | 27 +++++++++++++++++++++++++++ laptop-mode.service | 2 +- setsysmode | 8 ++++++++ sysmoded | 8 ++++++++ tablet-mode.desktop | 2 +- tablet-mode.json | 7 +++++++ tablet-mode.service | 2 +- 7 files changed, 53 insertions(+), 3 deletions(-) create mode 100755 install.sh create mode 100644 setsysmode create mode 100644 sysmoded create mode 100644 tablet-mode.json diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..66dc675 --- /dev/null +++ b/install.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +echo "Add tablet group..." +/usr/sbin/groupadd tablet + +read -p "Enter your local username: " user + +echo "Add user to group..." +usermod -a -G tablet "$user" + +echo "Copy files..." +cp -r tabletmode/ /usr/local/lib/python3.11/dist-packages +cp tablet-mode.service /etc/systemd/system +cp laptop-mode.service /etc/systemd/system +cp tablet-mode.json /etc/ +cp tablet-mode.desktop /home/"$user"/.local/applications +cp tablet-mode.sudoers /etc/sudoers.d/tablet-mode +cp setsysmode /usr/local/bin +chmod +x /usr/local/bin/setsysmode +cp sysmoded /usr/local/bin +chmod +x /usr/local/bin/sysmoded + +echo "Reload systemd..." +systemctl daemon-reload + +echo "Install packages..." +apt install evtest -y diff --git a/laptop-mode.service b/laptop-mode.service index 7f9bd26..93e4f27 100644 --- a/laptop-mode.service +++ b/laptop-mode.service @@ -3,7 +3,7 @@ Description=Configure system for laptop mode Conflicts=tablet-mode.service [Service] -ExecStart=/usr/bin/sysmoded laptop +ExecStart=/usr/local/bin/sysmoded laptop StandardOutput=null [Install] diff --git a/setsysmode b/setsysmode new file mode 100644 index 0000000..fb31d1f --- /dev/null +++ b/setsysmode @@ -0,0 +1,8 @@ +#! /usr/bin/env python3 +"""Sets the system mode.""" + +from tabletmode.cli import main + + +if __name__ == '__main__': + main() diff --git a/sysmoded b/sysmoded new file mode 100644 index 0000000..347aca9 --- /dev/null +++ b/sysmoded @@ -0,0 +1,8 @@ +#! /usr/bin/env python3 +"""System mode daemon.""" + +from tabletmode.daemon import main + + +if __name__ == '__main__': + main() diff --git a/tablet-mode.desktop b/tablet-mode.desktop index b077626..2c3a375 100644 --- a/tablet-mode.desktop +++ b/tablet-mode.desktop @@ -2,6 +2,6 @@ Comment=Toggle tablet mode Terminal=false Name=Tablet Mode -Exec=/usr/bin/setsysmode toggle +Exec=/usr/local/bin/setsysmode toggle Type=Application Icon=pda-symbolic diff --git a/tablet-mode.json b/tablet-mode.json new file mode 100644 index 0000000..14f657e --- /dev/null +++ b/tablet-mode.json @@ -0,0 +1,7 @@ +{ + "tablet": [ + "/dev/input/by-path/platform-i8042-serio-0-event-kbd", + "/dev/input/by-path/pci-0000:00:14.0-usb-0:9:1.0-event-mouse" + ], + "notify": false +} diff --git a/tablet-mode.service b/tablet-mode.service index 5ca2d1d..fc893e7 100644 --- a/tablet-mode.service +++ b/tablet-mode.service @@ -3,7 +3,7 @@ Description=Configure system for tablet mode Conflicts=laptop-mode.service [Service] -ExecStart=/usr/bin/sysmoded tablet +ExecStart=/usr/local/bin/sysmoded tablet StandardOutput=null [Install] From 8b0a4c954c86bce5af43844d35c32357e78bfbfc Mon Sep 17 00:00:00 2001 From: phil Date: Sun, 16 Jul 2023 12:21:58 +0200 Subject: [PATCH 2/6] Update README --- README.md | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 4afdc40..cdc0bc5 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,11 @@ -# tablet-mode +# Chuwi Minibook tablet mode switch -Allow users to toggle a convertible laptop between laptop and tablet mode. +Allow users to toggle a Chuwi Minibook laptop between laptop and tablet mode. -## Configuration +## Installation -The devices to be deactivated in either *tablet* or *laptop* mode must be specified in `/etc/tablet-mode.json`. -You can specify whether desktop notifications shall be send when changing the mode using the `notify` flag. -If specified, you can override `sudo` to provide another program that accepts commands to be run as root without a password -by the current user to elevate privileges, such as *doas*. - -```json -{ - "tablet": [ - "/dev/input/by-path/platform-i8042-serio-0-event-kbd", - "/dev/input/by-path/platform-i8042-serio-1-event-mouse" - ], - "notify": false, - "sudo": "/usr/bin/doas" -} -``` +Just run `install.sh` and enter the name of you local user account. ## Usage -You must be a member of the group `tablet` to toggle between tablet and laptop mode. You can toggle between tablet and laptop mode by running `setsysmode toggle` or use the desktop icon provided with this package. From 902e5bebe4a68a79d708f7af74b7e9dd2ab1909b Mon Sep 17 00:00:00 2001 From: phil Date: Sun, 16 Jul 2023 12:23:18 +0200 Subject: [PATCH 3/6] Hint about OS --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cdc0bc5..a3bbed6 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Allow users to toggle a Chuwi Minibook laptop between laptop and tablet mode. ## Installation -Just run `install.sh` and enter the name of you local user account. +Just run `install.sh` on you Debian system and enter the name of you local user account. ## Usage From 45b5790e79f7f79ed69471b60322d7534b2a78e1 Mon Sep 17 00:00:00 2001 From: phil Date: Sun, 16 Jul 2023 12:29:02 +0200 Subject: [PATCH 4/6] Add hint about reboot --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a3bbed6..5cbe1cd 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ Allow users to toggle a Chuwi Minibook laptop between laptop and tablet mode. ## Installation -Just run `install.sh` on you Debian system and enter the name of you local user account. +Just run `install.sh` on your Debian system and enter the name of you local user account. +Reboot after successful installation. ## Usage From 5a8657d7ca681e14a6fd8682bd6fd8369ed28ada Mon Sep 17 00:00:00 2001 From: phil Date: Sun, 16 Jul 2023 12:31:00 +0200 Subject: [PATCH 5/6] Add link to upstream repo --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5cbe1cd..db11fd8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Chuwi Minibook tablet mode switch Allow users to toggle a Chuwi Minibook laptop between laptop and tablet mode. +This is based on https://github.com/conqp/tablet-mode. ## Installation From 5488f154e1e047c1f74d736d09df8e871a8b9fd6 Mon Sep 17 00:00:00 2001 From: phil Date: Sun, 16 Jul 2023 13:03:10 +0200 Subject: [PATCH 6/6] Only add group and user if they don't exist --- install.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 66dc675..990b345 100755 --- a/install.sh +++ b/install.sh @@ -1,12 +1,20 @@ #!/usr/bin/env bash -echo "Add tablet group..." -/usr/sbin/groupadd tablet +set -eu + +GROUP=tablet + +if ! [ $(getent group "$GROUP") ]; then + echo "Add tablet group..." + /usr/sbin/groupadd tablet +fi read -p "Enter your local username: " user -echo "Add user to group..." -usermod -a -G tablet "$user" +if ! [ $(groupmems -g "$GROUP" -l | grep "$user" ) ]; then + echo "Add user to group..." + usermod -a -G tablet "$user" +fi echo "Copy files..." cp -r tabletmode/ /usr/local/lib/python3.11/dist-packages