install.sh

This commit is contained in:
pika 2025-05-22 11:36:37 +02:00
parent 20ff7e8ff4
commit 5055ab05ba
2 changed files with 64 additions and 137 deletions

1
bash Submodule

@ -0,0 +1 @@
Subproject commit 74357e75d7e2817a0544099fd6833069484c2fd9

View file

@ -1,106 +1,21 @@
#!/usr/bin/env bash
# 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
}
# ─< Check if the user is root and set sudo variable if necessary >───────────────────────
check_root() {
if ((EUID != 0)); then
if command_exists sudo; then
echo_info "User is not root. Using sudo for privileged operations."
_sudo="sudo"
getImports() {
local url="$1"
local import="$(mktemp)"
if command_exists curl; then
curl -fsSL $url -o $import
elif command_exists wget; then
wget -O $import $url
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=""
echo "curl/wget is required, but missing.."
exit 69
fi
source "$import"
sleep 0.2
rm "$import"
echo "imported $url"
}
# ─< Distribution detection and installation >────────────────────────────────────────
get_packager() {
pkger=(
"apt"
"pacman"
"dnf"
"apk"
"zypper"
)
for pkger in "${pkger[@]}"; do
if command_exists "$pkger"; then
echo_info "Found package manager: $pkger"
case "$pkger" in
"apt")
$_sudo apt-get update
_install() { $_sudo apt-get install --assume-yes "$@"; }
arch="false"
;;
"pacman")
$_sudo pacman -Syy
if command_exists paru; then
echo_info "Using paru as aur helper"
_install() { paru -S --noconfirm "$@"; }
elif command_exists yay; then
echo_info "Using yay as aur helper"
_install() { yay -S --noconfirm "$@"; }
else
echo_info "Using no aur helper!"
_install() { $_sudo pacman -S --noconfirm "$@"; }
fi
arch="true"
;;
"dnf")
$_sudo dnf update
_install() { $_sudo dnf install -y "$@"; }
arch="false"
;;
"apk")
_install() { $_sudo apk add "$@"; }
arch="false"
;;
"zypper")
$_sudo zypper ref
_install() { $_sudo zypper in -y "$@"; }
arch="false"
;;
esac
fi
done
}
silentexec() {
"$@" >/dev/null 2>&1
}
__pre_stow__() {
echo_note "__pre_stow__"
conf="$HOME/.config"
@ -121,16 +36,19 @@ __pre_stow__() {
"zellij"
)
pen yellow "Trying to clean the environment.."
if [ ! -d "$bak_dir" ]; then
echo_info "backup dir created at $bak_dir" &&
repen yellow "backup dir created at $bak_dir" &&
silentexec mkdir "$bak_dir"
else
echo_info "Backup dir already present, clearing now" &&
pen bold yellow "Backup dir already present, clearing now" &&
rm -rf "${bak_dir:?}/*"
fi
for _dirs in "${dirs[@]}"; do
if [ -d "$conf/$_dirs" ]; then
repen moved $_dirs
mv -f "$conf/$_dirs" "$bak_dir"
fi
done
@ -143,12 +61,14 @@ __pre_stow__() {
for _f in "${h_files[@]}"; do
if [ -f "$HOME/$_f" ]; then
repen moved $_f
mv -f "$HOME/$_f" "$bak_dir" && echo_info "Moved $_f to $bak_dir"
fi
done
for _d in ".zsh .tmux .fzf"; do
if [ -d "$HOME/$_d" ]; then
repen moved $_d
mv -f "$HOME/$_d" "$bak_dir" && echo_info "Moved $_d to $bak_dir"
fi
done
@ -156,42 +76,46 @@ __pre_stow__() {
askThings() {
if [ ! -d ./dotfiles/.config/tmux/ ] && [ ! -d ./dotfiles/.config/zellij/ ]; then
echo_info "Choose a menu - [t]mux || [z]ellij || [n]one"
choose askMultiPlexer "Choose a menu" tmux zellij none </dev/tty
read -r askMultiPlexer </dev/tty
fi
if [ ! -d ./dotfiles/.config/rofi/ ] && [ ! -d ./dotfiles/.config/tofi/ ]; then
echo_info "Choose a menu - [r]ofi || [t]ofi"
read -r askMenu </dev/tty
choose "Choose a menu" rofi tofi none </dev/tty
# read -r askMenu </dev/tty
fi
if [ ! -d ./dotfiles/.config/yazi/ ] && [ ! -d ./dotfiles/.config/lf/ ] && [ ! -d ./dotfiles/.config/ranger/ ]; then
echo_info "Choose a cli filemanager - [y]azi || [r]anger || [l]f"
read -r askFilemgr </dev/tty
choose "Choose a cli filemanager" yazi ranger lf </dev/tty
# read -r askFilemgr </dev/tty
fi
if $arch; then
if [ ! -d ./dotfiles/.config/waybar/ ] && [ ! -d ./dotfiles/.config/gBar/ ] && [ ! -d ./dotfiles/.config/hyprpanel/ ]; then
echo_info "Choose a bar provider - [w]aybar || [g]Bar || [h]yprpanel"
read -r askBar </dev/tty
choose "Choose a bar provider" waybar gbar hyprpanel </dev/tty
# read -r askBar </dev/tty
fi
else
choose "Choose a bar provider" waybar gbar </dev/tty
fi
if [ ! -d ./dotfiles/.config/foot/ ] && [ ! -d ./dotfiles/.config/ghostty/ ] && [ ! -d ./dotfiles/.config/alacritty/ ] && [ ! -d ./dotfiles/.config/kitty/ ]; then
echo_info "Choose a Terminal config - [f]oot || [g]hostty || [k]itty || [a]lacritty -"
read -r askTerminal </dev/tty
choose "Choose a Terminal config" alacritty foot ghostty kitty </dev/tty
# read -r askTerminal </dev/tty
fi
echo_info "Do you also want to install optional packages? (y/n)"
read -r askOptional </dev/tty
__optional__=false
if confirm askOptional "Do you also want to install optional packages?" </dev/tty; then
__optional__=true
fi
# read -r askOptional </dev/tty
if [ ! -d "$HOME/.config/nvim" ]; then
echo_info "Do you also want to install a neovim config? [m]inimal || [s]tandard || [a]stro || [n]o"
choose "Do you also want to install a neovim config?" default mini astro none
read -r askNvim </dev/tty
fi
case "$askOptional" in
[yY]) __optional__="true" ;;
[nN]) __optional__="false" ;;
esac
}
initNvim() {
@ -247,90 +171,90 @@ cloneDots() {
__validate__() {
if askThings; then
case "$askMultiPlexer" in
[tT] | tmux)
tmux)
cloneDots "tmux"
plexer="tmux"
;;
[zZ] | zellij)
zellij)
cloneDots "zellij"
plexer="zellij"
;;
esac
case "$askMenu" in
[rR] | rofi)
rofi)
cloneDots "rofi"
menu="rofi"
;;
[tT] | tofi)
tofi)
cloneDots "tofi"
menu="tofi"
;;
esac
case "$askFilemgr" in
[yY] | yazi)
yazi)
cloneDots "yazi"
filemgr="yazi"
;;
[rR] | ranger)
ranger)
cloneDots "ranger"
filemgr="ranger"
;;
[lL] | lf)
lf)
cloneDots "lf"
filemgr="lf"
;;
esac
case "$askBar" in
[wW] | waybar)
waybar)
cloneDots "waybar"
bar="waybar"
;;
[gG] | gBar | gbar)
gbar)
cloneDots "gBar"
bar="gBar"
;;
[hH] | hyprpanel)
hyprpanel)
cloneDots "hyprpanel"
bar="hyprpanel"
;;
esac
case "$askTerminal" in
[gG] | ghostty)
ghostty)
cloneDots "ghostty"
terminal="ghostty"
;;
[kK] | kitty)
kitty)
cloneDots "kitty"
terminal="kitty"
;;
[aA] | alacritty)
alacritty)
cloneDots "alacritty"
terminal="alacritty"
;;
[fF] | foot)
foot)
cloneDots "foot"
terminal="foot"
;;
esac
case "$askNvim" in
[sS] | standard)
default)
neovim="true"
cloneDots "nvim"
;;
[mM] | minimal)
mini)
neovim="true"
cloneDots "nvim-mini" "nvim"
;;
[aA] | astro)
astro)
neovim="true"
cloneDots "nvim-astro" "nvim"
;;
[nN] | no)
none)
neovim="false"
return 0
;;
@ -486,4 +410,6 @@ main() {
echo_note "found resolution ${res}"
}
main
if getImports "https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh" && getImports "https://git.k4li.de/scripts/beddu/raw/branch/main/dist/beddu.sh"; then
main
fi