From c1e2db9a2e76b91288e4cd638b3f114c136380e0 Mon Sep 17 00:00:00 2001 From: Ben Reaves Date: Tue, 21 Apr 2020 17:39:20 -0500 Subject: [PATCH] - Updated xkeysnail installer to properly copy desktop autostart and to restart service on config file changes --- system-config/unipkg.sh | 21 +++++++++++++++++++++ xkeysnail-config/xkeysnail.desktop | 8 ++++++++ xkeysnail-config/xkeysnail.service | 2 +- xkeysnail-config/xkeystart.sh | 8 ++++++++ xkeysnail_service.sh | 17 +++++++++++------ 5 files changed, 49 insertions(+), 7 deletions(-) create mode 100755 system-config/unipkg.sh create mode 100644 xkeysnail-config/xkeysnail.desktop create mode 100755 xkeysnail-config/xkeystart.sh diff --git a/system-config/unipkg.sh b/system-config/unipkg.sh new file mode 100755 index 0000000..fe69aa8 --- /dev/null +++ b/system-config/unipkg.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +if pkgmgr="$( which apt-get )" 2> /dev/null; then + echo "Debian" + $pkgmgr update + $pkgmgr install "$1" +elif pkgmgr="$( which dnf )" 2> /dev/null; then + echo "dnf" + $pkgmgr check-update; $pkgmgr install -y "$1" +elif pkgmgr="$( which pacman )" 2> /dev/null; then + echo "Arch-based" + $pkgmgr -Syy; $pkgmr -S "$1" +else + echo "Package manager not found, please install $1" >&2 + exit 1 +fi +if [[ 1 -ne $# ]]; then + echo "Syntax: $0 PACKAGE" + exit 1 +fi +exit $? \ No newline at end of file diff --git a/xkeysnail-config/xkeysnail.desktop b/xkeysnail-config/xkeysnail.desktop new file mode 100644 index 0000000..46a6b31 --- /dev/null +++ b/xkeysnail-config/xkeysnail.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=Kinto_xkey +GenericName=Kinto_xkey +Comment=Make Linux Type Like it's a Mac +Exec=/usr/bin/xhost +SI:localuser:root +Terminal=false +Type=Application +X-GNOME-Autostart-enabled=true \ No newline at end of file diff --git a/xkeysnail-config/xkeysnail.service b/xkeysnail-config/xkeysnail.service index b152d81..53fbbea 100644 --- a/xkeysnail-config/xkeysnail.service +++ b/xkeysnail-config/xkeysnail.service @@ -5,7 +5,7 @@ Description=xkeysnail Type=simple KillMode=process ExecStartPre=/sbin/runuser -l {username} -c /home/{username}/.config/kinto/prexk.sh -ExecStart=/usr/bin/sudo /usr/local/bin/xkeysnail --quiet --watch /home/{username}/.config/kinto/kinto.py +ExecStart=/usr/bin/sudo /bin/bash -c '/home/{username}/.config/kinto/xkeystart.sh "/home/{username}/.config/kinto/kinto.py"' ExecStop=/usr/bin/sudo /usr/bin/killall xkeysnail Restart=on-failure RestartSec=3 diff --git a/xkeysnail-config/xkeystart.sh b/xkeysnail-config/xkeystart.sh new file mode 100755 index 0000000..7a64e39 --- /dev/null +++ b/xkeysnail-config/xkeystart.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# >/dev/null 2>&1 +/usr/local/bin/xkeysnail --quiet --watch "$1" & +while true + do inotifywait -e close_write,moved_to,create -q "$1" + /usr/bin/killall xkeysnail + /usr/local/bin/xkeysnail --quiet --watch "$1" & +done \ No newline at end of file diff --git a/xkeysnail_service.sh b/xkeysnail_service.sh index 3f7f9ae..58704c5 100755 --- a/xkeysnail_service.sh +++ b/xkeysnail_service.sh @@ -15,6 +15,10 @@ if [ $# -eq 0 ]; then fi if [[ $1 == "1" || $1 == "2" || $1 == "3" || $1 == "winmac" || $1 == "mac" || $1 == "chromebook" ]]; then + if ! [ -x "$(command -v inotifywait)" ]; then + echo "Will need to install inotify-tools to restart key remapper live for config file changes..." + sudo ./system-config/unipkg.sh inotify-tools + fi # echo "Transferring files..." mkdir -p ~/.config/kinto @@ -23,9 +27,13 @@ if [[ $1 == "1" || $1 == "2" || $1 == "3" || $1 == "winmac" || $1 == "mac" || $1 echo -e '#!/bin/sh\rxhost +SI:localuser:root' > ~/.kde/Autostart/kintohost.sh chmod +x ~/.kde/Autostart/kintohost.sh - cp ./xkeysnail-config/kinto.py ./xkeysnail-config/kinto.py.new - cp ./xkeysnail-config/prexk.sh ~/.config/kinto/prexk.sh - cp ./xkeysnail-config/xkeysnail.service ./xkeysnail-config/xkeysnail.service.new + # KDE startup - xhost fix + yes | cp -rf ./xkeysnail-config/xkeysnail.desktop ~/.config/autostart/xkeysnail.desktop + + yes | cp -rf ./xkeysnail-config/xkeystart.sh ~/.config/kinto/xkeystart.sh + yes | cp -rf ./xkeysnail-config/kinto.py ./xkeysnail-config/kinto.py.new + yes | cp -rf ./xkeysnail-config/prexk.sh ~/.config/kinto/prexk.sh + yes | cp -rf ./xkeysnail-config/xkeysnail.service ./xkeysnail-config/xkeysnail.service.new sed -i "s/{username}/`whoami`/g" ./xkeysnail-config/xkeysnail.service.new sed -i "s/{displayid}/`echo "$DISPLAY"`/g" ./xkeysnail-config/xkeysnail.service.new else @@ -55,9 +63,6 @@ if [[ $1 == "1" || $1 == "2" || $1 == "3" || $1 == "winmac" || $1 == "mac" || $1 echo "Adding xhost fix..." - # KDE startup - xhost fix - cp ./xkeysnail-config/xkeysnail.desktop ~/.config/autostart/xkeysnail.desktop - LINE='xhost +SI:localuser:root' if [ ! -e "~/.xprofile" ]; then