166 lines
4.6 KiB
Bash
Executable file
166 lines
4.6 KiB
Bash
Executable file
distro=""
|
|
ubuntu="false"
|
|
debian="false"
|
|
arch="false"
|
|
fedora="false"
|
|
alpine="false"
|
|
opensuse="false"
|
|
|
|
# ─< 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
|
|
|
|
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
|
|
}
|
|
silentexec() {
|
|
echo_note "Refreshing repositories.."
|
|
"$@" >/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 -E"
|
|
else
|
|
echo_error "No sudo found and you're not root! Can't install packages."
|
|
return 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
|
|
|
|
# ─< Convert $ID and $ID_LIKE to lowercase >──────────────────────────────────────────────
|
|
ID=$(printf "%s" "$ID" | tr '[:upper:]' '[:lower:]')
|
|
ID_LIKE=$(printf "%s" "$ID_LIKE" | tr '[:upper:]' '[:lower:]')
|
|
|
|
case "$ID" in
|
|
ubuntu | pop)
|
|
ubuntu="true"
|
|
distro="ubuntu"
|
|
_install() { $_sudo apt-get install --assume-yes "$@"; }
|
|
;;
|
|
debian)
|
|
debian="true"
|
|
distro="debian"
|
|
_install() { $_sudo apt-get install --assume-yes "$@"; }
|
|
;;
|
|
fedora)
|
|
fedora="true"
|
|
distro="fedora"
|
|
_install() { $_sudo dnf install -y "$@"; }
|
|
;;
|
|
alpine)
|
|
alpine="true"
|
|
distro="alpine"
|
|
_install() { $_sudo apk add "$@"; }
|
|
;;
|
|
arch | manjaro | garuda | endeavour)
|
|
arch="true"
|
|
distro="arch"
|
|
_install() {
|
|
if command_exists paru; then
|
|
echo_info "Using paru"
|
|
paru -S --noconfirm "$@"
|
|
elif command_exists yay; then
|
|
echo_info "Using yay"
|
|
yay -S --noconfirm "$@"
|
|
else
|
|
echo_warning "Using pacman"
|
|
$_sudo pacman -S --noconfirm "$@"
|
|
fi
|
|
}
|
|
;;
|
|
opensuse*)
|
|
opensuse="true"
|
|
distro="opensuse"
|
|
_install() { $_sudo zypper in "$@"; }
|
|
;;
|
|
*)
|
|
if [ "${ID_LIKE#*debian}" != "$ID_LIKE" ]; then
|
|
debian="true"
|
|
distro="debian"
|
|
_install() { $_sudo apt-get install --assume-yes "$@"; }
|
|
elif [ "${ID_LIKE#*ubuntu}" != "$ID_LIKE" ]; then
|
|
ubuntu="true"
|
|
distro="ubuntu"
|
|
_install() { $_sudo apt-get install --assume-yes "$@"; }
|
|
elif [ "${ID_LIKE#*arch}" != "$ID_LIKE" ]; then
|
|
arch="true"
|
|
distro="arch"
|
|
_install() { $_sudo pacman -S --noconfirm "$@"; }
|
|
elif [ "${ID_LIKE#*fedora}" != "$ID_LIKE" ]; then
|
|
fedora="true"
|
|
distro="fedora"
|
|
_install() { $_sudo dnf install -y "$@"; }
|
|
elif [ "${ID_LIKE#*suse}" != "$ID_LIKE" ]; then
|
|
opensuse="true"
|
|
distro="opensuse"
|
|
_install() { $_sudo zypper in "$@"; }
|
|
else
|
|
echo_error "Unsupported distribution: $ID"
|
|
exit 1
|
|
fi
|
|
;;
|
|
esac
|
|
else
|
|
echo_error "Unable to detect distribution. /etc/os-release not found."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
update_package_list() {
|
|
case "$distro" in
|
|
ubuntu | debian) silentexec $_sudo apt-get update ;;
|
|
fedora) silentexec $_sudo dnf update ;;
|
|
arch)
|
|
if command_exists paru; then
|
|
silentexec paru -Sy
|
|
elif command_exists yay; then
|
|
silentexec yay -Sy
|
|
else
|
|
silentexec $_sudo pacman -Sy
|
|
fi
|
|
;;
|
|
opensuse) silentexec $_sudo zypper ref ;;
|
|
alpine) silentexec $_sudo apk update ;;
|
|
*) echo_error "Unsupported distribution: $distro" ;;
|
|
esac
|
|
}
|
|
|
|
if check_root; then
|
|
get_packager &&
|
|
update_package_list
|
|
|
|
fi
|