Files
Fishing_Tackle/fish_installer.sh
2025-08-09 08:58:36 +01:00

114 lines
3.1 KiB
Bash

#!/bin/bash
set -euo pipefail
# -------- Platform detection --------
detect_platform() {
if [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"; PKG_MGR="brew"
if ! command -v brew &>/dev/null; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
elif command -v apt &>/dev/null; then
OS="debian"; PKG_MGR="apt"
elif command -v dnf &>/dev/null; then
OS="rhel"; PKG_MGR="dnf"
elif command -v yum &>/dev/null; then
OS="rhel"; PKG_MGR="yum"
elif command -v pacman &>/dev/null; then
OS="arch"; PKG_MGR="pacman"
else
echo "Unsupported platform."; exit 1
fi
}
# -------- Debian repo/key --------
install_gpg_if_needed() {
if [[ "${OS}" == "debian" ]] && ! command -v gpg &>/dev/null; then
sudo apt update && sudo apt install -y gnupg
fi
}
add_fish_repo_debian() {
echo 'deb http://download.opensuse.org/repositories/shells:/fish:/release:/4/Debian_12/ /' \
| sudo tee /etc/apt/sources.list.d/fish.list >/dev/null
curl -fsSL https://download.opensuse.org/repositories/shells:fish:release:4/Debian_12/Release.key \
| gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/fish.gpg >/dev/null
sudo apt update
}
# -------- Install/Update fish --------
install_fish() {
case "$OS" in
debian) add_fish_repo_debian; sudo apt install -y fish ;;
rhel) sudo "$PKG_MGR" install -y fish ;;
arch) sudo pacman -Sy --noconfirm fish ;;
macos) brew install fish ;;
esac
}
update_fish_if_available() {
case "$PKG_MGR" in
apt)
sudo apt update
if apt list --upgradable 2>/dev/null | grep -q "^fish/"; then
sudo apt install -y fish
fi
;;
dnf|yum)
sudo "$PKG_MGR" check-update || true
if "$PKG_MGR" list updates | grep -q "^fish"; then
sudo "$PKG_MGR" update -y fish
fi
;;
pacman)
sudo pacman -Sy --noconfirm
if pacman -Qu | grep -q "^fish"; then
sudo pacman -S --noconfirm fish
fi
;;
brew)
brew update
if brew outdated | grep -q "^fish"; then
brew upgrade fish
fi
;;
esac
}
# -------- Fisher & plugins (stdin isolated) --------
install_fisher() {
curl -fsSL https://git.mycod.in/apt/fish_install/raw/branch/main/install_fisher.fish \
-o /tmp/install_fisher.fish
chmod +x /tmp/install_fisher.fish
fish /tmp/install_fisher.fish </dev/null
}
install_fish_plugins() {
curl -fsSL https://git.mycod.in/apt/fish_install/raw/branch/main/fish_plugins.fish \
-o /tmp/fish_plugins.fish
chmod +x /tmp/fish_plugins.fish
if [[ "${FISH_VERBOSE:-0}" == "1" ]]; then
fish /tmp/fish_plugins.fish </dev/null
else
fish /tmp/fish_plugins.fish </dev/null >/dev/null 2>&1
fi
}
# -------- Main --------
detect_platform
install_gpg_if_needed
if command -v fish &>/dev/null; then
update_fish_if_available
else
install_fish
fi
# Always ensure Fisher and plugins are present (idempotent)
install_fisher
install_fish_plugins
echo "✅ Fish + Fisher + plugins ensured on ${OS}."