From bc4ce82e6e7f187e291d1a0c6bb45768a7595a1b Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Mon, 3 Jun 2024 22:59:00 +0300 Subject: [PATCH] Refactoring - Moved configuration file to ~/.config/alyverkko-cli/alyverkko-cli.yaml - Modular install script - Add uninstall script --- alyverkko-cli.yaml | 2 +- doc/index.org | 60 ++++---- install | 137 ++++++++++-------- .../configuration/Configuration.java | 2 +- uninstall | 9 ++ 5 files changed, 119 insertions(+), 91 deletions(-) create mode 100755 uninstall diff --git a/alyverkko-cli.yaml b/alyverkko-cli.yaml index 0fc9ede..33d9cb2 100644 --- a/alyverkko-cli.yaml +++ b/alyverkko-cli.yaml @@ -1,7 +1,7 @@ mail_directory: "/home/user/AI/mail" models_directory: "/home/user/AI/models" default_temperature: 0.7 -llama_cpp_executable_path: "/home/user/AI/llama.cpp/main" +llama_cpp_dir_path: "/home/user/AI/llama.cpp" batch_thread_count: 10 thread_count: 6 models: diff --git a/doc/index.org b/doc/index.org index 9bc055e..b48744d 100644 --- a/doc/index.org +++ b/doc/index.org @@ -399,7 +399,7 @@ Suggested usage flow is to prepare AI assignments within the Älyverkko CLI mail directory using normal text editor. Once AI assignment is ready for processing, you should [[id:883d6e7c-60e0-422b-8c00-5cdc9dfec20d][initiate AI processing]] on that file. -** joinfiles command +** "joinfiles" command The *joinfiles* command is a utility for aggregating the contents of multiple files into a single document, which can then be processed by @@ -526,10 +526,10 @@ input a topic name. This name will serve as the basis for the filename and the title within the document. The function then constructs a file path by concatenating the -pre-defined =ai-topic-files-directory= (which should be set to your -topics directory), the topic name, and the =.org= extension. If a file -with this path does not already exist, the function will create a new -file and open it for editing. +pre-defined =alyverkko-topic-files-directory= (which should be set to +your topics directory), the topic name, and the =.org= extension. If a +file with this path does not already exist, the function will create a +new file and open it for editing. #+begin_src elisp :results none @@ -564,32 +564,32 @@ inserting the appropriate directive at the beginning of the current buffer in Emacs. #+begin_src elisp :results none -(defun alyverkko-compute () - "Select a prompt alias interactively and insert it at the beginning of the current buffer." - (interactive) - (let ((config-file "~/.config/alyverkko-cli.yaml") - (aliases '())) - (with-temp-buffer - (insert-file-contents config-file) - ;; Move to the beginning of the prompts section + (defun alyverkko-compute () + "Select a prompt alias interactively and insert it at the beginning of the current buffer." + (interactive) + (let ((config-file "~/.config/alyverkko-cli/alyverkko-cli.yaml") + (aliases '())) + (with-temp-buffer + (insert-file-contents config-file) + ;; Move to the beginning of the prompts section + (goto-char (point-min)) + (when (search-forward-regexp "^prompts:" nil t) + ;; Collect all aliases + (while (search-forward-regexp "^\\s-+- alias: \"\\([^\"]+\\)\"" nil t) + (push (match-string 1) aliases)))) + ;; Let the user choose from the collected aliases + (if aliases + (let ((selected-alias (completing-read "Select prompt alias: " (reverse aliases)))) + ;; now insert in original buffer + (alyverkko-insert-tocompute-line selected-alias)) + (message "No prompts found.")))) + + (defun alyverkko-insert-tocompute-line (prompt-alias) + "Inserts TOCOMPUTE line with selected PROMPT-ALIAS at the beginning of the buffer." + (save-excursion ; Preserve the original cursor location in the buffer (goto-char (point-min)) - (when (search-forward-regexp "^prompts:" nil t) - ;; Collect all aliases - (while (search-forward-regexp "^\\s-+- alias: \"\\([^\"]+\\)\"" nil t) - (push (match-string 1) aliases)))) - ;; Let the user choose from the collected aliases - (if aliases - (let ((selected-alias (completing-read "Select prompt alias: " (reverse aliases)))) - ;; now insert in original buffer - (alyverkko-insert-tocompute-line selected-alias)) - (message "No prompts found.")))) - -(defun alyverkko-insert-tocompute-line (prompt-alias) - "Inserts TOCOMPUTE line with selected PROMPT-ALIAS at the beginning of the buffer." - (save-excursion ; Preserve the original cursor location in the buffer - (goto-char (point-min)) - (insert (format "TOCOMPUTE: prompt=%s\n" prompt-alias)) - (save-buffer))) + (insert (format "TOCOMPUTE: prompt=%s\n" prompt-alias)) + (save-buffer))) #+end_src * TODO diff --git a/install b/install index b8b81e1..188e05b 100755 --- a/install +++ b/install @@ -1,68 +1,44 @@ #!/bin/bash -# Define constants for paths and filenames -INSTALL_DIR="/opt/alyverkko-cli" -BINARY="alyverkko-cli" -DESKTOP_FILE="alyverkko-cli.desktop" -ICON_FILE="$INSTALL_DIR/logo.png" -APPLICATIONS_DIR="/usr/share/applications" -SYSTEM_SERVICE_DIR="/etc/systemd/system" -CONFIG_DIR="${HOME}/.config/" -SYSTEM_SERVICE="alyverkko-cli.service" - -# Build the application -mvn --settings maven.xml clean package - -# Install the binary and jar -sudo mkdir -p "$INSTALL_DIR" -sudo rm -f "$INSTALL_DIR/$BINARY.jar" -sudo cp target/"$BINARY".jar "$INSTALL_DIR/$BINARY.jar" -sudo cp "$BINARY" "$INSTALL_DIR/$BINARY" - -# Create a symbolic link to run the program from CLI -sudo rm -f /usr/bin/"$BINARY" -sudo ln -s "$INSTALL_DIR/$BINARY" /usr/bin/"$BINARY" - -# Install the desktop launcher -cat < /dev/null +SYSTEMD_SERVICE_FILE="/etc/systemd/system/alyverkko-cli.service" + + +# Function to install binary and jar +install_to_opt() { + sudo rm -rf /opt/alyverkko-cli/ + sudo mkdir -p /opt/alyverkko-cli/ + sudo chmod 755 /opt/alyverkko-cli/ + + sudo cp target/alyverkko-cli.jar "/opt/alyverkko-cli/alyverkko-cli.jar" + sudo cp "alyverkko-cli" "/opt/alyverkko-cli/alyverkko-cli" + sudo chmod +x "/opt/alyverkko-cli/alyverkko-cli" + sudo cp logo.png "/opt/alyverkko-cli/logo.png" + + sudo ln -sf "/opt/alyverkko-cli/alyverkko-cli" /usr/bin/alyverkko-cli +} + +# Function to install the desktop launcher +install_desktop_entry() { + local desktop_entry_path="/usr/share/applications/alyverkko-cli.desktop" + + cat < /dev/null [Desktop Entry] Type=Application Terminal=true Name=Älyverkko CLI Comment=Runner for artificial neural network service -Icon=$ICON_FILE -Exec=/opt/alyverkko-cli/$BINARY mail +Icon=/opt/alyverkko-cli/logo.png +Exec=/opt/alyverkko-cli/alyverkko-cli mail Categories=Development; EOF -# Make sure the desktop file is executable -sudo chmod 644 "$APPLICATIONS_DIR/$DESKTOP_FILE" + sudo chmod 644 "$desktop_entry_path" +} -# Copy the icon (assuming you have an icon named alyverkko-cli.svg) -sudo cp logo.png "$ICON_FILE" +# Function to install systemd service +install_systemd_service() { -# Pre-deploy example configuration YAML file -sudo mkdir -p "$CONFIG_DIR" - -if [ -f "$CONFIG_DIR/alyverkko-cli.yaml" ]; then - echo "Configuration file already exists. Skipping pre-deployment." -else - sudo cp alyverkko-cli.yaml "$CONFIG_DIR" -fi - -# Check if systemd service already exists -if [ -f "$SYSTEM_SERVICE_DIR/$SYSTEM_SERVICE" ]; then - echo "Systemd service is already installed." - # Display the status without hanging - echo "Service status is:" - systemctl --no-pager -l status alyverkko-cli -else - # Install systemd service if requested - echo "Do you want to install Älyverkko CLI as a systemd service? (y/N)" - read install_service - - if [[ $install_service == [Yy] ]]; then - cat < /dev/null + cat < /dev/null [Unit] Description=Älyverkko CLI daemon in mail mode After=network.target @@ -78,12 +54,55 @@ RestartSec=10 [Install] WantedBy=multi-user.target EOF - sudo systemctl daemon-reload - sudo systemctl enable alyverkko-cli - sudo systemctl start alyverkko-cli - echo "Systemd service installed, enabled and started. Service status is:" + + sudo systemctl daemon-reload + sudo systemctl enable alyverkko-cli + sudo systemctl start alyverkko-cli + sleep 1 + echo "Systemd service installed, enabled and started. Service status is:" + systemctl --no-pager -l status alyverkko-cli +} + + +# Function to pre-deploy example configuration YAML file +install_config_file() { + local alyverkko_config_dir="${HOME}/.config/alyverkko-cli" + + if [ ! -d "$alyverkko_config_dir" ]; then + mkdir -p "$alyverkko_config_dir" + cp alyverkko-cli.yaml "$alyverkko_config_dir/" + else + echo "Configuration directory already exists: $alyverkko_config_dir" + fi +} + +# Main installation function +main() { + # Build the application + mvn --settings maven.xml clean package + + install_to_opt + install_desktop_entry + install_config_file + + # Check if systemd service already exists + if [ -f "$SYSTEMD_SERVICE_FILE" ]; then + echo "Systemd service is already installed." + # Display the status without hanging + echo "Service status is:" systemctl --no-pager -l status alyverkko-cli + else + # Install systemd service if requested + echo "Do you want to install Älyverkko CLI as a systemd service? (y/N)" + read install_service + + if [[ $install_service == [Yy] ]]; then + install_systemd_service + fi fi -fi -echo "Installation complete." + echo "Installation complete." +} + +# Call the main installation function +main diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/Configuration.java b/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/Configuration.java index a37d03d..15fab2d 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/Configuration.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/Configuration.java @@ -12,7 +12,7 @@ import java.util.List; @Data public class Configuration { - private static final String DEFAULT_CONFIG_FILE_PATH = "~/.config/alyverkko-cli.yaml".replaceFirst("^~", System.getProperty("user.home")); + private static final String DEFAULT_CONFIG_FILE_PATH = "~/.config/alyverkko-cli/alyverkko-cli.yaml".replaceFirst("^~", System.getProperty("user.home")); @JsonProperty("mail_directory") private File mailDirectory; diff --git a/uninstall b/uninstall new file mode 100755 index 0000000..7e4138e --- /dev/null +++ b/uninstall @@ -0,0 +1,9 @@ +#!/bin/bash + +SYSTEMD_SERVICE_FILE="/etc/systemd/system/alyverkko-cli.service" + +sudo systemctl stop alyverkko-cli +sudo systemctl disable alyverkko-cli +sudo rm "$SYSTEMD_SERVICE_FILE" +sudo rm -rf /opt/alyverkko-cli/ + -- 2.20.1