This commit is contained in:
pika 2025-05-08 17:28:54 +02:00
parent 84f4eb037e
commit 756b6e14f0

View file

@ -1,93 +1,28 @@
#!/usr/bin/env bash
# ANSI color codes
RED='\033[0;31m'
CYAN='\033[0;36m'
YELLOW='\033[0;33m'
LIGHT_GREEN='\033[0;92m'
BOLD='\033[1m'
NC='\033[0m' # No Color
pkgOption=""
echo_error() {
printf "${BOLD}${RED}ERROR: ${NC}${RED}%s${NC}\n" "$1" >&2
}
echo_info() {
printf "${BOLD}${CYAN}INFO: ${NC}${CYAN}%s${NC}\n" "$1"
}
echo_warning() {
printf "${BOLD}${YELLOW}WARNING: ${NC}${YELLOW}%s${NC}\n" "$1"
}
echo_note() {
printf "${BOLD}${LIGHT_GREEN}NOTE: ${NC}${LIGHT_GREEN}%s${NC}\n" "$1"
}
# ─< Check if the given command exists silently >─────────────────────────────────────────
command_exists() {
command -v "$@" >/dev/null 2>&1
}
# ─< Check if the user is root and set sudo variable if necessary >───────────────────────
check_root() {
if [ "$(id -u)" -ne 0 ]; then
if command_exists sudo; then
echo_info "User is not root. Using sudo for privileged operations."
_sudo="sudo"
# WHY:
# This import will give you the following variables:
# _sudo="sudo -E" <- only if non root user
# distro = <distro name, like 'arch', 'debian', 'fedora'..>
# arch = bool
# fedora = bool
# opensuse = bool....
# You can then use it for, `if $arch; then`
# Also this gives you the _install command, which installs a package pased on the packagemanager/distro used.
# CAUTION:
# This only wokrs for generic package names, like neovim, or vim, or tmux etc..
# not every package packagemanager has the same packagenames for their packages..
if command_exists curl; then
eval "$(curl -fsSL https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh)"
else
echo_error "No sudo found and you're not root! Can't install packages."
return 1
echo "curl is required, but missing.."
exit 1
fi
else
echo_info "Root access confirmed."
_sudo=""
fi
}
# ─< Distribution detection and installation >────────────────────────────────────────
get_packager() {
if [ -e /etc/os-release ]; then
echo_info "Detecting distribution..."
. /etc/os-release
ID=$(printf "%s" "$ID" | tr '[:upper:]' '[:lower:]')
ID_LIKE=$(printf "%s" "$ID_LIKE" | tr '[:upper:]' '[:lower:]')
case "$ID" in
ubuntu | pop) _install() { $_sudo apt-get install --assume-yes "$@"; } ;;
debian) _install() { $_sudo apt-get install --assume-yes "$@"; } ;;
fedora) _install() { $_sudo dnf install -y "$@"; } ;;
alpine) _install() { $_sudo apk add "$@"; } ;;
arch | archcraft | manjaro | garuda | endeavour) _install() { $_sudo pacman -S --noconfirm "$@"; } ;;
opensuse*) _install() { $_sudo zypper in -y "$@"; } ;;
*)
if echo "$ID_LIKE" | grep -q "debian"; then
_install() { $_sudo apt-get install --assume-yes "$@"; }
elif echo "$ID_LIKE" | grep -q "ubuntu"; then
_install() { $_sudo apt-get install --assume-yes "$@"; }
elif echo "$ID_LIKE" | grep -q "arch"; then
_install() { $_sudo pacman -S --noconfirm "$@"; }
elif echo "$ID_LIKE" | grep -q "fedora"; then
_install() { $_sudo dnf install -y "$@"; }
elif echo "$ID_LIKE" | grep -q "suse"; then
_install() { $_sudo zypper in -y "$@"; }
else
echo_error "Unsupported distribution: $ID"
return 1
fi
;;
esac
else
echo_error "Unable to detect distribution. /etc/os-release not found."
return 1
fi
}
silentexec() {
"$@" >/dev/null 2>&1
}
__pre_stow__() {
echo_note "__pre_stow__"
@ -106,7 +41,7 @@ __pre_stow__() {
if [ ! -d "$bak_dir" ]; then
echo_info "backup dir created at $bak_dir" &&
silentexec mkdir "$bak_dir"
mkdir "$bak_dir"
else
echo_info "Backup dir already present, clearing now" &&
rm -rf "${bak_dir:?}/*"
@ -251,12 +186,23 @@ __dep__() {
)
for hyprdots_dependency in "${_depss[@]}"; do
case "$hyprdots_dependency" in
zellij)
if ! command_exists "$hyprdots_dependency"; then
eval "$(curl -fsSL https://git.k4li.de/scripts/installs/raw/branch/main/zellij.sh)"
else
echo_info "$hyprdots_dependency is already installed"
fi
;;
*)
if ! command_exists "$hyprdots_dependency"; then
echo_note "--- installing $hyprdots_dependency ---"
_install "$hyprdots_dependency"
else
echo_info "$hyprdots_dependency is already installed"
fi
;;
esac
done
}
@ -277,7 +223,6 @@ pkg_optional() {
_install "$_o_"
fi
done
;;
*)
echo default