From 44f84f40f73b2837928c0a2b7da5e96c5509a662 Mon Sep 17 00:00:00 2001 From: frostwong Date: Fri, 6 Dec 2024 00:09:29 +0800 Subject: [PATCH] more friendly notification --- README.md | 2 +- install.sh | 58 ++++++++++++++++++++++++++++++++---------------------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 7e987cc..a48e8a9 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This keyboard remap is based on the [Xremap](https://github.com/k0kubun/xremap) ![Gnome macOS Remap Icon](./resources/gnome-macos-remap-wayland-dark.png#gh-dark-mode-only) ## How does it work? -Script doenloads the latest version of the `xremap` remapper for your architecture. Configuration file `config.yml` contains majority of the remapping instructions. On top of that the default GNOME shell and Mutter keybindings are modified. A systemd service is created and enabled for a particular user. Therefore after the install other users on the system will not be affected by the remap. +Script downloads the latest version of the `xremap` remapper for your architecture. Configuration file `config.yml` contains majority of the remapping instructions. On top of that the default GNOME shell and Mutter keybindings are modified. A systemd service is created and enabled for a particular user. Therefore after the install other users on the system will not be affected by the remap. ## Prerequisities * Install Git and GNOME extensions `sudo install git gnome-shell-extensions`. diff --git a/install.sh b/install.sh index af0aca9..8257212 100755 --- a/install.sh +++ b/install.sh @@ -30,27 +30,31 @@ else exit 1 fi -# Download latest release from GitHub -wget https://github.com/xremap/xremap/releases/latest/download/$ARCHIVE_NAME - -# Extract the archive -echo "INFO: Extracting the archive..." -if ! command -v unzip &> /dev/null; then - echo "ERROR: Command \"unzip\" not found." - exit 0 -fi -unzip -o ./xremap-linux-${ARCH}-*.zip - -# Remove old binary (if any) -if command -v gnome-terminal &> /dev/null ; then - echo "INFO: Removing old binary..." - sudo rm -rf /usr/local/bin/xremap +if which xremap > /dev/null 2>&1; then + echo "INFO: xremap is already installed. Skipping... +else + # Download latest release from GitHub + wget https://github.com/xremap/xremap/releases/latest/download/$ARCHIVE_NAME + + # Extract the archive + echo "INFO: Extracting the archive..." + if ! command -v unzip &> /dev/null; then + echo "ERROR: Command \"unzip\" not found." + exit 0 + fi + unzip -o ./xremap-linux-${ARCH}-*.zip + + # Remove old binary (if any) + if command -v gnome-terminal &> /dev/null ; then + echo "INFO: Removing old binary..." + sudo rm -rf /usr/local/bin/xremap + fi + + # Install new binary (if any) + echo "INFO: Installing the binary..." + sudo cp ./xremap /usr/local/bin fi -# Install new binary (if any) -echo "INFO: Installing the binary..." -sudo cp ./xremap /usr/local/bin - # Tweaking server access control for X11 # https://github.com/k0kubun/xremap#x11 if [ "${XDG_SESSION_TYPE}" == "x11" ]; then @@ -156,12 +160,18 @@ gsettings set org.gnome.settings-daemon.plugins.media-keys screensaver "[]" # Download and enable Xremap GNOME extension (for Wayland only) +systemctl --user status gnome-macos-remap if [ "${XDG_SESSION_TYPE}" == "wayland" ]; then - RED=`tput setaf 1` - RESET=`tput sgr0` - echo "INFO: ${RED}Action Required${RESET}. Install the xremap extension and restart your PC." - echo " https://extensions.gnome.org/extension/5060/xremap/" + # Check if xremap extension is enabled + if gnome-extensions list | grep -q "xremap@k0kubun.com"; then + echo "INFO: The xremap extension is already enabled." + else + RED=`tput setaf 1` + RESET=`tput sgr0` + echo "INFO: ${RED}Action Required${RESET}. Install the xremap extension and restart your PC." + echo " https://extensions.gnome.org/extension/5060/xremap/" + fi else gnome-extensions disable xremap@k0kubun.com echo "INFO: Please restart your computer." -fi +fi \ No newline at end of file