This commit is contained in:
pika 2025-05-11 14:48:23 +02:00
parent 46597d1677
commit d49530a51a
2 changed files with 81 additions and 519 deletions

View file

@ -1,69 +1,48 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
# ╭───────────────╮
# │ 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 >──────────────────────
# ─< 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"
# 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
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"
source "$import"
sleep 0.3
rm "$import"
}
BUILD_DEPS="git gcc make cmake meson ninja-build pkg-config"
RUST_DEPS="cargo rustc" # Separate rust dependencies
run(){
if $silent; then
silentexec "$@"
else
"$@"
fi
}
askThings() {
echo_note "Do you want to install hyprland? (y/N)"
@ -110,467 +89,31 @@ askThings() {
echo_info "Set menu to $menu"
fi
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
advDeps=(
$bar
$menu
)
}
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" ;;
instCustom() {
case $bar in
waybar) checkAndInstall waybar ;;
hyprpanel)
case $distro in
arch) _install ags-hyprpanel-git ;;
*) echo_error "Hyprpanel cannot be installed for ${YELLOW}${distro}${RED} right now.." ;;
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" ;;
gBar)
case $distro in
arch) _install gbar-git ;;
*) echo_error "gBar cannot be installed for ${YELLOW}${distro}${RED} right now.." ;;
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
@ -618,19 +161,30 @@ checkConfig() {
done
}
# ───────────────────────────────< main function to execute >───────────────────────────────
main() {
if check_root; then
askThings
if $askHyprland; then
checkDependencies
instDeps
instTools
checkConfig
fi
else
echo_error "Something went terribly wrong!"
fi
case "$distro" in
arch)
local deps=(
hyprland
hypridle
hyprpolkitagent
hyprland-protocols
wayland-utils
wayland-protocols
wl-clipboard
xdg-desktop-portal-hyprland
)
checkAndInstall "${deps[@]}"
;;
*)
echo "$distro is not supported by this script!"
exit 1
;;
esac
}
main
if getImports; then
askThings
instCustom
main
fi