#!/bin/bash

# START

if [[ $EUID -ne 0 ]]; then
   echo -e "\033[0;31mThis script must be run as root!\033[0m" 1>&2
   exit 1
fi

if [ "$#" -ne 1 ]; then
    echo -e "\033[0;31mArchi name has to be provided as single parameter!\033[0m"
    exit 1
fi

if [[ $1 =~ ^ARCHI([0-9]{2})?[0-9]{2}$ && !($1 =~ ^ARCHI00[0-9]{2}$) ]]; then

	if [[ -d "/home/$1" && ! -L "/home/$1" ]] ; then
		echo "Uninstalling completely $1..."	
		read -p "Are you sure? (Yy/Nn) " -n 1 -r
		echo
		if [[ ! $REPLY =~ ^[Yy]$ ]]; then
			exit 1
		fi	
	else
		echo -e "\033[0;31mThere is no $1 installed! Exiting...\033[0m"
		exit 1
	fi

else
	echo -e "\033[0;31mIncorrect archi name! Exiting...\033[0m" 1>&2
	exit 1
fi

sudo rm -Rf /home/$1

echo -e "\033[0;32mDeinstallation Complete!\033[0m"

exit 0
