#!/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/" # Ask user if they want to install systemd service echo "Do you want to install Älyverkko CLI as a systemd service? (y/N)" read install_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 [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 Categories=Development; EOF # Make sure the desktop file is executable sudo chmod 644 "$APPLICATIONS_DIR/$DESKTOP_FILE" # Copy the icon (assuming you have an icon named alyverkko-cli.svg) sudo cp logo.png "$ICON_FILE" # 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 # Install systemd service if requested if [[ $install_service == [Yy] ]]; then cat < /dev/null [Unit] Description=Älyverkko CLI daemon in mail mode After=network.target [Service] User=$USER ExecStart=/opt/alyverkko-cli/alyverkko-cli mail WorkingDirectory=/opt/alyverkko-cli Nice=10 Restart=always 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:" systemctl -l status alyverkko-cli fi echo "Installation complete."