#!/bin/bash
# My env install script ~ Skiqqy.

declare -A osInfo;
osInfo[/etc/redhat-release]=dnf
osInfo[/etc/arch-release]=pacman
osInfo[/etc/debian_version]=apt-get
osInfo[/etc/alpine-release]=apk

for f in "${!osInfo[@]}"
do
    if [[ -f $f ]];then
        echo Package manager: ${osInfo[$f]}
        if [[ ${osInfo[$f]} = "pacman" ]]; then
            ## Arch/ Manjaro ##
            echo "y" | sudo pacman -Syu
            echo "y" | sudo pacman -S vim tmux git make zsh pkg-config gcc feh imagemagick
            echo "y" | sudo pacman -S xorg-server xorg-xinit libxft libxinerama xcompmgr # For my dwm

            # Install yay
            git clone https://aur.archlinux.org/yay.git /tmp/yay
            cd /tmp/yay || { echo "could not cd to /tmp/yay" && exit 1; }
            makepkg -si # Build
            echo "y" | yay -S powerline scrot

            # Install my launch manager, i typically only use this with arch, hence why its only here
            git clone --recurse-submodules https://github.com/nullgemm/ly.git /tmp/ly
            cd /tmp/ly || { echo "could not cd to /tmp/ly" && exit 1; }
            sudo make install

            echo "Ly installed, to enable: $ systemctl enable ly.service"

        elif [[ ${osInfo[$f]} = "dnf" ]]; then
            ## Fedora/ RedHat ##
            sudo dnf install vim tmux git make zsh powerline tmux-powerline acpi
        elif [[ ${osInfo[$f]} = "apt-get" ]]; then
            ## Debian ##
            sudo apt update
            sudo apt install vim tmux git make zsh powerline
        elif [[ ${osInfo[$f]} = "apk"  ]]; then
            ## Alpine-Linux
            sudo apk add vim tmux git make zsh # no powerline package
        fi
        echo "finished with ${osInfo[$f]}"
    fi
done

cd "$HOME" || exit 1

# Clone repos
dir="$HOME/repos"
mkdir "$dir"
git clone https://git.sr.ht/~skiqqy/.dotfiles "$dir/.dotfiles"
git clone https://git.sr.ht/~skiqqy/.tmux     "$dir/.tmux"

dir="$HOME/Builds"
mkdir "$dir"
git clone https://git.sr.ht/~skiqqy/suckless  "$dir/suckless"

# Begin Installing
"$HOME/Builds/suckless/install" all --sudo # Install everything for my env
make -C "$HOME/repos/.dotfiles"
cd "$HOME/repos/.tmux" || exit 1
./install.sh
