#!/bin/sh

#-----------------------------------
# Name:     install-dmenu-inkletblot
# Version:  1.0.0
# Author:   Solomon Laing
# Description:
# Installs my customisation of dmenu
#-----------------------------------

clear

echo "This script is going to install my dotfiles."

read -r -p "Are You Sure? [y/N] " input

case $input in
[yY][eE][sS] | [yY])
    echo "The program will continue..."
    ;;
[nN][oO] | [nN])
    exit 0
    ;;
*)
    echo "Invalid input..."
    exit 1
    ;;
esac

function config {
   /usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@
}

if [ ! -d $HOME/.cfg ]; then
    git clone --bare https://gitlab.inkletblot.com/inkletblot/config.git $HOME/.cfg
fi

echo "

The script will now attempt to install the configs, if configs have been installed using the method found here: https://www.atlassian.com/git/tutorials/dotfiles, there will be issues.

"

echo "There are configs for laptops, my personal desktop, and a general config. Which would you like to intsall?"
echo "Standard, 1"
echo "Laptop (general), 2"
echo "Desktop (personal), 3"
read -r -p  "Choose one (default=1): " choice

case $choice in
    3)
        config checkout arch-desktop
    ;;
    2)
        config checkout arch-laptop
    ;;
    *)
        config checkout main
    ;;
esac

if [ $? = 0 ]; then
    echo "Checked out config.";
else
    echo "Backing up pre-existing dot files.";
    mkdir -p $HOME/.config-backup
    config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} mv $HOME/{} $HOME/.config-backup/{}
fi;

case $choice in
    3)
        config checkout arch-desktop
    ;;
    2)
        config checkout arch-laptop
    ;;
    *)
        config checkout main
    ;;
esac

config config status.showUntrackedFiles no
