diff --git a/Cargo.lock b/Cargo.lock index ed62c3c..9979532 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,7 +19,7 @@ checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] name = "andthe" -version = "0.1.0" +version = "0.1.1" dependencies = [ "serde", "serde_json", @@ -54,7 +54,7 @@ checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bluebird" -version = "0.1.0" +version = "0.1.1" dependencies = [ "andthe", "dirs", @@ -173,7 +173,7 @@ dependencies = [ [[package]] name = "liz" -version = "0.1.0" +version = "0.1.1" dependencies = [ "andthe", "serde", diff --git a/README.md b/README.md index de7ee8d..b599f25 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,18 @@ The project name is inspired by a great animation named "Liz and the Blue bird". ## Installation +### Download from [Release](https://github.com/philia897/liz-shortcut-helper/releases) + +Download the tar.gz package, and run the install.sh to install and auto configure everything. + +``` +tar -xzf [package_name.tar.gz] + +cd [package_name] + +./install.sh +``` + ### Building from source Fist please make sure `rustc` and `cargo` already installed for building this project. For Arch user, you can use `sudo pacman -Sy rust` to install both. @@ -37,6 +49,8 @@ rm -rf release/ release.tar.gz ``` +> If you have problems with ydotool (can not start the service, socket file permission wrong, etc): [read this](./doc/ydotool/README.md) + ## How to use ```bash diff --git a/andthe/Cargo.toml b/andthe/Cargo.toml index 7c8afb1..00d493b 100644 --- a/andthe/Cargo.toml +++ b/andthe/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "andthe" -version = "0.1.0" +version = "0.1.1" edition = "2021" authors = ["Felix Wang "] description = "Defines the communication protocol between Liz and Bluebird for liz-shortcut-helper" diff --git a/bluebird/Cargo.toml b/bluebird/Cargo.toml index 3f281f6..69756db 100644 --- a/bluebird/Cargo.toml +++ b/bluebird/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bluebird" -version = "0.1.0" +version = "0.1.1" edition = "2021" authors = ["Felix Wang "] description = "The daemon hearing, executing and responding to the commends from Liz for liz-shortcut-helper" diff --git a/data/music_sheet.lock b/data/music_sheet.lock index 4eaa103..b8fe50c 100644 --- a/data/music_sheet.lock +++ b/data/music_sheet.lock @@ -1 +1 @@ -[{"hit_number":7,"comment":"Clear the command prompt typed","keycode":"29.1 22.1 22.0 29.0","formatted":"Clear command prompt | Terminal | ctrl+u"},{"hit_number":6,"comment":"","keycode":"126.1 109.1 109.0 126.0","formatted":"Minimize Window | KWin | meta+pagedown"},{"hit_number":5,"comment":"Welcom message","keycode":"+ Hello World!","formatted":"Hello world | Welcome | (str)+ Hello World!"},{"hit_number":2,"comment":"Test to run shortcut 'ctrl+shift+c', the copy command in Zsh","keycode":"29.1 42.1 46.1 46.0 42.0 29.0","formatted":"Test: ctrl+shift+c | Example | ctrl+shift+c"},{"hit_number":2,"comment":"Test to run shortcut 'esc :set nu', set number in vim/nvim","keycode":"1.1 1.0 + :set 57.1 57.0 + nu","formatted":"Test: esc :set nu | Example | esc :set space nu"},{"hit_number":2,"comment":"Welcom message","keycode":"+ liz and the blue bird","formatted":"Welcome | Welcome | (str)+ liz and the blue bird"},{"hit_number":1,"comment":"","keycode":"126.1 104.1 104.0 126.0","formatted":"Maximize Window | KWin | meta+pageup"},{"hit_number":1,"comment":"Test to run shortcut 'esc :set nu', using (str) to type string instead","keycode":"1.1 1.0 + :set nu","formatted":"Test: esc :set nu (alternative) | Example | esc (str)+ :set nu"},{"hit_number":1,"comment":"Test to run shortcut 'esc :set nu enter', using (str) to type string instead","keycode":"1.1 1.0 + :set nu 28.1 28.0","formatted":"Test: esc :set nu enter (alternative) | Example | esc (str)+ :set nu (str) enter"},{"hit_number":1,"comment":"Test to run shortcut 'meta+pageup', maximize window in KDE or maybe other desktop","keycode":"126.1 104.1 104.0 126.0","formatted":"Test: meta+pageup | Example | meta+pageup"},{"hit_number":1,"comment":"Go to begin of command prompt","keycode":"29.1 30.1 30.0 29.0","formatted":"To command begin | Terminal | ctrl+a"},{"hit_number":1,"comment":"Go to end of command prompt","keycode":"29.1 18.1 18.0 29.0","formatted":"To command end | Terminal | ctrl+e"},{"hit_number":0,"comment":"","keycode":"56.1 62.1 62.0 56.0","formatted":"Close Window | KWin | alt+f4"},{"hit_number":0,"comment":"Copy the current line","keycode":"1.1 1.0 + yy","formatted":"Copy Line | Nvim | esc yy"},{"hit_number":0,"comment":"Copy the selected text to Nvim register 'a'","keycode":"+ \" + ay","formatted":"Copy the selection to Nvim register | Nvim | \" ay"},{"hit_number":0,"comment":"Copy the selected text to the system clipboard","keycode":"+ \" + + 21.1 21.0","formatted":"Copy the selection to system clipboard | Nvim | \" + y"},{"hit_number":0,"comment":"Cut the current line","keycode":"1.1 1.0 + dd","formatted":"Cut Line | Nvim | esc dd"},{"hit_number":0,"comment":"Move the cursor to the beginning of the page (scroll up)","keycode":"1.1 1.0 + gg","formatted":"Go to the file begin | Nvim | esc gg"},{"hit_number":0,"comment":"Move the cursor to the end of the page (scroll down)","keycode":"1.1 1.0 34.1 34.0","formatted":"Go to the file end | Nvim | esc G"},{"hit_number":0,"comment":"Move the cursor to the beginning of the current line","keycode":"1.1 1.0 11.1 11.0","formatted":"Go to the line begin | Nvim | esc 0"},{"hit_number":0,"comment":"Move the cursor to the end of the current line","keycode":"1.1 1.0 + $","formatted":"Go to the line end | Nvim | esc $"},{"hit_number":0,"comment":"Paste the content from Nvim register 'a'","keycode":"1.1 1.0 + \" + ap","formatted":"Paste the Nvim register | Nvim | esc \" ap"},{"hit_number":0,"comment":"Paste the content from the system clipboard","keycode":"1.1 1.0 + \" + + 25.1 25.0","formatted":"Paste the system clipboard | Nvim | esc \" + p"},{"hit_number":0,"comment":"Paste after the cursor","keycode":"1.1 1.0 25.1 25.0","formatted":"Paste | Nvim | esc p"},{"hit_number":0,"comment":"Quit Nvim without saving changes","keycode":"1.1 1.0 + :q! 28.1 28.0","formatted":"Quit Without Saving | Nvim | esc :q! enter"},{"hit_number":0,"comment":"Quit Nvim","keycode":"1.1 1.0 + :q 28.1 28.0","formatted":"Quit | Nvim | esc :q enter"},{"hit_number":0,"comment":"Redo the last undone change","keycode":"1.1 1.0 29.1 19.1 19.0 29.0","formatted":"Redo | Nvim | esc ctrl+r"},{"hit_number":0,"comment":"Replace 'old' with 'new' throughout the file","keycode":"1.1 1.0 + :%s/old/new/g 28.1 28.0","formatted":"Replace in File | Nvim | esc :%s/old/new/g enter"},{"hit_number":0,"comment":"Save the current file","keycode":"1.1 1.0 + :w 28.1 28.0","formatted":"Save File | Nvim | esc :w enter"},{"hit_number":0,"comment":"Save the current file and quit Nvim","keycode":"1.1 1.0 + :wq 28.1 28.0","formatted":"Save and Quit | Nvim | esc :wq enter"},{"hit_number":0,"comment":"Search for 'old' and replace with 'new' throughout the file","keycode":"1.1 1.0 + :%s/old/new/g","formatted":"Search and replace all | Nvim | esc :%s/old/new/g"},{"hit_number":0,"comment":"Search for 'old' and replace with 'new' (confirm each replacement)","keycode":"1.1 1.0 + :s/old/new/gc","formatted":"Search and replace one | Nvim | esc :s/old/new/gc"},{"hit_number":0,"comment":"Search case-insensitive within the file","keycode":"1.1 1.0 + /\\\\C","formatted":"Search case-insensitive | Nvim | esc /\\\\C"},{"hit_number":0,"comment":"Search case-sensitive within the file","keycode":"1.1 1.0 + /\\\\c 105.1 105.0 105.1 105.0","formatted":"Search case-sensitive | Nvim | esc /\\\\c left left"},{"hit_number":0,"comment":"Next search result of history","keycode":"29.1 49.1 49.0 29.0","formatted":"Search command history (next) | Terminal | ctrl+n"},{"hit_number":0,"comment":"Previous search result of history","keycode":"29.1 25.1 25.0 29.0","formatted":"Search command history (previous) | Terminal | ctrl+p"},{"hit_number":0,"comment":"Search command history in the terminal","keycode":"29.1 19.1 19.0 29.0","formatted":"Search command history | Terminal | ctrl+r"},{"hit_number":0,"comment":"Search within the file","keycode":"1.1 1.0 53.1 53.0","formatted":"Search in File | Nvim | esc /"},{"hit_number":0,"comment":"Test to run shortcut 'esc :set nu enter', set number in vim/nvim","keycode":"1.1 1.0 + :set 57.1 57.0 + nu 57.1 57.0 28.1 28.0","formatted":"Test: esc :set nu space enter | Example | esc :set space nu space enter"},{"hit_number":0,"comment":"Undo the last change","keycode":"1.1 1.0 22.1 22.0","formatted":"Undo | Nvim | esc u"}] \ No newline at end of file +[{"hit_number":8,"comment":"Clear the command prompt typed","keycode":"29.1 22.1 22.0 29.0","formatted":"Clear command prompt | Terminal | ctrl+u"},{"hit_number":6,"comment":"Welcom message","keycode":"+ Hello World!","formatted":"Hello world | Welcome | (str)+ Hello World!"},{"hit_number":6,"comment":"","keycode":"126.1 109.1 109.0 126.0","formatted":"Minimize Window | KWin | meta+pagedown"},{"hit_number":2,"comment":"Test to run shortcut 'ctrl+shift+c', the copy command in Zsh","keycode":"29.1 42.1 46.1 46.0 42.0 29.0","formatted":"Test: ctrl+shift+c | Example | ctrl+shift+c"},{"hit_number":2,"comment":"Test to run shortcut 'esc :set nu', set number in vim/nvim","keycode":"1.1 1.0 + :set 57.1 57.0 + nu","formatted":"Test: esc :set nu | Example | esc :set space nu"},{"hit_number":2,"comment":"Welcom message","keycode":"+ liz and the blue bird","formatted":"Welcome | Welcome | (str)+ liz and the blue bird"},{"hit_number":1,"comment":"","keycode":"126.1 104.1 104.0 126.0","formatted":"Maximize Window | KWin | meta+pageup"},{"hit_number":1,"comment":"Test to run shortcut 'esc :set nu', using (str) to type string instead","keycode":"1.1 1.0 + :set nu","formatted":"Test: esc :set nu (alternative) | Example | esc (str)+ :set nu"},{"hit_number":1,"comment":"Test to run shortcut 'esc :set nu enter', using (str) to type string instead","keycode":"1.1 1.0 + :set nu 28.1 28.0","formatted":"Test: esc :set nu enter (alternative) | Example | esc (str)+ :set nu (str) enter"},{"hit_number":1,"comment":"Test to run shortcut 'meta+pageup', maximize window in KDE or maybe other desktop","keycode":"126.1 104.1 104.0 126.0","formatted":"Test: meta+pageup | Example | meta+pageup"},{"hit_number":1,"comment":"Go to begin of command prompt","keycode":"29.1 30.1 30.0 29.0","formatted":"To command begin | Terminal | ctrl+a"},{"hit_number":1,"comment":"Go to end of command prompt","keycode":"29.1 18.1 18.0 29.0","formatted":"To command end | Terminal | ctrl+e"},{"hit_number":0,"comment":"","keycode":"56.1 62.1 62.0 56.0","formatted":"Close Window | KWin | alt+f4"},{"hit_number":0,"comment":"Copy the current line","keycode":"1.1 1.0 + yy","formatted":"Copy Line | Nvim | esc yy"},{"hit_number":0,"comment":"Copy the selected text to Nvim register 'a'","keycode":"+ \" + ay","formatted":"Copy the selection to Nvim register | Nvim | \" ay"},{"hit_number":0,"comment":"Copy the selected text to the system clipboard","keycode":"+ \" + + 21.1 21.0","formatted":"Copy the selection to system clipboard | Nvim | \" + y"},{"hit_number":0,"comment":"Cut the current line","keycode":"1.1 1.0 + dd","formatted":"Cut Line | Nvim | esc dd"},{"hit_number":0,"comment":"Move the cursor to the beginning of the page (scroll up)","keycode":"1.1 1.0 + gg","formatted":"Go to the file begin | Nvim | esc gg"},{"hit_number":0,"comment":"Move the cursor to the end of the page (scroll down)","keycode":"1.1 1.0 34.1 34.0","formatted":"Go to the file end | Nvim | esc G"},{"hit_number":0,"comment":"Move the cursor to the beginning of the current line","keycode":"1.1 1.0 11.1 11.0","formatted":"Go to the line begin | Nvim | esc 0"},{"hit_number":0,"comment":"Move the cursor to the end of the current line","keycode":"1.1 1.0 + $","formatted":"Go to the line end | Nvim | esc $"},{"hit_number":0,"comment":"Paste the content from Nvim register 'a'","keycode":"1.1 1.0 + \" + ap","formatted":"Paste the Nvim register | Nvim | esc \" ap"},{"hit_number":0,"comment":"Paste the content from the system clipboard","keycode":"1.1 1.0 + \" + + 25.1 25.0","formatted":"Paste the system clipboard | Nvim | esc \" + p"},{"hit_number":0,"comment":"Paste after the cursor","keycode":"1.1 1.0 25.1 25.0","formatted":"Paste | Nvim | esc p"},{"hit_number":0,"comment":"Quit Nvim without saving changes","keycode":"1.1 1.0 + :q! 28.1 28.0","formatted":"Quit Without Saving | Nvim | esc :q! enter"},{"hit_number":0,"comment":"Quit Nvim","keycode":"1.1 1.0 + :q 28.1 28.0","formatted":"Quit | Nvim | esc :q enter"},{"hit_number":0,"comment":"Redo the last undone change","keycode":"1.1 1.0 29.1 19.1 19.0 29.0","formatted":"Redo | Nvim | esc ctrl+r"},{"hit_number":0,"comment":"Replace 'old' with 'new' throughout the file","keycode":"1.1 1.0 + :%s/old/new/g 28.1 28.0","formatted":"Replace in File | Nvim | esc :%s/old/new/g enter"},{"hit_number":0,"comment":"Save the current file","keycode":"1.1 1.0 + :w 28.1 28.0","formatted":"Save File | Nvim | esc :w enter"},{"hit_number":0,"comment":"Save the current file and quit Nvim","keycode":"1.1 1.0 + :wq 28.1 28.0","formatted":"Save and Quit | Nvim | esc :wq enter"},{"hit_number":0,"comment":"Search for 'old' and replace with 'new' throughout the file","keycode":"1.1 1.0 + :%s/old/new/g","formatted":"Search and replace all | Nvim | esc :%s/old/new/g"},{"hit_number":0,"comment":"Search for 'old' and replace with 'new' (confirm each replacement)","keycode":"1.1 1.0 + :s/old/new/gc","formatted":"Search and replace one | Nvim | esc :s/old/new/gc"},{"hit_number":0,"comment":"Search case-insensitive within the file","keycode":"1.1 1.0 + /\\\\C","formatted":"Search case-insensitive | Nvim | esc /\\\\C"},{"hit_number":0,"comment":"Search case-sensitive within the file","keycode":"1.1 1.0 + /\\\\c 105.1 105.0 105.1 105.0","formatted":"Search case-sensitive | Nvim | esc /\\\\c left left"},{"hit_number":0,"comment":"Next search result of history","keycode":"29.1 49.1 49.0 29.0","formatted":"Search command history (next) | Terminal | ctrl+n"},{"hit_number":0,"comment":"Previous search result of history","keycode":"29.1 25.1 25.0 29.0","formatted":"Search command history (previous) | Terminal | ctrl+p"},{"hit_number":0,"comment":"Search command history in the terminal","keycode":"29.1 19.1 19.0 29.0","formatted":"Search command history | Terminal | ctrl+r"},{"hit_number":0,"comment":"Search within the file","keycode":"1.1 1.0 53.1 53.0","formatted":"Search in File | Nvim | esc /"},{"hit_number":0,"comment":"Test to run shortcut 'esc :set nu enter', set number in vim/nvim","keycode":"1.1 1.0 + :set 57.1 57.0 + nu 57.1 57.0 28.1 28.0","formatted":"Test: esc :set nu space enter | Example | esc :set space nu space enter"},{"hit_number":0,"comment":"Undo the last change","keycode":"1.1 1.0 22.1 22.0","formatted":"Undo | Nvim | esc u"}] \ No newline at end of file diff --git a/doc/ydotool/customize.md b/doc/ydotool/README.md similarity index 100% rename from doc/ydotool/customize.md rename to doc/ydotool/README.md diff --git a/liz/Cargo.toml b/liz/Cargo.toml index e44d092..f83ec38 100644 --- a/liz/Cargo.toml +++ b/liz/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "liz" -version = "0.1.0" +version = "0.1.1" edition = "2021" authors = ["Felix Wang "] description = "The client to send commands to bluebird for liz-shortcut-helper" diff --git a/scripts/copy_to_config_liz.sh b/scripts/copy_to_config_liz.sh index 780c37b..68abefe 100755 --- a/scripts/copy_to_config_liz.sh +++ b/scripts/copy_to_config_liz.sh @@ -4,13 +4,49 @@ set -e # Define the target directory TARGET_DIR="$HOME/.config/liz" -# Check if the target directory exists, create it if not -if [ ! -d "$TARGET_DIR" ]; then +# Check if the target directory exists +if [ -d "$TARGET_DIR" ]; then + echo "Directory $TARGET_DIR already exists." + read -p "Do you want to overwrite it? (y/N): " choice + choice=${choice:-N} # Default to 'N' if no input is provided + case "$choice" in + [yY][eE][sS]|[yY]) + echo "Overwriting $TARGET_DIR..." + rm -rf "$TARGET_DIR" + mkdir -p "$TARGET_DIR" + ;; + *) + echo "Exiting without making changes." + return 0 + ;; + esac +else echo "Directory $TARGET_DIR does not exist. Creating it..." mkdir -p "$TARGET_DIR" fi -source generate_default_rhythm.sh + +# Get the current username +USER=$(whoami) + +# Define the paths with the current user +LIZ_PATH="/home/$USER/.config/liz/" +MUSIC_SHEET_PATH="/home/$USER/Workroom/liz-shortcut-helper/data/music_sheet.lock" +USER_SHEETS_PATH="/home/$USER/Workroom/liz-shortcut-helper/data/sheets" +KEYMAP_PATH="/home/$USER/.config/liz/keymap.json" +YDOTTOOL_SOCKET_PATH="/tmp/.ydotool_socket" + +# Create the rhythm.toml file with the paths +cat < ./data/rhythm.toml +liz_path = "$LIZ_PATH" +music_sheet_path = "$MUSIC_SHEET_PATH" +user_sheets_path = "$USER_SHEETS_PATH" +keymap_path = "$KEYMAP_PATH" +ydotool_socket_path = "$YDOTTOOL_SOCKET_PATH" +EOL + +echo "rhythm.toml has been generated with paths for user '$USER'." + # Copy files from ./data/* to ~/.config/liz echo "Copying files from ./data/* to $TARGET_DIR..." diff --git a/scripts/generate_default_rhythm.sh b/scripts/generate_default_rhythm.sh deleted file mode 100644 index 7f4f689..0000000 --- a/scripts/generate_default_rhythm.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -# Get the current username -USER=$(whoami) - -# Define the paths with the current user -LIZ_PATH="/home/$USER/.config/liz/" -MUSIC_SHEET_PATH="/home/$USER/Workroom/liz-shortcut-helper/data/music_sheet.lock" -USER_SHEETS_PATH="/home/$USER/Workroom/liz-shortcut-helper/data/sheets" -KEYMAP_PATH="/home/$USER/.config/liz/keymap.json" -YDOTTOOL_SOCKET_PATH="/tmp/.ydotool_socket" - -# Create the rhythm.toml file with the paths -cat < ./data/rhythm.toml -liz_path = "$LIZ_PATH" -music_sheet_path = "$MUSIC_SHEET_PATH" -user_sheets_path = "$USER_SHEETS_PATH" -keymap_path = "$KEYMAP_PATH" -ydotool_socket_path = "$YDOTTOOL_SOCKET_PATH" -EOL - -echo "rhythm.toml has been generated with paths for user '$USER'." diff --git a/scripts/install.sh b/scripts/install.sh index baeffad..822417e 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,17 +1,23 @@ #!/bin/bash set -e -echo "Move binaries to /usr/local/bin" -sudo cp liz /usr/local/bin/ -sudo cp bluebird /usr/local/bin/ +# Copy the data/* to the default place where is +# /home/yourname/.config/liz/ +# If it already exists, feel free to comment and skip this +source copy_to_config_liz.sh || { echo "Install Failed"; exit 1; } -echo "Make binaries executable" -sudo chmod +x /usr/local/bin/liz -sudo chmod +x /usr/local/bin/bluebird +# Intall ydotool and rofi, if you already installed them +# or you want to install by yourself, comment this +source install_dependencies.sh || { echo "Install Failed"; exit 1; } -source copy_to_config_liz.sh -source install_dependencies.sh -source setup_ydotoold_service.sh -source setup_bluebird_service.sh /usr/local/bin/bluebird +# Setup the ydotool deamon service, if youw want to do this +# manually, skip this. Or you can check this to see what it +# does and make sure it is safe in your system. +source setup_ydotoold_service.sh || { echo "Install Failed"; exit 1; } + +# Setup the bluebird service, and enable it to automatically +# start on startup. It is mandatory, and should NOT be commented +# Or the bluebird and liz will not be upgraded. +source setup_bluebird_service.sh || { echo "Install Failed"; exit 1; } echo "Install complete!" \ No newline at end of file diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh index 5f08995..3af5295 100755 --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -1,22 +1,54 @@ #!/bin/bash set -e +# Function to check if a package is installed +is_installed() { + local package="$1" + if [ "$OS" == "Arch" ]; then + pacman -Qi "$package" &> /dev/null + elif [ "$OS" == "Debian" ]; then + dpkg -l "$package" &> /dev/null + elif [ "$OS" == "Fedora" ]; then + rpm -q "$package" &> /dev/null + elif [ "$OS" == "SUSE" ]; then + rpm -q "$package" &> /dev/null + else + echo "Unsupported OS: $OS" + return 1 + fi +} + # Function to install packages install_packages() { local packages=("$@") + local to_install=() + + for package in "${packages[@]}"; do + if is_installed "$package"; then + echo "$package is already installed. Skipping." + else + to_install+=("$package") + fi + done + + if [ ${#to_install[@]} -eq 0 ]; then + echo "All packages are already installed. Exiting." + return 0 + fi + echo "Installing ${packages[*]}..." if [ "$OS" == "Arch" ]; then sudo pacman -S "${packages[@]}" elif [ "$OS" == "Debian" ]; then sudo apt update - sudo apt install -y "${packages[@]}" + sudo apt install "${packages[@]}" elif [ "$OS" == "Fedora" ]; then - sudo dnf install -y "${packages[@]}" + sudo dnf install "${packages[@]}" elif [ "$OS" == "SUSE" ]; then - sudo zypper install -y "${packages[@]}" + sudo zypper install "${packages[@]}" else echo "Unsupported OS: $OS" - exit 1 + return 1 fi } @@ -40,12 +72,12 @@ if [ -f /etc/os-release ]; then ;; *) echo "Unsupported Linux distribution: $ID" - exit 1 + return 1 ;; esac else echo "Could not detect OS." - exit 1 + return 1 fi # Install ydotool and rofi @@ -58,4 +90,4 @@ else install_packages ydotool rofi fi -echo "Installation complete!" \ No newline at end of file +echo "All packages are installed!" \ No newline at end of file diff --git a/scripts/setup_bluebird_service.sh b/scripts/setup_bluebird_service.sh index e487f65..3100c85 100755 --- a/scripts/setup_bluebird_service.sh +++ b/scripts/setup_bluebird_service.sh @@ -2,29 +2,72 @@ set -e # Check if the EXEC_START parameter is provided -if [ -z "$1" ]; then - echo "Error: No ExecStart path provided." - echo "Usage: sudo ./setup_bluebird_service.sh /path/to/bluebird" - exit 1 -fi +# if [ -z "$1" ]; then +# echo "Error: No ExecStart path provided." +# echo "Usage: sudo ./setup_bluebird_service.sh /path/to/bluebird" +# exit 1 +# fi # Variables SERVICE_NAME="bluebird" SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" -EXEC_START="$1" +BIN_PATH=${1:-"/usr/local/bin"} USER=$(whoami) # Automatically get the current user +# Function to upgrade the executable bluebird and liz +upgrading() { + + echo "Upgrading liz and bluebird" + + echo "Move binaries to $BIN_PATH" + sudo cp liz $BIN_PATH + sudo cp bluebird $BIN_PATH + + echo "Make binaries executable" + sudo chmod +x $BIN_PATH/liz + sudo chmod +x $BIN_PATH/bluebird +} + +# Check if need to further running +if [ -f "$SERVICE_FILE" ]; then + + echo "Disabling and stopping the existing $SERVICE_NAME.service..." + # sudo systemctl disable $SERVICE_NAME.service + sudo systemctl stop $SERVICE_NAME.service + + upgrading + + echo "The service file $SERVICE_FILE already exists." + read -p "Do you want to overwrite it? (Y/n): " choice + choice=${choice:-Y} # Default to 'N' if no input is provided + case "$choice" in + [yY][eE][sS]|[yY]) + echo "Overwriting $SERVICE_FILE..." + ;; + *) + # Restart the service + echo "Starting and enabling the services..." + sudo systemctl start ${SERVICE_NAME}.service + # sudo systemctl enable ${SERVICE_NAME}.service + echo "Exiting without changing the service" + return 0 + ;; + esac +else + echo "Creating the systemd service file..." +fi + # Create or overwrite the service file echo "Creating systemd service file at ${SERVICE_FILE}..." cat < /dev/null [Unit] Description=Bluebird Service for Liz -After=ydotoold.service -Requires=ydotoold.service +# After=ydotoold.service +# Requires=ydotoold.service [Service] -ExecStart=${EXEC_START} +ExecStart=${BIN_PATH}/bluebird Restart=on-failure User=${USER} # WorkingDirectory=/home/${USER}/.config/liz @@ -48,4 +91,4 @@ sudo systemctl enable ${SERVICE_NAME}.service # Status check echo "Checking the status of ${SERVICE_NAME} service..." -sudo systemctl status ${SERVICE_NAME}.service +sudo systemctl status ${SERVICE_NAME}.service --no-pager \ No newline at end of file diff --git a/scripts/setup_ydotoold_service.sh b/scripts/setup_ydotoold_service.sh index ca55fdc..e724578 100755 --- a/scripts/setup_ydotoold_service.sh +++ b/scripts/setup_ydotoold_service.sh @@ -13,6 +13,31 @@ fi echo "Adding $(whoami) to the 'ydotoolgroup'..." sudo usermod -aG ydotoolgroup $(whoami) + +# Check if need to further creating the service +SERVICE_FILE="/etc/systemd/system/ydotoold.service" + +if [ -f "$SERVICE_FILE" ]; then + echo "The service file $SERVICE_FILE already exists." + read -p "Do you want to overwrite it? (y/N): " choice + choice=${choice:-N} # Default to 'N' if no input is provided + case "$choice" in + [yY][eE][sS]|[yY]) + echo "Disabling and stopping the existing ydotoold.service..." + sudo systemctl disable ydotoold.service + sudo systemctl stop ydotoold.service + echo "Overwriting $SERVICE_FILE..." + ;; + *) + echo "Exiting without making changes." + return 0 + ;; + esac +else + echo "Creating the systemd service file..." +fi + + # Step 3: Remove the old socket file if it exists SOCKET_FILE="/tmp/.ydotool_socket" if [ -e "$SOCKET_FILE" ]; then @@ -23,7 +48,6 @@ else fi # Step 4: Edit the systemd service file -SERVICE_FILE="/etc/systemd/system/ydotoold.service" echo "Creating or updating the systemd service file..." sudo tee $SERVICE_FILE > /dev/null << EOL @@ -56,4 +80,4 @@ sudo systemctl start ydotoold.service # Step 7: Verify the service status echo "Checking ydotoold.service status..." -sudo systemctl status ydotoold.service +sudo systemctl status ydotoold.service --no-pager