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 #!/usr/bin/env bash
getImports() {
# ANSI color codes local url="$1"
RED='\033[0;31m' local import="$(mktemp)"
CYAN='\033[0;36m' if command_exists curl; then
YELLOW='\033[0;33m' curl -fsSL $url -o $import
LIGHT_GREEN='\033[0;92m' elif command_exists wget; then
BOLD='\033[1m' wget -O $import $url
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"
else else
echo_error "No sudo found and you're not root! Can't install packages." echo "curl/wget is required, but missing.."
return 1 exit 69
fi
else
echo_info "Root access confirmed."
_sudo=""
fi 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__() { __pre_stow__() {
echo_note "__pre_stow__" echo_note "__pre_stow__"
conf="$HOME/.config" conf="$HOME/.config"
@ -121,16 +36,19 @@ __pre_stow__() {
"zellij" "zellij"
) )
pen yellow "Trying to clean the environment.."
if [ ! -d "$bak_dir" ]; then 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" silentexec mkdir "$bak_dir"
else else
echo_info "Backup dir already present, clearing now" && pen bold yellow "Backup dir already present, clearing now" &&
rm -rf "${bak_dir:?}/*" rm -rf "${bak_dir:?}/*"
fi fi
for _dirs in "${dirs[@]}"; do for _dirs in "${dirs[@]}"; do
if [ -d "$conf/$_dirs" ]; then if [ -d "$conf/$_dirs" ]; then
repen moved $_dirs
mv -f "$conf/$_dirs" "$bak_dir" mv -f "$conf/$_dirs" "$bak_dir"
fi fi
done done
@ -143,12 +61,14 @@ __pre_stow__() {
for _f in "${h_files[@]}"; do for _f in "${h_files[@]}"; do
if [ -f "$HOME/$_f" ]; then if [ -f "$HOME/$_f" ]; then
repen moved $_f
mv -f "$HOME/$_f" "$bak_dir" && echo_info "Moved $_f to $bak_dir" mv -f "$HOME/$_f" "$bak_dir" && echo_info "Moved $_f to $bak_dir"
fi fi
done done
for _d in ".zsh .tmux .fzf"; do for _d in ".zsh .tmux .fzf"; do
if [ -d "$HOME/$_d" ]; then if [ -d "$HOME/$_d" ]; then
repen moved $_d
mv -f "$HOME/$_d" "$bak_dir" && echo_info "Moved $_d to $bak_dir" mv -f "$HOME/$_d" "$bak_dir" && echo_info "Moved $_d to $bak_dir"
fi fi
done done
@ -156,42 +76,46 @@ __pre_stow__() {
askThings() { askThings() {
if [ ! -d ./dotfiles/.config/tmux/ ] && [ ! -d ./dotfiles/.config/zellij/ ]; then 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 read -r askMultiPlexer </dev/tty
fi fi
if [ ! -d ./dotfiles/.config/rofi/ ] && [ ! -d ./dotfiles/.config/tofi/ ]; then if [ ! -d ./dotfiles/.config/rofi/ ] && [ ! -d ./dotfiles/.config/tofi/ ]; then
echo_info "Choose a menu - [r]ofi || [t]ofi" choose "Choose a menu" rofi tofi none </dev/tty
read -r askMenu </dev/tty # read -r askMenu </dev/tty
fi fi
if [ ! -d ./dotfiles/.config/yazi/ ] && [ ! -d ./dotfiles/.config/lf/ ] && [ ! -d ./dotfiles/.config/ranger/ ]; then 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" choose "Choose a cli filemanager" yazi ranger lf </dev/tty
read -r askFilemgr </dev/tty # read -r askFilemgr </dev/tty
fi fi
if $arch; then
if [ ! -d ./dotfiles/.config/waybar/ ] && [ ! -d ./dotfiles/.config/gBar/ ] && [ ! -d ./dotfiles/.config/hyprpanel/ ]; 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" choose "Choose a bar provider" waybar gbar hyprpanel </dev/tty
read -r askBar </dev/tty # read -r askBar </dev/tty
fi
else
choose "Choose a bar provider" waybar gbar </dev/tty
fi fi
if [ ! -d ./dotfiles/.config/foot/ ] && [ ! -d ./dotfiles/.config/ghostty/ ] && [ ! -d ./dotfiles/.config/alacritty/ ] && [ ! -d ./dotfiles/.config/kitty/ ]; then 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 -" choose "Choose a Terminal config" alacritty foot ghostty kitty </dev/tty
read -r askTerminal </dev/tty # read -r askTerminal </dev/tty
fi fi
echo_info "Do you also want to install optional packages? (y/n)" __optional__=false
read -r askOptional </dev/tty
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 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 read -r askNvim </dev/tty
fi fi
case "$askOptional" in
[yY]) __optional__="true" ;;
[nN]) __optional__="false" ;;
esac
} }
initNvim() { initNvim() {
@ -247,90 +171,90 @@ cloneDots() {
__validate__() { __validate__() {
if askThings; then if askThings; then
case "$askMultiPlexer" in case "$askMultiPlexer" in
[tT] | tmux) tmux)
cloneDots "tmux" cloneDots "tmux"
plexer="tmux" plexer="tmux"
;; ;;
[zZ] | zellij) zellij)
cloneDots "zellij" cloneDots "zellij"
plexer="zellij" plexer="zellij"
;; ;;
esac esac
case "$askMenu" in case "$askMenu" in
[rR] | rofi) rofi)
cloneDots "rofi" cloneDots "rofi"
menu="rofi" menu="rofi"
;; ;;
[tT] | tofi) tofi)
cloneDots "tofi" cloneDots "tofi"
menu="tofi" menu="tofi"
;; ;;
esac esac
case "$askFilemgr" in case "$askFilemgr" in
[yY] | yazi) yazi)
cloneDots "yazi" cloneDots "yazi"
filemgr="yazi" filemgr="yazi"
;; ;;
[rR] | ranger) ranger)
cloneDots "ranger" cloneDots "ranger"
filemgr="ranger" filemgr="ranger"
;; ;;
[lL] | lf) lf)
cloneDots "lf" cloneDots "lf"
filemgr="lf" filemgr="lf"
;; ;;
esac esac
case "$askBar" in case "$askBar" in
[wW] | waybar) waybar)
cloneDots "waybar" cloneDots "waybar"
bar="waybar" bar="waybar"
;; ;;
[gG] | gBar | gbar) gbar)
cloneDots "gBar" cloneDots "gBar"
bar="gBar" bar="gBar"
;; ;;
[hH] | hyprpanel) hyprpanel)
cloneDots "hyprpanel" cloneDots "hyprpanel"
bar="hyprpanel" bar="hyprpanel"
;; ;;
esac esac
case "$askTerminal" in case "$askTerminal" in
[gG] | ghostty) ghostty)
cloneDots "ghostty" cloneDots "ghostty"
terminal="ghostty" terminal="ghostty"
;; ;;
[kK] | kitty) kitty)
cloneDots "kitty" cloneDots "kitty"
terminal="kitty" terminal="kitty"
;; ;;
[aA] | alacritty) alacritty)
cloneDots "alacritty" cloneDots "alacritty"
terminal="alacritty" terminal="alacritty"
;; ;;
[fF] | foot) foot)
cloneDots "foot" cloneDots "foot"
terminal="foot" terminal="foot"
;; ;;
esac esac
case "$askNvim" in case "$askNvim" in
[sS] | standard) default)
neovim="true" neovim="true"
cloneDots "nvim" cloneDots "nvim"
;; ;;
[mM] | minimal) mini)
neovim="true" neovim="true"
cloneDots "nvim-mini" "nvim" cloneDots "nvim-mini" "nvim"
;; ;;
[aA] | astro) astro)
neovim="true" neovim="true"
cloneDots "nvim-astro" "nvim" cloneDots "nvim-astro" "nvim"
;; ;;
[nN] | no) none)
neovim="false" neovim="false"
return 0 return 0
;; ;;
@ -486,4 +410,6 @@ main() {
echo_note "found resolution ${res}" echo_note "found resolution ${res}"
} }
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 main
fi