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 #!/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 >───────────────────────────────────────── # ─< Check if the given command exists silently >─────────────────────────────────────────
command_exists() { command_exists() {
command -v "$@" >/dev/null 2>&1 command -v "$@" >/dev/null 2>&1
} }
# ─< Check if the user is root and set sudo variable if necessary >─────────────────────── # WHY:
check_root() { # This import will give you the following variables:
if [ "$(id -u)" -ne 0 ]; then # _sudo="sudo -E" <- only if non root user
if command_exists sudo; then # distro = <distro name, like 'arch', 'debian', 'fedora'..>
echo_info "User is not root. Using sudo for privileged operations." # arch = bool
_sudo="sudo" # fedora = bool
else # opensuse = bool....
echo_error "No sudo found and you're not root! Can't install packages." # You can then use it for, `if $arch; then`
return 1 # Also this gives you the _install command, which installs a package pased on the packagemanager/distro used.
fi # CAUTION:
else # This only wokrs for generic package names, like neovim, or vim, or tmux etc..
echo_info "Root access confirmed." # not every package packagemanager has the same packagenames for their packages..
_sudo="" if command_exists curl; then
fi eval "$(curl -fsSL https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh)"
} else
echo "curl is required, but missing.."
# ─< Distribution detection and installation >──────────────────────────────────────── exit 1
get_packager() { fi
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__() { __pre_stow__() {
echo_note "__pre_stow__" echo_note "__pre_stow__"
@ -106,7 +41,7 @@ __pre_stow__() {
if [ ! -d "$bak_dir" ]; then if [ ! -d "$bak_dir" ]; then
echo_info "backup dir created at $bak_dir" && echo_info "backup dir created at $bak_dir" &&
silentexec mkdir "$bak_dir" mkdir "$bak_dir"
else else
echo_info "Backup dir already present, clearing now" && echo_info "Backup dir already present, clearing now" &&
rm -rf "${bak_dir:?}/*" rm -rf "${bak_dir:?}/*"
@ -251,12 +186,23 @@ __dep__() {
) )
for hyprdots_dependency in "${_depss[@]}"; do for hyprdots_dependency in "${_depss[@]}"; do
if ! command_exists "$hyprdots_dependency"; then case "$hyprdots_dependency" in
echo_note "--- installing $hyprdots_dependency ---" zellij)
_install "$hyprdots_dependency" if ! command_exists "$hyprdots_dependency"; then
else eval "$(curl -fsSL https://git.k4li.de/scripts/installs/raw/branch/main/zellij.sh)"
echo_info "$hyprdots_dependency is already installed" else
fi 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 done
} }
@ -277,7 +223,6 @@ pkg_optional() {
_install "$_o_" _install "$_o_"
fi fi
done done
;; ;;
*) *)
echo default echo default