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`
This commit is contained in:
Adam Perkowski 2024-09-20 06:01:43 +02:00 committed by GitHub
parent 6a1df3c3a9
commit 8385e38a0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 127 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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" ]