wip
This commit is contained in:
parent
55d75c6e4b
commit
3785b242c8
1 changed files with 149 additions and 151 deletions
300
distros.sh
300
distros.sh
|
@ -1,178 +1,176 @@
|
||||||
{
|
distro=""
|
||||||
distro=""
|
ubuntu="false"
|
||||||
ubuntu="false"
|
debian="false"
|
||||||
debian="false"
|
arch="false"
|
||||||
arch="false"
|
fedora="false"
|
||||||
fedora="false"
|
alpine="false"
|
||||||
alpine="false"
|
opensuse="false"
|
||||||
opensuse="false"
|
|
||||||
|
|
||||||
# ─< ANSI color codes >───────────────────────────────────────────────────────────────────
|
# ─< ANSI color codes >───────────────────────────────────────────────────────────────────
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
CYAN='\033[0;36m'
|
CYAN='\033[0;36m'
|
||||||
YELLOW='\033[0;33m'
|
YELLOW='\033[0;33m'
|
||||||
LIGHT_GREEN='\033[0;92m'
|
LIGHT_GREEN='\033[0;92m'
|
||||||
BOLD='\033[1m'
|
BOLD='\033[1m'
|
||||||
NC='\033[0m' # No Color
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
echo_error() {
|
echo_error() {
|
||||||
printf "${BOLD}${RED}ERROR: ${NC}${RED}%s${NC}\n" "$1" >&2
|
printf "${BOLD}${RED}ERROR: ${NC}${RED}%s${NC}\n" "$1" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
echo_info() {
|
echo_info() {
|
||||||
printf "${BOLD}${CYAN}INFO: ${NC}${CYAN}%s${NC}\n" "$1"
|
printf "${BOLD}${CYAN}INFO: ${NC}${CYAN}%s${NC}\n" "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo_warning() {
|
echo_warning() {
|
||||||
printf "${BOLD}${YELLOW}WARNING: ${NC}${YELLOW}%s${NC}\n" "$1"
|
printf "${BOLD}${YELLOW}WARNING: ${NC}${YELLOW}%s${NC}\n" "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo_note() {
|
echo_note() {
|
||||||
printf "${BOLD}${LIGHT_GREEN}NOTE: ${NC}${LIGHT_GREEN}%s${NC}\n" "$1"
|
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
|
||||||
}
|
}
|
||||||
silentexec() {
|
silentexec() {
|
||||||
echo_note "Refreshing repositories.."
|
echo_note "Refreshing repositories.."
|
||||||
"$@" >/dev/null 2>&1
|
"$@" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
# ─< Check if the user is root and set sudo variable if necessary >───────────────────────
|
# ─< Check if the user is root and set sudo variable if necessary >───────────────────────
|
||||||
check_root() {
|
check_root() {
|
||||||
if [ "$(id -u)" -ne 0 ]; then
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
if command_exists sudo; then
|
if command_exists sudo; then
|
||||||
echo_info "User is not root. Using sudo for privileged operations."
|
echo_info "User is not root. Using sudo for privileged operations."
|
||||||
_sudo="sudo -E"
|
_sudo="sudo -E"
|
||||||
else
|
|
||||||
echo_error "No sudo found and you're not root! Can't install packages."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo_info "Root access confirmed."
|
echo_error "No sudo found and you're not root! Can't install packages."
|
||||||
_sudo=""
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
else
|
||||||
|
echo_info "Root access confirmed."
|
||||||
|
_sudo=""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# ─< Distribution detection and installation >────────────────────────────────────────
|
# ─< Distribution detection and installation >────────────────────────────────────────
|
||||||
get_packager() {
|
get_packager() {
|
||||||
if [ -e /etc/os-release ]; then
|
if [ -e /etc/os-release ]; then
|
||||||
echo_info "Detecting distribution..."
|
echo_info "Detecting distribution..."
|
||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
|
|
||||||
# ─< Convert $ID and $ID_LIKE to lowercase >──────────────────────────────────────────────
|
# ─< Convert $ID and $ID_LIKE to lowercase >──────────────────────────────────────────────
|
||||||
ID=$(printf "%s" "$ID" | tr '[:upper:]' '[:lower:]')
|
ID=$(printf "%s" "$ID" | tr '[:upper:]' '[:lower:]')
|
||||||
ID_LIKE=$(printf "%s" "$ID_LIKE" | tr '[:upper:]' '[:lower:]')
|
ID_LIKE=$(printf "%s" "$ID_LIKE" | tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
case "$ID" in
|
case "$ID" in
|
||||||
ubuntu | pop)
|
ubuntu | pop)
|
||||||
ubuntu="true"
|
ubuntu="true"
|
||||||
distro="ubuntu"
|
distro="ubuntu"
|
||||||
_install() { $_sudo apt-get install --assume-yes "$@"; }
|
_install() { $_sudo apt-get install --assume-yes "$@"; }
|
||||||
silentexec $_sudo apt-get update
|
silentexec $_sudo apt-get update
|
||||||
;;
|
;;
|
||||||
debian)
|
debian)
|
||||||
|
debian="true"
|
||||||
|
distro="debian"
|
||||||
|
_install() { $_sudo apt-get install --assume-yes "$@"; }
|
||||||
|
silentexec $_sudo apt-get update
|
||||||
|
;;
|
||||||
|
fedora)
|
||||||
|
fedora="true"
|
||||||
|
distro="fedora"
|
||||||
|
_install() { $_sudo dnf install -y "$@"; }
|
||||||
|
silentexec $_sudo dnf update
|
||||||
|
;;
|
||||||
|
alpine)
|
||||||
|
alpine="true"
|
||||||
|
distro="alpine"
|
||||||
|
_install() { $_sudo apk add "$@"; }
|
||||||
|
silentexec $_sudo apk update
|
||||||
|
;;
|
||||||
|
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
|
||||||
|
}
|
||||||
|
if command_exists paru; then
|
||||||
|
silentexec paru -Sy
|
||||||
|
elif command_exists yay; then
|
||||||
|
silentexec yay -Sy
|
||||||
|
else
|
||||||
|
silentexec $_sudo pacman -Sy
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
opensuse*)
|
||||||
|
opensuse="true"
|
||||||
|
distro="opensuse"
|
||||||
|
_install() { $_sudo zypper in "$@"; }
|
||||||
|
silentexec $_sudo zypper ref
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [ "${ID_LIKE#*debian}" != "$ID_LIKE" ]; then
|
||||||
debian="true"
|
debian="true"
|
||||||
distro="debian"
|
distro="debian"
|
||||||
_install() { $_sudo apt-get install --assume-yes "$@"; }
|
_install() { $_sudo apt-get install --assume-yes "$@"; }
|
||||||
silentexec $_sudo apt-get update
|
silentexec $_sudo apt-get update
|
||||||
;;
|
elif [ "${ID_LIKE#*ubuntu}" != "$ID_LIKE" ]; then
|
||||||
fedora)
|
ubuntu="true"
|
||||||
|
distro="ubuntu"
|
||||||
|
_install() { $_sudo apt-get install --assume-yes "$@"; }
|
||||||
|
silentexec $_sudo apt-get update
|
||||||
|
elif [ "${ID_LIKE#*arch}" != "$ID_LIKE" ]; then
|
||||||
|
arch="true"
|
||||||
|
distro="arch"
|
||||||
|
_install() { $_sudo pacman -S --noconfirm "$@"; }
|
||||||
|
silentexec $_sudo pacman -Sy
|
||||||
|
elif [ "${ID_LIKE#*fedora}" != "$ID_LIKE" ]; then
|
||||||
fedora="true"
|
fedora="true"
|
||||||
distro="fedora"
|
distro="fedora"
|
||||||
_install() { $_sudo dnf install -y "$@"; }
|
_install() { $_sudo dnf install -y "$@"; }
|
||||||
silentexec $_sudo dnf update
|
silentexec $_sudo dnf update
|
||||||
;;
|
elif [ "${ID_LIKE#*suse}" != "$ID_LIKE" ]; then
|
||||||
alpine)
|
|
||||||
alpine="true"
|
|
||||||
distro="alpine"
|
|
||||||
_install() { $_sudo apk add "$@"; }
|
|
||||||
silentexec $_sudo apk update
|
|
||||||
;;
|
|
||||||
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
|
|
||||||
}
|
|
||||||
if command_exists paru; then
|
|
||||||
silentexec paru -Sy
|
|
||||||
elif command_exists yay; then
|
|
||||||
silentexec yay -Sy
|
|
||||||
else
|
|
||||||
silentexec $_sudo pacman -Sy
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
opensuse*)
|
|
||||||
opensuse="true"
|
opensuse="true"
|
||||||
distro="opensuse"
|
distro="opensuse"
|
||||||
_install() { $_sudo zypper in "$@"; }
|
_install() { $_sudo zypper in "$@"; }
|
||||||
silentexec $_sudo zypper ref
|
silentexec $_sudo zypper ref
|
||||||
;;
|
else
|
||||||
*)
|
echo_error "Unsupported distribution: $ID"
|
||||||
if [ "${ID_LIKE#*debian}" != "$ID_LIKE" ]; then
|
exit 1
|
||||||
debian="true"
|
|
||||||
distro="debian"
|
|
||||||
_install() { $_sudo apt-get install --assume-yes "$@"; }
|
|
||||||
silentexec $_sudo apt-get update
|
|
||||||
elif [ "${ID_LIKE#*ubuntu}" != "$ID_LIKE" ]; then
|
|
||||||
ubuntu="true"
|
|
||||||
distro="ubuntu"
|
|
||||||
_install() { $_sudo apt-get install --assume-yes "$@"; }
|
|
||||||
silentexec $_sudo apt-get update
|
|
||||||
elif [ "${ID_LIKE#*arch}" != "$ID_LIKE" ]; then
|
|
||||||
arch="true"
|
|
||||||
distro="arch"
|
|
||||||
_install() { $_sudo pacman -S --noconfirm "$@"; }
|
|
||||||
silentexec $_sudo pacman -Sy
|
|
||||||
elif [ "${ID_LIKE#*fedora}" != "$ID_LIKE" ]; then
|
|
||||||
fedora="true"
|
|
||||||
distro="fedora"
|
|
||||||
_install() { $_sudo dnf install -y "$@"; }
|
|
||||||
silentexec $_sudo dnf update
|
|
||||||
elif [ "${ID_LIKE#*suse}" != "$ID_LIKE" ]; then
|
|
||||||
opensuse="true"
|
|
||||||
distro="opensuse"
|
|
||||||
_install() { $_sudo zypper in "$@"; }
|
|
||||||
silentexec $_sudo zypper ref
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
if check_root; then
|
|
||||||
get_packager &&
|
|
||||||
if $arch; then
|
|
||||||
echo "Arch it is.."
|
|
||||||
elif $debian; then
|
|
||||||
echo "Debian it is.."
|
|
||||||
elif $ubuntu; then
|
|
||||||
echo "Ubuntu it is.."
|
|
||||||
elif $fedora; then
|
|
||||||
echo "Fedora it is.."
|
|
||||||
elif $opensuse; then
|
|
||||||
echo "OpenSuse it is.."
|
|
||||||
elif $alpine; then
|
|
||||||
echo "Alpine it is.."
|
|
||||||
fi
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
echo_error "Unable to detect distribution. /etc/os-release not found."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if check_root; then
|
||||||
|
get_packager &&
|
||||||
|
if $arch; then
|
||||||
|
echo "Arch it is.."
|
||||||
|
elif $debian; then
|
||||||
|
echo "Debian it is.."
|
||||||
|
elif $ubuntu; then
|
||||||
|
echo "Ubuntu it is.."
|
||||||
|
elif $fedora; then
|
||||||
|
echo "Fedora it is.."
|
||||||
|
elif $opensuse; then
|
||||||
|
echo "OpenSuse it is.."
|
||||||
|
elif $alpine; then
|
||||||
|
echo "Alpine it is.."
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue