testing
This commit is contained in:
parent
c811cea4b3
commit
55d75c6e4b
1 changed files with 154 additions and 154 deletions
74
distros.sh
74
distros.sh
|
@ -1,48 +1,47 @@
|
||||||
#!/usr/bin/env bash
|
{
|
||||||
|
distro=""
|
||||||
|
ubuntu="false"
|
||||||
|
debian="false"
|
||||||
|
arch="false"
|
||||||
|
fedora="false"
|
||||||
|
alpine="false"
|
||||||
|
opensuse="false"
|
||||||
|
|
||||||
distro=""
|
# ─< ANSI color codes >───────────────────────────────────────────────────────────────────
|
||||||
ubuntu="false"
|
RED='\033[0;31m'
|
||||||
debian="false"
|
CYAN='\033[0;36m'
|
||||||
arch="false"
|
YELLOW='\033[0;33m'
|
||||||
fedora="false"
|
LIGHT_GREEN='\033[0;92m'
|
||||||
alpine="false"
|
BOLD='\033[1m'
|
||||||
opensuse="false"
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
# ─< ANSI color codes >───────────────────────────────────────────────────────────────────
|
echo_error() {
|
||||||
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
|
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."
|
||||||
|
@ -55,10 +54,10 @@ check_root() {
|
||||||
echo_info "Root access confirmed."
|
echo_info "Root access confirmed."
|
||||||
_sudo=""
|
_sudo=""
|
||||||
fi
|
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
|
||||||
|
@ -157,9 +156,9 @@ get_packager() {
|
||||||
echo_error "Unable to detect distribution. /etc/os-release not found."
|
echo_error "Unable to detect distribution. /etc/os-release not found."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if check_root; then
|
if check_root; then
|
||||||
get_packager &&
|
get_packager &&
|
||||||
if $arch; then
|
if $arch; then
|
||||||
echo "Arch it is.."
|
echo "Arch it is.."
|
||||||
|
@ -175,4 +174,5 @@ if check_root; then
|
||||||
echo "Alpine it is.."
|
echo "Alpine it is.."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue