This commit is contained in:
pika 2025-05-19 15:09:23 +02:00
parent f7801c918a
commit 61957873b9

View file

@ -96,8 +96,8 @@ echo_pkg() {
esac
else
case "$1" in
deps)
echo "${BOLD}${BRIGHT_RED}${PACKAGE:-PKG}-dependencies:${BRIGHT_YELLOW} $2 ${NC}"
deps | dep | dependencies)
echo "${BOLD}${BRIGHT_RED}${PACKAGE:-PKG}-${pkger:-dependencies}:${BRIGHT_YELLOW} $2 ${NC}"
;;
*)
echo "${BOLD}${BRIGHT_RED}${PACKAGE:-PKG}-$1:${NC}${BRIGHT_YELLOW} $2 ${NC}"
@ -205,21 +205,56 @@ check_env() {
fi
}
# CAUTION:
# ╭─────────────────────────────────────────────────────────────────────╮
# │ This can break really quickly, since the _remove() function removes │
# │ without confirmation! use with CAUTION!! │
# ╰─────────────────────────────────────────────────────────────────────╯
_setup() {
case "$1" in
debian | ubuntu)
_install() { $_sudo apt-get install --assume-yes "$@"; }
_install() {
# $_sudo apt-get install --assume-yes "$@"
if command_exists nala; then
pkger=nala
# echo_pkg "Using paru"
$_sudo nala install --assume-yes "$@"
else
pkger=apt-get
# echo_pkg "Using pacman"
$_sudo apt-get install --assume-yes "$@"
fi
}
# CAUTION:
_remove() {
$_sudo apt-get remove --assume-yes "$@"
$_sudo apt-get autoremove --assume-yes
if command_exists nala; then
pkger=nala
# echo_pkg "Using paru"
$_sudo nala remove --assume-yes "$@"
$_sudo nala autoremove --assume-yes
$_sudo nala autopurge --assume-yes
else
pkger=apt-get
# echo_pkg "Using pacman"
$_sudo apt-get remove --assume-yes "$@"
$_sudo apt-get autoremove --assume-yes
fi
}
;;
fedora)
_install() { $_sudo dnf -y install "$@"; }
_remove() { $_sudo dnf -y remove "$@"; }
_install() {
pkger=dnf
$_sudo dnf -y install "$@"
}
# CAUTION:
_remove() {
pkger=dnf
$_sudo dnf -y remove "$@"
}
;;
arch)
checkAUR() {
if ! command_exists yay && ! command_exists paru; then
return 69
@ -230,42 +265,109 @@ _setup() {
_install() {
if command_exists paru; then
echo_pkg "Using paru"
pkger=paru
# echo_pkg "Using paru"
paru -S --color always --noconfirm --needed "$@"
elif command_exists yay; then
echo_pkg "Using yay"
pkger=yay
# echo_pkg "Using yay"
yay -S --color always --noconfirm --needed "$@"
else
echo_pkg "Using pacman"
pkger=pacman
# echo_pkg "Using pacman"
$_sudo pacman -S --color always --noconfirm --needed "$@"
fi
}
# CAUTION:
_remove() {
if command_exists paru; then
echo_info "Using paru"
pkger=paru
# echo_info "Using paru"
paru -R --color always --noconfirm "$@"
elif command_exists yay; then
echo_info "Using yay"
pkger=yay
# echo_info "Using yay"
yay -R --color always --noconfirm "$@"
else
echo_warning "Using pacman"
pkger=pacman
# echo_warning "Using pacman"
$_sudo pacman -R --color always --noconfirm "$@"
fi
}
;;
opensuse)
_install() { $_sudo zypper in "$@"; }
_remove() { $_sudo zypper rem "$@"; }
_install() {
pkger=zypper
$_sudo zypper in "$@"
}
# CAUTION:
_remove() {
pkger=zypper
$_sudo zypper rem "$@"
}
;;
alpine)
_install() { apk add "$@"; }
_remove() { apk remove "$@"; }
_install() {
pkger=apk
apk add "$@"
}
# CAUTION:
_remove() {
pkger=apk
apk remove "$@"
}
;;
esac
}
# ─< Distribution detection and installation >────────────────────────────────────────
get_packager() {
fallback() {
# ─────────────────────────────────────< get packager >─────────────────────────────────────
local pkger=""
for pkg in apt-get dnf pacman apk zypper; do
if command_exists $pkg; then
printf "Using ${RED}${pkg}${NC} method.."
pkger="$pkg"
# break
return 0
fi
done
case "$pkger" in
apt-get)
ubuntu="true"
debian="true"
distro="debian"
;;
dnf)
fedora="true"
distro="fedora"
;;
apk)
alpine="true"
distro="alpine"
;;
pacman)
arch="true"
distro="arch"
;;
zypper)
opensuse="true"
distro="opensuse"
;;
*)
echo_error "Can not detect distribution correctly!"
# echo_error "DEBUG:: $pkger ::"
return 69
;;
esac
}
if [ -e /etc/os-release ]; then
echo_info "Detecting distribution..."
. /etc/os-release
@ -317,54 +419,18 @@ get_packager() {
distro="opensuse"
else
echo_error "Unsupported distribution: $ID"
exit 1
echo_warning "Trying fallback.."
fallback
fi
;;
esac
else
echo_warning "Unable to detect distribution /etc/os-release not found."
echo_warning "Unable to detect distribution - /etc/os-release not found."
echo_note "Trying other methods.."
# ─────────────────────────────────────< get packager >─────────────────────────────────────
pkger=""
for pkg in apt-get dnf pacman apk zypper; do
if command_exists $pkg; then
printf "Using ${RED}${pkg}${NC} method.."
pkger="$pkg"
sleep 3
# break
return 0
fi
done
case "$pkger" in
apt-get)
ubuntu="true"
debian="true"
distro="debian"
;;
dnf)
fedora="true"
distro="fedora"
;;
apk)
alpine="true"
distro="alpine"
;;
pacman)
arch="true"
distro="arch"
;;
zypper)
opensuse="true"
distro="opensuse"
;;
*)
echo_error "Can not detect distribution correctly!"
# echo_error "DEBUG:: $pkger ::"
return 69
;;
esac
fallback
fi
}
@ -435,7 +501,7 @@ update_package_list() {
$_sudo mkdir -p "$paruBuildDir"
# if ! command_exists paru; then
echo "${YELLOW}Installing paru as AUR helper...${NC}"
$_sudo pacman -S --needed --noconfirm base-devel git
run $_sudo pacman -S --needed --noconfirm base-devel git
cd "$paruBuildDir" && $_sudo git clone https://aur.archlinux.org/paru-bin.git paru
$_sudo chown -R "$USER": "$paruBuildDir/paru"
cd "$paruBuildDir/paru" && makepkg --noconfirm -si