From 4533a8f097d2e0eeb76d863f386027636f21b791 Mon Sep 17 00:00:00 2001 From: LHSmicius Date: Sun, 4 May 2025 00:53:08 +0300 Subject: [PATCH] chore: add installer script for linux --- install-linux.sh | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 install-linux.sh diff --git a/install-linux.sh b/install-linux.sh new file mode 100755 index 0000000..20b5ff9 --- /dev/null +++ b/install-linux.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +APP_PATH="/usr/bin/SavvyCAN" +DESKTOP_PATH="/usr/share/applications/savvycan.desktop" +ICON_PATH="/usr/share/pixmaps/SavvyCAN.png" + +require_root() { + if [ "$(id -u)" -ne 0 ]; then + echo "This script must be run as root." + exit 1 + fi +} + +show_help() { + echo "Usage: $0 [option]" + echo "" + echo "Options:" + echo " --help Show this help message" + echo " --uninstall Remove SavvyCAN from the system" + echo " (no option) Install or reinstall SavvyCAN" +} + +install_error() { + echo "SavvyCAN installation failed." + exit 1 +} + +uninstall_error() { + echo "SavvyCAN uninstallation failed." + exit 1 +} + +if [ "$1" = "--help" ]; then + show_help + exit 0 +fi + +require_root + +# Uninstall +if [ "$1" = "--uninstall" ]; then + echo "Uninstalling SavvyCAN..." + trap uninstall_error ERR + rm -f "$APP_PATH" "$DESKTOP_PATH" "$ICON_PATH" + trap - ERR + echo "SavvyCAN has been uninstalled." + exit 0 +fi + +# Check required files +if [ ! -f "SavvyCAN" ]; then + echo "Missing file \"SavvyCAN\". You need to build first." + install_error +fi + +if [ ! -f "SavvyCAN.desktop" ]; then + echo "Missing file \"SavvyCAN.desktop\"." + install_error +fi + +if [ ! -f "icons/SavvyIcon.png" ]; then + echo "Missing file \"icons/SavvyIcon.png\"." + install_error +fi + +# Install +if [ -f "$APP_PATH" ]; then + echo "Re-installing SavvyCAN..." +else + echo "Installing SavvyCAN..." +fi + +trap install_error ERR +install -Dm755 SavvyCAN "$APP_PATH" +install -Dm644 SavvyCAN.desktop "$DESKTOP_PATH" +install -Dm644 icons/SavvyIcon.png "$ICON_PATH" +trap - ERR + +echo "SavvyCAN is installed."