installs/hyprland.sh
2025-05-19 19:03:04 +02:00

336 lines
9.5 KiB
Bash

#!/usr/bin/env bash
# ╭───────────────╮
# │ env functions │
# ╰───────────────╯
# ───────────────────────────────────< ANSI color codes >───────────────────────────────────
# ─< Check if the given command exists silently >─────────────────────────────────────────
command_exists() {
command -v "$@" >/dev/null 2>&1
}
# 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..
getImports() {
i="https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh"
import="$(mktemp)"
if command_exists curl; then
curl -fsSL $i -o $import
else
echo "curl is required, but missing.."
exit 1
fi
source "$import"
sleep 0.3
rm "$import"
}
checkEnv() {
if $debian; then
echo_info "Using debian.. checking for compatibility.."
if ! $trixie; then
echo_error "You are not using trixie, this script can currently only run on trixie (13)!"
echo_error "trixie: $trixie"
echo_error "bookworm: $bookworm"
echo_error "bullseye: $bullseye"
echo_error "buster: $buster"
return 69
else
echo_info "Using trixie.. good choice"
return 0
fi
elif $arch; then
echo_info "Using arch linux.. You really shouldn't get any errors :)"
return 0
else
echo_error "Cannot install $PACKAGE for $distro"
return 69
fi
}
askThings() {
echo_note "Do you want to install hyprland? (y/N)"
read -r askHyprland </dev/tty
case "$askHyprland" in
[yY]) ;;
*)
echo_error "Aborting now!"
exit 69
;;
esac
if ! command_exists waybar && ! command_exists hyprpanel && ! command_exists gBar; then
echo_note "What bar do you want to install? (available: [w]aybar, [h]yprpanel, [g]Bar)"
read -r askBar </dev/tty
case "$askBar" in
[Ww] | waybar)
bar="waybar"
;;
[Hh] | hyprpanel)
if $debian; then
echo_warning "hyprpanel is not available for $distro"
echo_warning "the script automatically chose gBar for you instead.."
bar="gBar"
else
bar="hyprpanel"
fi
;;
[Gg] | gBar | gbar)
bar="gBar"
;;
esac
echo_info "Set bar to $bar"
fi
if ! command_exists rofi && ! command_exists tofi; then
echo_note "Do you want to install [r]ofi or [t]ofi?: "
read -r askRofi </dev/tty
case "$askRofi" in
[tT] | tofi)
menu="tofi"
;;
[rR] | rofi)
menu="rofi"
;;
*)
menu="rofi"
;;
esac
echo_info "Set menu to $menu"
fi
echo_note "What terminal to you want to install? [a]lacritty, [f]oot, [k]itty, [w]ezterm"
read -r askTerminal </dev/tty
case "$askTerminal" in
[aA] | alacritty)
terminal="alacritty"
;;
[fF] | foot)
terminal="foot"
;;
[kK] | kitty)
terminal="kitty"
;;
[wW] | wezterm)
terminal="wezterm"
;;
*)
terminal="foot"
;;
esac
echo_info "Set terminal to $terminal"
advDeps=(
${menu:-rofi}
${terminal:-foot}
$bar
hyprshot
hyprlock
swww
)
}
instCustom() {
for _d in "${advDeps[@]}"; do
case "$_d" in
hyprpanel)
# eval "$(curl -fsSL https://git.k4li.de/scripts/installs/raw/branch/main/hyprpanel.sh)"
source_script https://git.k4li.de/scripts/installs/raw/branch/main/hyprpanel.sh
;;
hyprlock)
source_script https://git.k4li.de/scripts/installs/raw/branch/main/hyprlock.sh
;;
hyprshot)
source_script https://git.k4li.de/scripts/installs/raw/branch/main/hyprshot.sh
;;
gBar)
source_script https://git.k4li.de/scripts/installs/raw/branch/main/gBar.sh
;;
rofi)
source_script https://git.k4li.de/scripts/installs/raw/branch/main/rofi.sh
;;
swww)
source_script https://git.k4li.de/scripts/installs/raw/branch/main/swww.sh
;;
*)
checkAndInstall "$_d"
;;
esac
done
}
cloneDotfiles() {
echo_info "Which dotfiles do you want to clone? ([p]ika's config, or just type the link to your own repo)"
read -r askDotfiles2 </dev/tty
case "$askDotfiles2" in
[pP])
echo_info "Cloning pika's config..."
run git clone --recursive --depth=1 https://git.k4li.de/dotfiles/hyprdots.git "$HOME/git/hyprdots" || { echo_error "Failed to clone dotfiles!" && exit 1; }
cd $HOME/git/hyprdots || { echo_error "Failed to clone dotfiles!" && exit 1; }
echo_info "Installing dotfiles..."
make </dev/tty || { echo_error "Failed to install dotfiles!" && exit 1; }
echo_info "Dotfiles installed successfully!"
;;
*)
echo_info "Cloning dotfiles from $askDotfiles2..."
git clone --recursive --depth=1 $askDotfiles2 $HOME/git/hyprdots
cd $HOME/git/hyprdots || { echo_error "Failed to clone dotfiles!" && exit 1; }
echo_info "Your dotfiles have been saved to $HOME/git/hyprdots"
echo_info "You can now install your dotfiles how you want to!"
;;
esac
}
checkConfig() {
dirs="hypr $menu $bar"
for i in $dirs; do
if [ ! -d "$HOME/.config/$i" ]; then
echo_warning "Config directory $i not found!"
echo_note "Do you want to clone some dotfiles? (y/N)"
read -r askDotfiles </dev/tty
case "$askDotfiles" in
[yY])
echo_info "Cloning dotfiles..."
cloneDotfiles
;;
[nN])
echo_note "Skipping dotfiles installation..."
;;
esac
fi
done
}
getDependencies() {
echo_info "Checking build dependencies.."
# INFO:
# ╭─────────────────────────────────────────────────────────────────────────╮
# │ You can define dependencies for various linux distros here. It will │
# │ automagically be pulled via the $pkgArray[$distro] variable │
# ╰─────────────────────────────────────────────────────────────────────────╯
generalDeps=(
hyprland
xdg-desktop-portal-hyprland
hyprland-protocols
wayland-protocols
grim
slurp
wlogout
ffmpeg
wob
nwg-look
kitty
wl-clipboard
)
depsDebian=(
hyprland-dev
)
depsFedora=()
depsOpensuse=()
depsArch=(
hyprpolkitagent
wayland-utils
wayland-protocols
)
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]}"
case "$distro" in
arch)
checkAndInstall "${generalDeps[@]}"
checkAndInstall "${pkgArray[@]}"
;;
debian)
if $trixie; then
checkAndInstall "${generalDeps[@]}"
checkAndInstall "${pkgArray[@]}"
else
echo_error "Your current distro of debian is not sufficient, you have to have trixie (13) installed"
echo "trixie: $trixie"
echo "bookworm: $bookworm"
echo "bullseye: $bullseye"
echo "buster: $buster"
exit 69
fi
;;
*)
echo "$distro is currently not supported by this script!"
exit 69
;;
esac
}
main() {
askThings
if $silent; then
echo_warning "Executing script silently!"
fi
checkEnv
getDependencies
instCustom
checkConfig
}
if getImports; then
# ─< package variable >───────────────────────────────────────────────────────────────────
unset PACKAGE
# ─< argument list variables >────────────────────────────────────────────────────────────
silent=false
sleep 0.1
PACKAGE=hyprland
if command_exists "$PACKAGE"; then
echo_warning "$PACKAGE is already installed!"
echo_warning "Exiting now!"
exit 69
fi
# ─< parse arguments and get variable contents >──────────────────────────────────────────
for arg in "$@"; do
case "$arg" in
--silent | -s)
export silent=true
;;
esac
done
main
fi