#!/usr/bin/env bash

# Getting hypr to work with neauveau drivers and legacy nvidia cards
# https://github.com/HyprWM/Hyprland/issues/1070

# i915 driver
# apt-cache policy xserver-xorg-video-intel libgl1-mesa-dri i965-va-driver
# lspci
# 00:02.0 VGA compatible controller: Intel Corporation Mobile GM965/GL960 Integrated Graphics Controller (primary) (rev 0c)
# 00:02.1 Display controller: Intel Corporation Mobile GM965/GL960 Integrated Graphics Controller (secondary) (rev 0c)

# Debian packages for hyprland have hit unstable and we attempt to build
# debs locally for devuan using gbp.

DOTFILE_SRC="/space/code_repositories/hypr/dotfiles/Hyprland-config"

# For sound and screensharing
# autostart with
sudo apt-get install -y \
  pipewire \
  wireplumber

sudo apt-get install -y \
  waypipe \
  brightnessctl \
  brightness-udev \
  playerctl \
  shutter \
  wf-recorder \
  wl-clipboard \
  zathura \
  ranger
#  swaylock

# team-hyprland packages (I made that up, there is a team-sway)
sudo apt-get install -y \
  libudis86-0 \
  udcli \
  hyprwayland-scanner \
  libhyprlang2 \
  libhyprcursor0 \
  libhyprutils0 \
  hyprcursor-util \
  hyprland-protocols \
  hyprland \
  hyprland-backgrounds \
  hyprpaper

## ranger - Console File Manager
cp -a ${DOTFILE_SRC}/ranger ~/.config

## zathura document viewer
cp -a ${DOTFILE_SRC}/zathura ~/.config

## swaylock config
cp -a ${DOTFILE_SRC}/swaylock ~/.config

## hyprland config
mv ${HOME}/.config/hypr/hyprland.conf ${HOME}/.config/hypr/hyprland.conf.bak
cp -a ${DOTFILE_SRC}/hypr/* ${HOME}/.config/hypr/

## hyprpaper config
conf_print_hyprpaper() {
  cat <<-EOF
preload = ${HOME}/Pictures/Wallpaper/default.png
# if more than one preload is desired then continue to preload other backgrounds
preload = ${HOME}/Pictures/Wallpaper/default.png
# .. more preloads

# set the default wallpaper(s) seen on initial workspace(s) --depending on the number of monitors used
wallpaper = monitor1,${HOME}/Pictures/Wallpaper/default.jpg

# if more than one monitor in use, can load a 2nd image
# wallpaper = monitor2,/path/to/next_image.png
# .. more monitors

# enable splash text rendering over the wallpaper
splash = true

# fully disable ipc
# ipc = off
EOF
}
conf_print_hyprpaper | tee ~/.config/hypr/hyprpaper.conf

# Add the wallpaper images
PAPER_DIR="${HOME}/Pictures/Wallpaper"
mkdir -p ${PAPER_DIR}
cp ${DOTFILE_SRC}/Wallpaper/* ${PAPER_DIR}/
ln -s ${PAPER_DIR}/samurai_strike.jpg ${PAPER_DIR}/default.jpg
ln -s ${PAPER_DIR}/street-tn.png ${PAPER_DIR}/default.png

## Status bar
# [eww](https://elkowar.github.io/eww/) rust based not packaged.
#
# waybar
# exec-once=waybar
sudo apt-get install -y \
  waybar

## waybar config
# cp -a /etc/xdg/waybar into ~/.config/
# sed -i 's|sway\/workspaces|hyprland\/workspaces/g' ~/.config/waybar/config
# sed -i 's|sway\/workspaces|hyprland\/workspaces/g' ~/.config/waybar/config.jsonc

# or use a pre configured set of dotfiles as a starting point:
# https://github.com/knightfallxz/Hyprland-config
cp -a ${DOTFILE_SRC}/waybar ~/.config

# - default have pulseaudio needs to be changed to pipewire/wireplumber
# https://github.com/Alexays/Waybar/wiki/
# https://github.com/Alexays/Waybar/wiki/Module:-WirePlumber
# https://github.com/Alexays/Waybar/wiki/Module:-Hyprland
#

# application launcher for wlroots based wayland compositors
sudo apt-get install -y \
  wofi

cp -a ${DOTFILE_SRC}/wofi ~/.config

# XDG Portal - Packaged on gitea
sudo apt-get install -y xdg-desktop-portal-hyprland

# Notification daemon - pick one
# mako is minimal
# swaync less so.
sudo apt-get install -y \
  dunst
#  sway-notification-center \
#  mako-notifier

cp -a ${DOTFILE_SRC}/dunst ~/.config

# Terminal - Packaged or configured in automate scripts here for reference.
# More kitty binds in hyprland.conf examples than wezterm.
# sudo apt-get install -y \
#   kitty \
#   wezterm
# cp -a ${DOTFILE_SRC}/kitty ~/.config

# Authenitication Agent
# /etc/xdg/autostart/polkit-kde-authentication-agent-1.desktop
# autostart it with
# $ exec-once=/usr/lib/polkit-kde-authentication-agent-1
# exec-once=/usr/lib/x86_64-linux-gnu/libexec/polkit-kde-authentication-agent-1
sudo apt-get install -y \
  hyprpolkitagent
#  polkit-kde-agent-1
