installs/quickshell.sh
2025-06-08 14:40:40 +02:00

183 lines
5.5 KiB
Bash

{
#!/usr/bin/env bash
# ─< Check if the given command exists silently >─────────────────────────────────────────
command_exists() {
command -v "$@" >/dev/null 2>&1
}
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 "curl/wget is required, but missing.."
exit 69
fi
source "$import"
echo "${BLUE}Sourcing external script:${NC} $url"
sleep 0.1
rm -f "$import"
}
setup-env() {
# WHY:
# This import will give you the following variables:
# _sudo="sudo -E" <- only if non root user
# distro = <distro name, like 'arch', 'debian', 'fedora'..>
# arch = bool
# fedora = bool
# opensuse = bool....
# You can then use it for, `if $arch; then`
# Also this gives you the _install command, which installs a package pased on the packagemanager/distro used.
#
# CAUTION:
# This only wokrs for generic package names, like neovim, or vim, or tmux etc..
# not every package packagemanager has the same packagenames for their packages..
#
# local beddu=https://git.k4li.de/scripts/beddu/raw/branch/main/dist/beddu.sh
# local pika=https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh
# dream ~= combined beddu and pika
local dream=https://git.k4li.de/scripts/imports/raw/branch/main/dream.sh
if ! command_exists pkg-install && ! command_exists check-and-install && ! command_exists pen; then
getImports $dream
fi
}
install-dependencies() {
# INFO:
# ╭─────────────────────────────────────────────────────────────────────────╮
# │ You can define dependencies for various linux distros here. It will │
# │ automagically be pulled via the $pkgArray[$distro] variable │
# ╰─────────────────────────────────────────────────────────────────────────╯
depsGeneral=(
fish
)
# depsDebian=()
# depsUbuntu=()
# depsFedora=()
# depsOpensuse=()
depsArch=(
git
quickshell
curl
jq
ttf-material-symbols-variable-git
ttf-jetbrains-mono-nerd
ttf-ibm-plex
app2unit-git
fd
fish
python-aubio
python-pyaudio
python-numpy
cava
networkmanager
bluez-utils
ddcutil
brightnessctl
)
# depsAlpine=()
declare -A deps=(
# [debian]="depsDebian"
# [ubuntu]="depsUbuntu"
# [fedora]="depsFedora"
[arch]="depsArch"
# [alpine]="depsAlpine"
# [opensuse]="depsOpensuse"
)
# INFO:
# ╭────────────────────────────────────────────────────────────────╮
# │ This variable stores the packages you provided for each distro │
# ╰────────────────────────────────────────────────────────────────╯
declare -n pkgArray="${deps[$distro]}"
pkgArray="${pkgArray[@]} ${depsGeneral[@]}"
case "$distro" in
arch)
# installs packages inside the ${pkgArray[@]} list, which is the $distro part of the confiruation above
check-and-install ${pkgArray[@]}
;;
*)
pen bold yellow "There are no dependencies to install for $distro"
return 0
;;
esac
}
clone-quickshell() {
local err out
local dir="$HOME/.config/quickshell"
if [ -d "$dir" ]; then
pen bold red "There is already a configuration at $dir"
if confirm bold blue "Do you want to delete it?" </dev/tty; then
rm -rf "$dir"
else
pen bold red "Cannot continue!"
exit 69
fi
else
spin bold yellow "Cloning quickshell to $dir.."
if run --err err --out out git clone --depth=1 https://github.com/caelestia-dots/shell.git $dir; then
upclear
check bold green "Cloned quickshell successfully"
else
upclear
throw bold red "Error while cloning dotfiles.."
pen bold grey "OUT: ${out:-}"
echo-error "${err:-}"
exit 69
fi
fi
}
main() {
if $silent; then
pen yellow "ARG: Executing script silently!"
fi
case "$distro" in
arch)
if ! install-dependencies; then
throw "Error when installing dependencies.."
fi
if clone-quickshell; then
check "Completed installation and configuration"
else
throw "Installation did not finish correctly"
fi
;;
*)
echo "$distro is not supported by this script!"
exit 69
;;
esac
}
if setup-env; then
# ─< package variable >───────────────────────────────────────────────────────────────────
unset PACKAGE
PACKAGE=quickshell
if command_exists "$PACKAGE"; then
pen bold yellow "$PACKAGE is already installed!"
pen bold yellow "Exiting now!"
exit 69
fi
main
fi
}