#!/bin/bash

# Run as root
# Kitty tab bar: https://github.com/kovidgoyal/kitty/discussions/4447#discussioncomment-3240635
# Copy everything from .config

###################################################################
# SYMBOLIC LINKS
###################################################################

ln -s ~/dotfiles/wallpapers ~/wallpapers
ln -s ~/dotfiles/.fonts ~/.fonts

# Starship config
ln -s ~/dotfiles/.config/starship.toml ~/.config/starship.toml
ln -s ~/dotfiles/.config/starship.toml /root/.config/starship.toml

# Fix Electron Apps Wayland scaling issue:
# If app doesn't work, add "--no-sandbox" to app in /usr/share/applications/
ln -s ~/dotfiles/.conf/environment.d ~/.config/environment.d

###################################################################
# PACKAGES
###################################################################

# Hyperland stuff
# uwsm needed for launching hypr on boot
pacman -S uwsm hyprland xdg-desktop-portal-hyprland hyprpaper qt5-wayland

# Basic essentials
pacman -S waybar dunst libnotify wofi pipewire brightnessctl wireless_tools man-db man-pages 

# Yazi dependencies (but also useful otherwise)
pacman -S yazi ffmpeg poppler fd p7zip

# Other software
pacman -S stress btop  bat neovim nano dust fastfetch imv wl-clipboard

# Screenshots
pacman -S grim slurp

# Bash prompt bar
pacman -S starship

# Additional Pacman utils like "checkupdates"
sudo pacman -S pacman-contrib

# Networking
# For connecting to eduroam install config with this script: https://cat.eduroam.org/
# wpa_supplicant is dependency of networkmanager that was not installed for some reason.
# Run networkmanager with "nmcli dev wifi connect 'ssid' password 'password'"
pacman -S networkmanager wpa_supplicant

# Waybar: https://github.com/sejjy/mechabar/tree/classic
# Dependencies: 
# wireplumber is Session/policy manager implementation for PipeWire
pacman -S cava bluez-utils bluez pipewire-pulse ttf-jetbrains-mono-nerd wireplumber
yay -S rofi-lbonn-wayland-git bluetui
systemctl enable --now bluetooth.service

###################################################################
# TINKERING
###################################################################

# Launch directly into hyprlock and skipping login
echo '[Service]\nExecStart=\nExecStart=-/sbin/agetty --noreset --noclear --autologin alex %I $TERM' | sudo tee /etc/systemd/system/getty@tty1.service.d/override.conf > /dev/null && sudo systemctl enable getty@tty1

# Battery optimization
cp ~/dotfiles/etc/tlp.conf /etc/
pacman -S tlp tlp-rdw
systemctl enable --now tlp.service
systemctl enable --now NetworkManager-dispatcher.service
systemctl mask systemd-rfkill.service # Needed for auto-disable of BT on boot by TLP
systemctl mask systemd-rfkill.socket # Also needed for auto-disable BT

# Make wireguard connection persistent in /etc/wireguard 
#   and ensure wireguard restarts when network is re-established after loss
echo "PersistentKeepalive = 25" >> /etc/wireguard/home.conf
cp ~/dotfiles/etc/NetworkManager/dispatcher.d/* /etc/NetworkManager/dispatcher.d/

###################################################################
# MANUAL CONFIGURATION REQUIRED
###################################################################

# After installing Anki, force Anki to use Wayland by replacing Exec= in /usr/local/share/applications/anki.desktop
# Exec=env ANKI_WAYLAND=1 anki %f
