#!/bin/bash

# I use some of Luke Smiths scripts and although they don't often update, they are known to.
# The output is going to include a bunch of copy errors as I'm just copying each file in this directory from his .local/bin back to here, obviously my custom scripts won't exist so they'll fail.

echo "This script will clone Luke Smith's voidrice and copy the scripts from it that I use."
read -r -p "Are you sure you want to continue [Y/n]" input

case $input in
    [nN][oO] | [nN])
        echo "Okay, exiting..."
        exit 0
        ;;
    *)
        printf "\n"
        ;;
esac

git clone https://github.com/LukeSmithxyz/voidrice

printf "\nCopying scripts...\n"

if [ -d voidrice ]; then
    for script in "$HOME"/.local/bin/*; do
        if [ -f "./voidrice/.local/bin/${script##*/}" ]; then
            cp "./voidrice/.local/bin/${script##*/}" "$HOME/.local/bin/" -v
        fi
    done

    for cron in "$HOME"/.local/bin/cron/*; do
        if [ -f "./voidrice/.local/bin/cron/${cron##*/}" ]; then
            cp "./voidrice/.local/bin/cron/${cron##*/}" "$HOME/.local/bin/cron/" -v
        fi
    done

    printf "\nRemoving voidrice..."
    rm -rf ./voidrice && printf "\nUpdate Complete."
else
    echo "directory voidrice does not exist"
fi
