scripts/installs/hyprland.sh
2025-04-14 09:22:15 +02:00

632 lines
17 KiB
Bash

#!/bin/sh -e
# ╭───────────────╮
# │ env functions │
# ╰───────────────╯
# ───────────────────────────────────< 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 user is root and set sudo variable if necessary >─────────────
check_root() {
if [ "$(id -u)" -ne 0 ]; then
if command_exists sudo; then
echo_info "User is not root. Using sudo for privileged operations."
_sudo="sudo"
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=""
fi
}
# ──────────────────────< Check if the given command exists silently >──────────────────────
command_exists() {
command -v "$@" >/dev/null 2>&1
}
# ╭────────────────────────────────────╮
# │ insert your scripts/functions here │
# ╰────────────────────────────────────╯
hyprSlim="hyprland hyprland-protocols hyprwayland-scanner libhyprcursor-dev wayland-utils wayland-protocols wl-clipboard nwg-look xdg-desktop-portal-hyprland liblz4"
hyprAdvanced="$menu pavucontrol pamixer btop bluez wlogout wob"
OPTIONAL_SCREENSHOT="grimshot slurp swappy"
OPTIONAL_SCREENRECORD="wf-recorder"
OPTIONAL_AUDIO="pulseaudio pavucontrol"
OPTIONAL_NOTIFY="sway-notification-center libnotify"
OPTIONAL_UTILS="brightnessctl network-manager-gnome gnome-keyring swayidle playerctl"
OPTIONAL_FILES="xdg-user-dirs nautilus gvfs"
OPTIONAL_SDDM_DEPS="qml6-module-qtquick-controls qml6-module-qtquick-effects sddm"
BUILD_DEPS="git gcc make cmake meson ninja-build pkg-config"
RUST_DEPS="cargo rustc" # Separate rust dependencies
askThings() {
echo_note "Do you want to install hyprland? (y/N)"
read -r askHyprland </dev/tty
case "$askHyprland" in
[yY]) askHyprland="true" ;;
*)
echo_error "Aborting now!"
exit 1
;;
esac
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)
bar="hyprpanel"
;;
[Gg] | gBar | gbar)
bar="gBar"
;;
esac
echo_info "Set bar to $bar"
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"
echo_note "Doy you want to install sddm with minimal dependency theme? [catppucchin-mocha] (Y/n) :"
read -r askSddm </dev/tty
case "$askSddm" in
[nN]) ;;
*)
hyprAdvanced="$hyprAdvanced $OPTIONAL_SDDM_DEPS"
sddm_minimal="true"
;;
esac
echo_info "Installing - $OPTIONAL_SDDM_DEPS - for sddm"
# Optional packages section
echo_note "Would you like to install screenshot tools ($OPTIONAL_SCREENSHOT)? (Y/n)"
read -r askScreenshot </dev/tty
case "$askScreenshot" in
[nN]) ;;
*) hyprAdvanced="$hyprAdvanced $OPTIONAL_SCREENSHOT" ;;
esac
echo_note "Would you like to install screen recording tools ($OPTIONAL_SCREENRECORD)? (Y/n)"
read -r askRecord </dev/tty
case "$askRecord" in
[nN]) ;;
*) hyprAdvanced="$hyprAdvanced $OPTIONAL_SCREENRECORD" ;;
esac
echo_note "Would you like to install audio tools ($OPTIONAL_AUDIO)? (Y/n)"
read -r askAudio </dev/tty
case "$askAudio" in
[nN]) ;;
*) hyprAdvanced="$hyprAdvanced $OPTIONAL_AUDIO" ;;
esac
echo_note "Would you like to install notification daemon ($OPTIONAL_NOTIFY)? (Y/n)"
read -r askNotify </dev/tty
case "$askNotify" in
[nN]) ;;
*) hyprAdvanced="$hyprAdvanced $OPTIONAL_NOTIFY" ;;
esac
echo_note "Would you like to install utility tools ($OPTIONAL_UTILS)? (Y/n)"
read -r askUtils </dev/tty
case "$askUtils" in
[nN]) ;;
*) hyprAdvanced="$hyprAdvanced $OPTIONAL_UTILS" ;;
esac
echo_note "Would you like to install additional file management tools ($OPTIONAL_FILES)? (Y/n)"
read -r askFiles </dev/tty
case "$askFiles" in
[nN]) ;;
*) hyprAdvanced="$hyprAdvanced $OPTIONAL_FILES" ;;
esac
}
buildBar() {
echo "..installing ${RED}${bar}${NC}"
case "$bar" in
waybar)
$_sudo $pkg install -y $bar </dev/tty
;;
gBar) ;;
hyprpanel) ;;
esac
}
instTools() {
case "$pkg" in
pacman)
aur="yay paru"
for i in $aur; do
if command_exists $i; then
echo "..using ${RED}$i${NC}"
pkgAur=$i
fi
done
if [ -z $pkgAur ]; then
echo_error "No aur helper present! You first have to install either yay or paru!"
exit 1
fi
if [ "$bar" = "hyprpanel" ]; then
if command_exists $pkgAur; then
echo_info "Installing hyprpanel..."
$pkgAur -S ags-hyprpanel-git --noconfirm </dev/tty
fi
elif [ "$bar" = "gBar" ]; then
if command_exists $pkgAur; then
echo_info "Installing gBar..."
$pkgAur -S gbar-git --noconfirm </dev/tty
fi
fi
;;
*)
buildBar
;;
esac
}
get_package_name() {
_package="$1"
case "$pkg" in
pacman)
echo_info "Getting package names..."
case "$_package" in
# Core/Slim
libhyprcursor-dev) echo "hyprcursor-git" ;;
xdg-desktop-portal-hyprland) echo "xdg-desktop-portal-hyprland" ;;
wayland-utils) echo "wayland-utils" ;;
nwg-look) echo "nwg-look-bin" ;;
# Advanced
btop) echo "btop" ;;
pamixer) echo "pamixer" ;;
wlogout) echo "wlogout" ;;
wob) echo "wob" ;;
# sddm
qml6-module-qtquick-*) echo "kirigami" ;;
# Screenshot
grim) echo "grim" ;;
slurp) echo "slurp" ;;
swappy) echo "swappy" ;;
# Screen recording
wf-recorder) echo "wf-recorder" ;;
# Audio
pipewire) echo "pipewire" ;;
wireplumber) echo "wireplumber" ;;
pipewire-alsa) echo "pipewire-alsa" ;;
pipewire-pulse) echo "pipewire-pulse" ;;
# Notification
sway-notification-center) echo "sway-notification-center" ;;
libnotify) echo "libnotify" ;;
# Utils
brightnessctl) echo "brightnessctl" ;;
network-manager-gnome) echo "network-manager-applet" ;;
gnome-keyring) echo "gnome-keyring" ;;
swayidle) echo "swayidle" ;;
playerctl) echo "playerctl" ;;
# Files
xdg-user-dirs) echo "xdg-user-dirs" ;;
gvfs) echo "gvfs" ;;
liblz4) echo "lz4" ;;
*) echo "$_package" ;;
esac
;;
apt-get)
case "$_package" in
# Core/Slim
hyprland) echo "hyprland" ;;
libhyprcursor-dev) echo "libhyprcursor-dev" ;;
nwg-look) echo "nwg-look" ;;
# Advanced
pamixer) echo "pamixer" ;;
wob) echo "wob" ;;
# sddm
qml6-module-qtquick-controls) echo "qml6-module-qtquick-controls" ;;
qml6-module-qtquick-effects) echo "qml6-module-qtquick-effects" ;;
# Screenshot
grim) echo "grim" ;;
slurp) echo "slurp" ;;
swappy) echo "swappy" ;;
# Screen recording
wf-recorder) echo "wf-recorder" ;;
# Audio
pipewire) echo "pipewire" ;;
wireplumber) echo "wireplumber" ;;
pipewire-alsa) echo "pipewire-alsa" ;;
pipewire-pulse) echo "pipewire-pulse" ;;
# Notification
sway-notification-center) echo "sway-notification-center" ;;
libnotify) echo "libnotify-bin" ;;
# Utils
brightnessctl) echo "brightnessctl" ;;
network-manager-gnome) echo "network-manager-gnome" ;;
gnome-keyring) echo "gnome-keyring" ;;
swayidle) echo "swayidle" ;;
playerctl) echo "playerctl" ;;
# Files
xdg-user-dirs) echo "xdg-user-dirs" ;;
gvfs) echo "gvfs" ;;
liblz4) echo "liblz4-dev" ;;
*) echo "$_package" ;;
esac
;;
dnf)
case "$_package" in
# Core/Slim
libhyprcursor-dev) echo "hyprcursor-devel" ;;
xdg-desktop-portal-hyprland) echo "xdg-desktop-portal-hyprland" ;;
nwg-look) echo "nwg-look" ;;
# Advanced
wlogout) echo "wlogout" ;;
# sddm
qml6-module-qtquick-controls) echo "qml6-module-qtquick-controls" ;;
qml6-module-qtquick-effects) echo "qml6-module-qtquick-effects" ;;
# Screenshot
grim) echo "grim" ;;
slurp) echo "slurp" ;;
swappy) echo "swappy" ;;
# Screen recording
wf-recorder) echo "wf-recorder" ;;
# Audio
pipewire) echo "pipewire" ;;
wireplumber) echo "wireplumber" ;;
pipewire-alsa) echo "pipewire-alsa" ;;
pipewire-pulse) echo "pipewire-pulseaudio" ;;
# Notification
sway-notification-center) echo "sway-notification-center" ;;
libnotify) echo "libnotify" ;;
# Utils
brightnessctl) echo "brightnessctl" ;;
network-manager-gnome) echo "nm-connection-editor" ;;
gnome-keyring) echo "gnome-keyring" ;;
swayidle) echo "swayidle" ;;
playerctl) echo "playerctl" ;;
# Files
xdg-user-dirs) echo "xdg-user-dirs" ;;
gvfs) echo "gvfs" ;;
liblz4) echo "lz4-devel" ;;
*) echo "$_package" ;;
esac
;;
zypper)
case "$_package" in
# Core/Slim
libhyprcursor-dev) echo "hyprcursor-devel" ;;
# Advanced
pamixer) echo "pamixer" ;;
wob) echo "wob" ;;
# sddm
qml6-module-qtquick-controls) echo "qml6-module-qtquick-control" ;;
qml6-module-qtquick-effects) echo "qml6-module-qtquick-effects" ;;
# Screenshot
grim) echo "grim" ;;
slurp) echo "slurp" ;;
swappy) echo "swappy" ;;
# Screen recording
wf-recorder) echo "wf-recorder" ;;
# Audio
pipewire) echo "pipewire" ;;
wireplumber) echo "wireplumber" ;;
pipewire-alsa) echo "pipewire-alsa" ;;
pipewire-pulse) echo "pipewire-pulseaudio" ;;
# Notification
sway-notification-center) echo "sway-notification-center" ;;
libnotify) echo "libnotify" ;;
# Utils
brightnessctl) echo "brightnessctl" ;;
network-manager-gnome) echo "NetworkManager-gnome" ;;
gnome-keyring) echo "gnome-keyring" ;;
swayidle) echo "swayidle" ;;
playerctl) echo "playerctl" ;;
# Files
xdg-user-dirs) echo "xdg-user-dirs" ;;
gvfs) echo "gvfs" ;;
liblz4) echo "liblz4-devel" ;;
*) echo "$_package" ;;
esac
;;
esac
}
# Add this function to check for Rust toolchain
check_rust() {
for tool in $RUST_DEPS; do
if ! command_exists "$tool"; then
case $pkg in
pacman)
echo_info "Updating package database..."
$_sudo pacman -Sy
echo_info "Installing Rust toolchain..."
$_sudo pacman -S rust cargo --noconfirm </dev/tty
;;
apt-get)
echo_info "Updating package database..."
$_sudo apt-get update
echo_info "Installing Rust toolchain..."
$_sudo apt-get install rustc cargo -y </dev/tty
;;
dnf)
echo_info "Updating package database..."
$_sudo dnf install rust cargo -y </dev/tty
;;
zypper)
echo_info "Updating package database..."
$_sudo zypper install rust cargo -y </dev/tty
;;
esac
return $?
fi
done
return 0
}
# Modify build_swww to check for Rust first
build_swww() {
echo_info "Building swww from source..."
# Check for Rust toolchain
if ! check_rust; then
echo_error "Failed to install Rust toolchain"
failed_builds="$failed_builds swww"
return 1
fi
# Store current directory
current_dir=$(pwd)
# Create temporary build directory
build_dir=$(mktemp -d)
trap "$_sudo rm -rf $build_dir" EXIT
cd "$build_dir" || exit 1
# Clone and build swww
if git clone https://github.com/Horus645/swww.git; then
cd swww || exit 1
if cargo build --release; then
echo_info "Installing swww..."
$_sudo cp target/release/swww /usr/local/bin/
$_sudo cp target/release/swww-daemon /usr/local/bin/
echo_note "swww installed successfully!"
else
echo_error "Failed to build swww"
failed_builds="$failed_builds swww"
fi
else
echo_error "Failed to clone swww repository"
failed_builds="$failed_builds swww"
fi
# Cleanup and return to original directory
cd "$current_dir" || exit 1
rm -rf "$build_dir"
}
# Modify instDeps() to use the new check_rust function
instDeps() {
pkgManager="apt-get pacman dnf zypper"
for i in $pkgManager; do
if command_exists $i; then
echo "..using ${RED}$i${NC}"
pkg=$i
fi
done
# First install build dependencies if we need to build swww
if ! command_exists swww; then
echo_info "Installing build dependencies for swww..."
case $pkg in
pacman)
echo_info "Updating package database..."
$_sudo pacman -Sy
echo_info "Installing build dependencies..."
$_sudo pacman -S $BUILD_DEPS --noconfirm </dev/tty
echo_info "Installing swww..."
$_sudo pacman -S swww -y </dev/tty
;;
apt-get | dnf)
echo_info "Updating package database..."
$_sudo $pkg update
echo_info "Installing build dependencies..."
$_sudo $pkg install $BUILD_DEPS -y </dev/tty
build_swww
;;
zypper)
echo_info "Updating package database..."
$_sudo zypper install $BUILD_DEPS -y </dev/tty
echo_info "Installing swww..."
$_sudo zypper install swww -y </dev/tty
;;
esac
fi
# Continue with normal package installation
transformed_deps=""
for dep in $deps; do
transformed_deps="$transformed_deps $(get_package_name "$dep")"
done
deps="$transformed_deps"
echo_info "Installing dependencies..."
case $pkg in
pacman)
if [ "$sddm_minimal" = "true" ]; then
$_sudo pacman -S sddm --noconfirm </dev/tty
fi
for d in $deps; do
if ! command_exists "$d"; then
$_sudo pacman -S "$d" --noconfirm </dev/tty
fi
done
# $_sudo pacman -S $deps --noconfirm </dev/tty
;;
apt-get)
if [ "$sddm_minimal" = "true" ]; then
$_sudo "$pkg" install sddm --no-install-recommends </dev/tty
fi
for d in $deps; do
if ! command_exists "$d"; then
$_sudo $pkg install "$d" --assume-yes </dev/tty
fi
done
;;
*)
for d in $deps; do
if ! command_exists "$d"; then
$_sudo $pkg install "$d" -y </dev/tty
fi
done
;;
esac
}
checkDependencies() {
deps=""
cd="$hyprSlim $hyprAdvanced"
for f in $cd; do
if ! command_exists $f; then
deps="$deps $f"
fi
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..."
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
}
# ───────────────────────────────< main function to execute >───────────────────────────────
main() {
if check_root; then
askThings
if [ "$askHyprland" = "true" ]; then
checkDependencies
instDeps
instTools
checkConfig
fi
else
echo_error "Something went terribly wrong!"
fi
}
main