From 8385e38a0d96c4be2450b8bc00e006be1617ea4a Mon Sep 17 00:00:00 2001 From: Adam Perkowski Date: Fri, 20 Sep 2024 06:01:43 +0200 Subject: [PATCH] Add a Linutil package installation & update script (#526) * AUR Installation * Finished the scripts * Forgot about $RC * Fixed func name * oopsie 2 * Replaced `jq` with `grep` --- .../applications-setup/linutil-installer.sh | 62 +++++++++++++++++++ .../applications-setup/linutil-updater.sh | 45 ++++++++++++++ core/tabs/applications-setup/tab_data.toml | 20 ++++++ 3 files changed, 127 insertions(+) create mode 100755 core/tabs/applications-setup/linutil-installer.sh create mode 100755 core/tabs/applications-setup/linutil-updater.sh diff --git a/core/tabs/applications-setup/linutil-installer.sh b/core/tabs/applications-setup/linutil-installer.sh new file mode 100755 index 00000000..7fbb09a6 --- /dev/null +++ b/core/tabs/applications-setup/linutil-installer.sh @@ -0,0 +1,62 @@ +#!/bin/sh -e + +. ../common-script.sh + +installLinutil() { + printf "%b\n" "${YELLOW}Installing Linutil...${RC}" + case "$PACKAGER" in + pacman) + printf "%b\n" "-----------------------------------------------------" + printf "%b\n" "Select the package to install:" + printf "%b\n" "1. ${CYAN}linutil${RC} (stable release compiled from source)" + printf "%b\n" "2. ${CYAN}linutil-bin${RC} (stable release pre-compiled)" + printf "%b\n" "3. ${CYAN}linutil-git${RC} (compiled from the latest commit)" + printf "%b\n" "-----------------------------------------------------" + printf "%b" "Enter your choice: " + read -r choice + case $choice in + 1) "$AUR_HELPER" -S --noconfirm linutil ;; + 2) "$AUR_HELPER" -S --noconfirm linutil-bin ;; + 3) "$AUR_HELPER" -S --noconfirm linutil-git ;; + *) + printf "%b\n" "${RED}Invalid choice:${RC} $choice" + exit 1 + ;; + esac + printf "%b\n" "${GREEN}Installed successfully.${RC}" + ;; + *) + printf "%b\n" "${RED}There are no official packages for your distro.${RC}" + printf "%b" "${YELLOW}Do you want to install the crates.io package? (y/N) ${RC}" + read -r choice + case $choice in + y|Y) + if ! command_exists cargo; then + printf "%b\n" "${YELLOW}Installing rustup...${RC}" + case "$PACKAGER" in + pacman) + "$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm rustup + ;; + zypper) + "$ESCALATION_TOOL" "$PACKAGER" install -n curl gcc make + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh + . $HOME/.cargo/env + ;; + *) + "$ESCALATION_TOOL" "$PACKAGER" install -y rustup + ;; + esac + fi + rustup default stable + cargo install --force linutil_tui + printf "%b\n" "${GREEN}Installed successfully.${RC}" + ;; + *) printf "%b\n" "${RED}Linutil not installed.${RC}" ;; + esac + esac +} + +checkEnv +checkEscalationTool +checkAURHelper +installLinutil diff --git a/core/tabs/applications-setup/linutil-updater.sh b/core/tabs/applications-setup/linutil-updater.sh new file mode 100755 index 00000000..8cf1762d --- /dev/null +++ b/core/tabs/applications-setup/linutil-updater.sh @@ -0,0 +1,45 @@ +#!/bin/sh -e + +. ../common-script.sh + +updateLinutil() { + if [ ! -e "$HOME/.cargo/bin/linutil" ]; then + printf "%b\n" "${RED}This script only updates the binary installed through cargo.\nlinutil_tui is not installed.${RC}" + exit 1 + fi + + if ! command_exists cargo; then + printf "%b\n" "${YELLOW}Installing rustup...${RC}" + case "$PACKAGER" in + pacman) + "$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm rustup + ;; + zypper) + "$ESCALATION_TOOL" "$PACKAGER" install -n curl gcc make + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh + . $HOME/.cargo/env + ;; + *) + "$ESCALATION_TOOL" "$PACKAGER" install -y rustup + ;; + esac + fi + + INSTALLED_VERSION=$(cargo install --list | grep "linutil_tui" | awk '{print $2}' | tr -d 'v:') + LATEST_VERSION=$(curl -s https://crates.io/api/v1/crates/linutil_tui | grep -oP '"max_version":\s*"\K[^"]+') + + if [ "$INSTALLED_VERSION" = "$LATEST_VERSION" ]; then + printf "%b\n" "${GREEN}linutil_tui is up to date.${RC}" + exit 0 + fi + + printf "%b\n" "${YELLOW}Updating linutil_tui...${RC}" + rustup default stable + cargo install --force linutil_tui + printf "%b\n" "${GREEN}Updated successfully.${RC}" +} + +checkEnv +checkEscalationTool +checkAURHelper +updateLinutil diff --git a/core/tabs/applications-setup/tab_data.toml b/core/tabs/applications-setup/tab_data.toml index 0a8633b1..c0480ef7 100644 --- a/core/tabs/applications-setup/tab_data.toml +++ b/core/tabs/applications-setup/tab_data.toml @@ -53,3 +53,23 @@ script = "rofi-setup.sh" name = "ZSH Prompt" description = "The Z shell is a Unix shell that can be used as an interactive login shell and as a command interpreter for shell scripting. Zsh is an extended Bourne shell with many improvements, including some features of Bash, ksh, and tcsh.\nThis command installs ZSH prompt and provides basic configuration." script = "zsh-setup.sh" + +[[data]] +name = "Install Linutil" +description = "Installs a distro-specific Linutil package locally." +script = "linutil-installer.sh" + +[[data.preconditions]] +matches = false +data = "command_exists" +values = [ "linutil" ] + +[[data]] +name = "Update Linutil" +description = "Updates your local Linutil crate installation." +script = "linutil-updater.sh" + +[[data.preconditions]] +matches = true +data = "command_exists" +values = [ "linutil" ]