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"
|
alpine="false"
|
||||||
opensuse="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
|
# Basic Colors
|
||||||
BLACK=$'\e[30m'
|
BLACK=$'\e[30m'
|
||||||
RED=$'\e[31m'
|
RED=$'\e[31m'
|
||||||
|
@ -38,26 +30,6 @@ BRIGHT_MAGENTA=$'\e[95m'
|
||||||
BRIGHT_CYAN=$'\e[96m'
|
BRIGHT_CYAN=$'\e[96m'
|
||||||
BRIGHT_WHITE=$'\e[97m'
|
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
|
# Styles
|
||||||
BOLD=$'\e[1m'
|
BOLD=$'\e[1m'
|
||||||
ITALIC=$'\e[3m'
|
ITALIC=$'\e[3m'
|
||||||
|
@ -69,53 +41,20 @@ STRIKE=$'\e[9m' # Strikethrough
|
||||||
# Reset
|
# Reset
|
||||||
NC=$'\e[0m' # Reset all styles/colors
|
NC=$'\e[0m' # Reset all styles/colors
|
||||||
|
|
||||||
echo_error() {
|
|
||||||
echo "${BOLD}${RED}${UNDERLINE}ERROR:${NC}${BRIGHT_RED} $1 ${NC}" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
echo-error() {
|
echo-error() {
|
||||||
echo "${BOLD}${RED}${UNDERLINE}ERROR:${NC}${BRIGHT_RED} $1 ${NC}" >&2
|
echo "${BOLD}${RED}${UNDERLINE}ERROR:${NC}${BRIGHT_RED} $1 ${NC}" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
# INFO:
|
echo_error() {
|
||||||
# ↓ should get set in the install script itself
|
echo-error "$@"
|
||||||
# ↓
|
|
||||||
# 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_info() {
|
echo-info() {
|
||||||
echo "${BOLD}${BLUE}INFO:${NC} $1${NC}"
|
echo "${BOLD}${BLUE}INFO:${NC} $1${NC}"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo_info() {
|
echo_info() {
|
||||||
echo "${BOLD}${BLUE}INFO:${NC} $1${NC}"
|
echo-info "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo-warning() {
|
echo-warning() {
|
||||||
|
@ -123,7 +62,7 @@ echo-warning() {
|
||||||
}
|
}
|
||||||
|
|
||||||
echo_warning() {
|
echo_warning() {
|
||||||
echo "${BOLD}${YELLOW}WARNING:${NC} $1${NC}"
|
echo-warning "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo-note() {
|
echo-note() {
|
||||||
|
@ -131,29 +70,18 @@ echo-note() {
|
||||||
}
|
}
|
||||||
|
|
||||||
echo_note() {
|
echo_note() {
|
||||||
echo "${BOLD}${GREEN}NOTE:${NC} $1${NC}"
|
echo-note "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ─< 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
|
||||||
}
|
}
|
||||||
command-exists() {
|
|
||||||
command -v "$@" >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
silentexec() {
|
silentexec() {
|
||||||
"$@" >/dev/null 2>&1
|
"$@" >/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
|
# if given an array, it checks if the command is available, and if not - installs all packages in that array one by one
|
||||||
checkAndInstall() {
|
checkAndInstall() {
|
||||||
local pkg=$1
|
local pkg=$1
|
||||||
|
@ -161,23 +89,22 @@ checkAndInstall() {
|
||||||
# INFO: if it's not a list, then just check and install the package..
|
# INFO: if it's not a list, then just check and install the package..
|
||||||
if [[ -z $2 ]]; then
|
if [[ -z $2 ]]; then
|
||||||
if ! command_exists "$pkg"; then
|
if ! command_exists "$pkg"; then
|
||||||
echo_pkg deps "Installing $pkg"
|
echo "${GREY}${BOLD}Installing ${GREEN}$pkg${NC}"
|
||||||
if run-silent pkg-install "$pkg"; then
|
if pkg-install "$pkg"; then
|
||||||
echo_pkg deps "Installed $pkg"
|
echo "${GREEN}${BOLD}Installed $pkg${NC}"
|
||||||
else
|
else
|
||||||
echo_pkg deps "$pkg is already installed.."
|
echo-error "Installing $pkg"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo_pkg deps "skipping $pkg - as it's ${RED}already installed.."
|
echo "${BOLD}${GREY}$pkg is already installed..${NC}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# ─< else go though the list of items and do the same >───────────────────────────────────
|
# ─< else go though the list of items and do the same >───────────────────────────────────
|
||||||
echo_pkg deps "${BRIGHT_YELLOW}Installing ${RED}${#@}${BRIGHT_YELLOW} packages..${NC}"
|
echo "${BRIGHT_YELLOW}Installing ${RED}${#@}${BRIGHT_YELLOW} packages..${NC}"
|
||||||
echo_pkg deps "${BRIGHT_BLUE} $* ${NC}"
|
# echo "${BRIGHT_BLUE} $* ${NC}"
|
||||||
for deps in "${@}"; do
|
for deps in "${@}"; do
|
||||||
# echo_pkg deps "Installing $deps"
|
|
||||||
if ! command_exists $deps; then
|
if ! command_exists $deps; then
|
||||||
if run-silent pkg-install "$deps"; then
|
if pkg-install "$deps"; then
|
||||||
echo_pkg deps "$deps - ${GREEN}installed"
|
echo_pkg deps "$deps - ${GREEN}installed"
|
||||||
else
|
else
|
||||||
echo_pkg deps "$deps is already installed.."
|
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 if the user is root and set sudo variable if necessary >───────────────────────
|
||||||
check_env() {
|
check-environment() {
|
||||||
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
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
@ -285,16 +212,10 @@ _setup() {
|
||||||
|
|
||||||
pkg-install() {
|
pkg-install() {
|
||||||
if command_exists paru; then
|
if command_exists paru; then
|
||||||
pkger=paru
|
|
||||||
# echo_pkg "Using paru"
|
|
||||||
paru -S --color always --noconfirm --needed "$@"
|
paru -S --color always --noconfirm --needed "$@"
|
||||||
elif command_exists yay; then
|
elif command_exists yay; then
|
||||||
pkger=yay
|
|
||||||
# echo_pkg "Using yay"
|
|
||||||
yay -S --color always --noconfirm --needed "$@"
|
yay -S --color always --noconfirm --needed "$@"
|
||||||
else
|
else
|
||||||
pkger=pacman
|
|
||||||
# echo_pkg "Using pacman"
|
|
||||||
$_sudo pacman -S --color always --noconfirm --needed "$@"
|
$_sudo pacman -S --color always --noconfirm --needed "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -302,49 +223,39 @@ _setup() {
|
||||||
# CAUTION:
|
# CAUTION:
|
||||||
pkg-remove() {
|
pkg-remove() {
|
||||||
if command_exists paru; then
|
if command_exists paru; then
|
||||||
pkger=paru
|
|
||||||
# echo_info "Using paru"
|
|
||||||
paru -R --color always --noconfirm "$@"
|
paru -R --color always --noconfirm "$@"
|
||||||
elif command_exists yay; then
|
elif command_exists yay; then
|
||||||
pkger=yay
|
|
||||||
# echo_info "Using yay"
|
|
||||||
yay -R --color always --noconfirm "$@"
|
yay -R --color always --noconfirm "$@"
|
||||||
else
|
else
|
||||||
pkger=pacman
|
|
||||||
# echo_warning "Using pacman"
|
|
||||||
$_sudo pacman -R --color always --noconfirm "$@"
|
$_sudo pacman -R --color always --noconfirm "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
;;
|
;;
|
||||||
opensuse)
|
opensuse)
|
||||||
pkg-install() {
|
pkg-install() {
|
||||||
pkger=zypper
|
|
||||||
$_sudo zypper in "$@"
|
$_sudo zypper in "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# CAUTION:
|
# CAUTION:
|
||||||
pkg-remove() {
|
pkg-remove() {
|
||||||
pkger=zypper
|
|
||||||
$_sudo zypper rem "$@"
|
$_sudo zypper rem "$@"
|
||||||
}
|
}
|
||||||
;;
|
;;
|
||||||
alpine)
|
alpine)
|
||||||
pkg-install() {
|
pkg-install() {
|
||||||
pkger=apk
|
$_sudo apk add "$@"
|
||||||
apk add "$@"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# CAUTION:
|
# CAUTION:
|
||||||
pkg-remove() {
|
pkg-remove() {
|
||||||
pkger=apk
|
$_sudo apk remove "$@"
|
||||||
apk remove "$@"
|
|
||||||
}
|
}
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# ─< Distribution detection and installation >────────────────────────────────────────
|
# ─< Distribution detection and installation >────────────────────────────────────────
|
||||||
get_packager() {
|
get-packagemanager() {
|
||||||
# ─< define fallback function >───────────────────────────────────────────────────────────
|
# ─< define fallback function >───────────────────────────────────────────────────────────
|
||||||
fallback() {
|
fallback() {
|
||||||
# ─────────────────────────────────────< get packager >─────────────────────────────────────
|
# ─────────────────────────────────────< get packager >─────────────────────────────────────
|
||||||
|
@ -382,8 +293,8 @@ get_packager() {
|
||||||
distro="opensuse"
|
distro="opensuse"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo_error "Can not detect distribution correctly!"
|
echo-error "Can not detect distribution correctly!"
|
||||||
# echo_error "DEBUG:: $pkger ::"
|
# echo-error "DEBUG:: $pkger ::"
|
||||||
return 69
|
return 69
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -439,7 +350,7 @@ get_packager() {
|
||||||
opensuse="true"
|
opensuse="true"
|
||||||
distro="opensuse"
|
distro="opensuse"
|
||||||
else
|
else
|
||||||
echo_error "Unsupported distribution: $ID"
|
echo-error "Unsupported distribution: $ID"
|
||||||
echo_warning "Trying fallback.."
|
echo_warning "Trying fallback.."
|
||||||
fallback
|
fallback
|
||||||
fi
|
fi
|
||||||
|
@ -460,7 +371,7 @@ get_packager() {
|
||||||
# │ Automated setup for refreshing repositories and overall getting the variables to setup │
|
# │ Automated setup for refreshing repositories and overall getting the variables to setup │
|
||||||
# ╰────────────────────────────────────────────────────────────────────────────────────────╯
|
# ╰────────────────────────────────────────────────────────────────────────────────────────╯
|
||||||
|
|
||||||
dist_setup() {
|
distro-setup() {
|
||||||
case "$distro" in
|
case "$distro" in
|
||||||
debian)
|
debian)
|
||||||
echo "${BOLD}Found ${RED}debian${NC}"
|
echo "${BOLD}Found ${RED}debian${NC}"
|
||||||
|
@ -520,8 +431,8 @@ update_package_list() {
|
||||||
|
|
||||||
echo_info "Refreshing repository sources.."
|
echo_info "Refreshing repository sources.."
|
||||||
case "$distro" in
|
case "$distro" in
|
||||||
ubuntu | debian) run-silent $_sudo apt-get update ;;
|
ubuntu | debian) $_sudo apt-get update ;;
|
||||||
fedora) run-silent $_sudo dnf update ;;
|
fedora) $_sudo dnf update ;;
|
||||||
arch)
|
arch)
|
||||||
if command_exists pacman; then
|
if command_exists pacman; then
|
||||||
if ! checkAUR; then
|
if ! checkAUR; then
|
||||||
|
@ -552,38 +463,40 @@ update_package_list() {
|
||||||
sleep 0.01
|
sleep 0.01
|
||||||
|
|
||||||
if command_exists paru; then
|
if command_exists paru; then
|
||||||
run-silent paru -Sy
|
paru -Sy
|
||||||
elif command_exists yay; then
|
elif command_exists yay; then
|
||||||
run-silent yay -Sy
|
yay -Sy
|
||||||
else
|
else
|
||||||
run-silent $_sudo pacman -Sy
|
$_sudo pacman -Sy
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
opensuse) run-silent $_sudo zypper ref ;;
|
opensuse) $_sudo zypper ref ;;
|
||||||
alpine) run-silent $_sudo apk update ;;
|
alpine) $_sudo apk update ;;
|
||||||
*)
|
*)
|
||||||
echo_error "Unsupported distribution: ${BRIGHT_RED}$distro"
|
echo-error "Unsupported distribution: ${BRIGHT_RED}$distro"
|
||||||
return 69
|
return 69
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
if check_env; then
|
if check-environment; then
|
||||||
get_packager
|
get-packagemanager
|
||||||
dist_setup
|
distro-setup
|
||||||
|
|
||||||
# WHY:
|
# WHY:
|
||||||
# ╭─────────────────────────────────────────────────────────────────────────╮
|
# ╭─────────────────────────────────────────────────────────────────────────╮
|
||||||
# │ check if the script has run at least once, so that the sources dont │
|
# │ check if the script has run at least once, so that the sources dont │
|
||||||
# │ have to get updated again.. │
|
# │ have to get updated again.. │
|
||||||
# ╰─────────────────────────────────────────────────────────────────────────╯
|
# ╰─────────────────────────────────────────────────────────────────────────╯
|
||||||
if [[ -z "$PIKA_INIT" ]]; then
|
pikaCheckFile="$HOME/.cache/pika_script_detection"
|
||||||
echo_pkg "First time importing.."
|
|
||||||
|
|
||||||
if update_package_list; then
|
if ! checkFileAge "$pikaCheckFile"; then
|
||||||
|
echo "${BOLD}${GREY}Updating sources..${NC}"
|
||||||
|
|
||||||
|
if update-package-list; then
|
||||||
silentexec touch "$pikaCheckFile"
|
silentexec touch "$pikaCheckFile"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo_pkg "Skipping repo refresh"
|
echo "${BOLD}${GREY}Skipping repo refresh${NC}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue