wip
This commit is contained in:
parent
934933c058
commit
201119feb5
1 changed files with 40 additions and 127 deletions
167
distros.sh
Executable file → Normal file
167
distros.sh
Executable file → Normal file
|
@ -10,14 +10,6 @@ fedora="false"
|
|||
alpine="false"
|
||||
opensuse="false"
|
||||
|
||||
# ─< old - 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
|
||||
|
||||
# Basic Colors
|
||||
BLACK=$'\e[30m'
|
||||
RED=$'\e[31m'
|
||||
|
@ -38,26 +30,6 @@ BRIGHT_MAGENTA=$'\e[95m'
|
|||
BRIGHT_CYAN=$'\e[96m'
|
||||
BRIGHT_WHITE=$'\e[97m'
|
||||
|
||||
# Background Colors (standard)
|
||||
BG_BLACK=$'\e[40m'
|
||||
BG_RED=$'\e[41m'
|
||||
BG_GREEN=$'\e[42m'
|
||||
BG_YELLOW=$'\e[43m'
|
||||
BG_BLUE=$'\e[44m'
|
||||
BG_MAGENTA=$'\e[45m'
|
||||
BG_CYAN=$'\e[46m'
|
||||
BG_WHITE=$'\e[47m'
|
||||
|
||||
# Background Bright Colors
|
||||
BG_BRIGHT_BLACK=$'\e[100m'
|
||||
BG_BRIGHT_RED=$'\e[101m'
|
||||
BG_BRIGHT_GREEN=$'\e[102m'
|
||||
BG_BRIGHT_YELLOW=$'\e[103m'
|
||||
BG_BRIGHT_BLUE=$'\e[104m'
|
||||
BG_BRIGHT_MAGENTA=$'\e[105m'
|
||||
BG_BRIGHT_CYAN=$'\e[106m'
|
||||
BG_BRIGHT_WHITE=$'\e[107m'
|
||||
|
||||
# Styles
|
||||
BOLD=$'\e[1m'
|
||||
ITALIC=$'\e[3m'
|
||||
|
@ -69,53 +41,20 @@ STRIKE=$'\e[9m' # Strikethrough
|
|||
# Reset
|
||||
NC=$'\e[0m' # Reset all styles/colors
|
||||
|
||||
echo_error() {
|
||||
echo "${BOLD}${RED}${UNDERLINE}ERROR:${NC}${BRIGHT_RED} $1 ${NC}" >&2
|
||||
}
|
||||
|
||||
echo-error() {
|
||||
echo "${BOLD}${RED}${UNDERLINE}ERROR:${NC}${BRIGHT_RED} $1 ${NC}" >&2
|
||||
}
|
||||
|
||||
# INFO:
|
||||
# ↓ should get set in the install script itself
|
||||
# ↓
|
||||
# echo with $PACKAGE and first argument, if 2 exist
|
||||
echo_pkg() {
|
||||
# if arg 2 does not exist, use normal echo
|
||||
if [[ -z $2 ]]; then
|
||||
case "$1" in
|
||||
build)
|
||||
echo "${BOLD}${BRIGHT_RED}${PACKAGE:-PKG}-build:${NC}${BRIGHT_BLUE} Building $PACKAGE ${NC}"
|
||||
;;
|
||||
clone)
|
||||
echo "${BOLD}${BRIGHT_RED}${PACKAGE:-PKG}-clone:${NC}${BRIGHT_YELLOW} Cloning $PACKAGE sources..${NC}"
|
||||
;;
|
||||
install)
|
||||
echo "${BOLD}${BRIGHT_RED}${PACKAGE:-PKG}-install:${NC}${BRIGHT_GREEN} Installing $PACKAGE now!${NC}"
|
||||
;;
|
||||
*)
|
||||
echo "${BOLD}${BRIGHT_RED}${PACKAGE:-PKG}:${NC}${YELLOW} $1 ${NC}"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
case "$1" in
|
||||
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}"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
echo_error() {
|
||||
echo-error "$@"
|
||||
}
|
||||
|
||||
echo_info() {
|
||||
echo-info() {
|
||||
echo "${BOLD}${BLUE}INFO:${NC} $1${NC}"
|
||||
}
|
||||
|
||||
echo_info() {
|
||||
echo "${BOLD}${BLUE}INFO:${NC} $1${NC}"
|
||||
echo-info "$@"
|
||||
}
|
||||
|
||||
echo-warning() {
|
||||
|
@ -123,7 +62,7 @@ echo-warning() {
|
|||
}
|
||||
|
||||
echo_warning() {
|
||||
echo "${BOLD}${YELLOW}WARNING:${NC} $1${NC}"
|
||||
echo-warning "$@"
|
||||
}
|
||||
|
||||
echo-note() {
|
||||
|
@ -131,29 +70,18 @@ echo-note() {
|
|||
}
|
||||
|
||||
echo_note() {
|
||||
echo "${BOLD}${GREEN}NOTE:${NC} $1${NC}"
|
||||
echo-note "$@"
|
||||
}
|
||||
|
||||
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
||||
command_exists() {
|
||||
command -v "$@" >/dev/null 2>&1
|
||||
}
|
||||
command-exists() {
|
||||
command -v "$@" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
silentexec() {
|
||||
"$@" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
run-silent() {
|
||||
if [[ -z $silent ]] || ! $silent; then
|
||||
"$@"
|
||||
else
|
||||
silentexec "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# if given an array, it checks if the command is available, and if not - installs all packages in that array one by one
|
||||
checkAndInstall() {
|
||||
local pkg=$1
|
||||
|
@ -161,23 +89,22 @@ checkAndInstall() {
|
|||
# INFO: if it's not a list, then just check and install the package..
|
||||
if [[ -z $2 ]]; then
|
||||
if ! command_exists "$pkg"; then
|
||||
echo_pkg deps "Installing $pkg"
|
||||
if run-silent pkg-install "$pkg"; then
|
||||
echo_pkg deps "Installed $pkg"
|
||||
echo "${GREY}${BOLD}Installing ${GREEN}$pkg${NC}"
|
||||
if pkg-install "$pkg"; then
|
||||
echo "${GREEN}${BOLD}Installed $pkg${NC}"
|
||||
else
|
||||
echo_pkg deps "$pkg is already installed.."
|
||||
echo-error "Installing $pkg"
|
||||
fi
|
||||
else
|
||||
echo_pkg deps "skipping $pkg - as it's ${RED}already installed.."
|
||||
echo "${BOLD}${GREY}$pkg is already installed..${NC}"
|
||||
fi
|
||||
else
|
||||
# ─< else go though the list of items and do the same >───────────────────────────────────
|
||||
echo_pkg deps "${BRIGHT_YELLOW}Installing ${RED}${#@}${BRIGHT_YELLOW} packages..${NC}"
|
||||
echo_pkg deps "${BRIGHT_BLUE} $* ${NC}"
|
||||
echo "${BRIGHT_YELLOW}Installing ${RED}${#@}${BRIGHT_YELLOW} packages..${NC}"
|
||||
# echo "${BRIGHT_BLUE} $* ${NC}"
|
||||
for deps in "${@}"; do
|
||||
# echo_pkg deps "Installing $deps"
|
||||
if ! command_exists $deps; then
|
||||
if run-silent pkg-install "$deps"; then
|
||||
if pkg-install "$deps"; then
|
||||
echo_pkg deps "$deps - ${GREEN}installed"
|
||||
else
|
||||
echo_pkg deps "$deps is already installed.."
|
||||
|
@ -190,13 +117,13 @@ checkAndInstall() {
|
|||
}
|
||||
|
||||
# ─< Check if the user is root and set sudo variable if necessary >───────────────────────
|
||||
check_env() {
|
||||
check-environment() {
|
||||
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."
|
||||
echo-error "No sudo found and you're not root! Can't install packages."
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
|
@ -285,16 +212,10 @@ _setup() {
|
|||
|
||||
pkg-install() {
|
||||
if command_exists paru; then
|
||||
pkger=paru
|
||||
# echo_pkg "Using paru"
|
||||
paru -S --color always --noconfirm --needed "$@"
|
||||
elif command_exists yay; then
|
||||
pkger=yay
|
||||
# echo_pkg "Using yay"
|
||||
yay -S --color always --noconfirm --needed "$@"
|
||||
else
|
||||
pkger=pacman
|
||||
# echo_pkg "Using pacman"
|
||||
$_sudo pacman -S --color always --noconfirm --needed "$@"
|
||||
fi
|
||||
}
|
||||
|
@ -302,49 +223,39 @@ _setup() {
|
|||
# CAUTION:
|
||||
pkg-remove() {
|
||||
if command_exists paru; then
|
||||
pkger=paru
|
||||
# echo_info "Using paru"
|
||||
paru -R --color always --noconfirm "$@"
|
||||
elif command_exists yay; then
|
||||
pkger=yay
|
||||
# echo_info "Using yay"
|
||||
yay -R --color always --noconfirm "$@"
|
||||
else
|
||||
pkger=pacman
|
||||
# echo_warning "Using pacman"
|
||||
$_sudo pacman -R --color always --noconfirm "$@"
|
||||
fi
|
||||
}
|
||||
;;
|
||||
opensuse)
|
||||
pkg-install() {
|
||||
pkger=zypper
|
||||
$_sudo zypper in "$@"
|
||||
}
|
||||
|
||||
# CAUTION:
|
||||
pkg-remove() {
|
||||
pkger=zypper
|
||||
$_sudo zypper rem "$@"
|
||||
}
|
||||
;;
|
||||
alpine)
|
||||
pkg-install() {
|
||||
pkger=apk
|
||||
apk add "$@"
|
||||
$_sudo apk add "$@"
|
||||
}
|
||||
|
||||
# CAUTION:
|
||||
pkg-remove() {
|
||||
pkger=apk
|
||||
apk remove "$@"
|
||||
$_sudo apk remove "$@"
|
||||
}
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# ─< Distribution detection and installation >────────────────────────────────────────
|
||||
get_packager() {
|
||||
get-packagemanager() {
|
||||
# ─< define fallback function >───────────────────────────────────────────────────────────
|
||||
fallback() {
|
||||
# ─────────────────────────────────────< get packager >─────────────────────────────────────
|
||||
|
@ -382,8 +293,8 @@ get_packager() {
|
|||
distro="opensuse"
|
||||
;;
|
||||
*)
|
||||
echo_error "Can not detect distribution correctly!"
|
||||
# echo_error "DEBUG:: $pkger ::"
|
||||
echo-error "Can not detect distribution correctly!"
|
||||
# echo-error "DEBUG:: $pkger ::"
|
||||
return 69
|
||||
;;
|
||||
esac
|
||||
|
@ -439,7 +350,7 @@ get_packager() {
|
|||
opensuse="true"
|
||||
distro="opensuse"
|
||||
else
|
||||
echo_error "Unsupported distribution: $ID"
|
||||
echo-error "Unsupported distribution: $ID"
|
||||
echo_warning "Trying fallback.."
|
||||
fallback
|
||||
fi
|
||||
|
@ -460,7 +371,7 @@ get_packager() {
|
|||
# │ Automated setup for refreshing repositories and overall getting the variables to setup │
|
||||
# ╰────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
|
||||
dist_setup() {
|
||||
distro-setup() {
|
||||
case "$distro" in
|
||||
debian)
|
||||
echo "${BOLD}Found ${RED}debian${NC}"
|
||||
|
@ -520,8 +431,8 @@ update_package_list() {
|
|||
|
||||
echo_info "Refreshing repository sources.."
|
||||
case "$distro" in
|
||||
ubuntu | debian) run-silent $_sudo apt-get update ;;
|
||||
fedora) run-silent $_sudo dnf update ;;
|
||||
ubuntu | debian) $_sudo apt-get update ;;
|
||||
fedora) $_sudo dnf update ;;
|
||||
arch)
|
||||
if command_exists pacman; then
|
||||
if ! checkAUR; then
|
||||
|
@ -552,38 +463,40 @@ update_package_list() {
|
|||
sleep 0.01
|
||||
|
||||
if command_exists paru; then
|
||||
run-silent paru -Sy
|
||||
paru -Sy
|
||||
elif command_exists yay; then
|
||||
run-silent yay -Sy
|
||||
yay -Sy
|
||||
else
|
||||
run-silent $_sudo pacman -Sy
|
||||
$_sudo pacman -Sy
|
||||
fi
|
||||
;;
|
||||
opensuse) run-silent $_sudo zypper ref ;;
|
||||
alpine) run-silent $_sudo apk update ;;
|
||||
opensuse) $_sudo zypper ref ;;
|
||||
alpine) $_sudo apk update ;;
|
||||
*)
|
||||
echo_error "Unsupported distribution: ${BRIGHT_RED}$distro"
|
||||
echo-error "Unsupported distribution: ${BRIGHT_RED}$distro"
|
||||
return 69
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
if check_env; then
|
||||
get_packager
|
||||
dist_setup
|
||||
if check-environment; then
|
||||
get-packagemanager
|
||||
distro-setup
|
||||
|
||||
# WHY:
|
||||
# ╭─────────────────────────────────────────────────────────────────────────╮
|
||||
# │ check if the script has run at least once, so that the sources dont │
|
||||
# │ have to get updated again.. │
|
||||
# ╰─────────────────────────────────────────────────────────────────────────╯
|
||||
if [[ -z "$PIKA_INIT" ]]; then
|
||||
echo_pkg "First time importing.."
|
||||
pikaCheckFile="$HOME/.cache/pika_script_detection"
|
||||
|
||||
if update_package_list; then
|
||||
if ! checkFileAge "$pikaCheckFile"; then
|
||||
echo "${BOLD}${GREY}Updating sources..${NC}"
|
||||
|
||||
if update-package-list; then
|
||||
silentexec touch "$pikaCheckFile"
|
||||
fi
|
||||
else
|
||||
echo_pkg "Skipping repo refresh"
|
||||
echo "${BOLD}${GREY}Skipping repo refresh${NC}"
|
||||
fi
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue