#!/bin/bash

SETUP_SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

source $SETUP_SCRIPT_DIR/config.sh 
source $SETUP_SCRIPT_DIR/programs/os/os_install.sh

source $SETUP_SCRIPT_DIR/../scripts/colors.sh 
source $SETUP_SCRIPT_DIR/../scripts/graphics.sh 
source $SETUP_SCRIPT_DIR/../scripts/check_installed.sh 

os_count=${#os_list[@]}
pckgmngr_count=${#pckgmngr_list[@]}

OS="NONE"
OS_NO=99

exit_abord()
{
	graphics_error "Linux instalation Script Has been aborded"
}

exit_sucsess()
{
	graphics_success "Linux instalation Script Has ended with Sucsess"
}

echo ""
graphics_header "Wellcome to my Linux instalation Script"
echo ""

graphics_comment "SYSTEM IMFORMATION:"
graphics_comment "Cpu Core Count = $CPU_CORE_COUNT"
graphics_comment "Configuration dir = $USER_DOTFILE_DIR"
graphics_comment "Fonts dir = $FONTS_DIR"
graphics_comment "Wallpapers dir = $WALLPAPERS_DIR"
echo ""

graphics_indication "The Following programs will be installed :"

color_start "themeFocus"
for i in "${!common_programs_list[@]}"; 
do 
	printf "${common_programs_list[$i]} | "
done
echo ""
echo ""
color_stop

graphics_indication "Please Select your OS"
for i in "${!os_list[@]}"; 
do 
	color_start "themeSelect"
	printf "[$(($i + 1))] ${os_list[$i]}"
	color_stop
   	echo -e " install cmd: \"${pckgmngr_list[$i]}\""
done
echo ""
echo ""
color_start "themeUserInput"
read -p "Select your os or ( q to quit ) : " answer
color_stop

if [[ "$answer" == "q" ]]; then
	exit_abord
else
	if [ $answer -lt $(($os_count + 1)) ]; then
		answer=$(( $answer - 1 ))
		OS=${os_list[$answer]}
		OS_NO=$answer
		install_start
	else
		echo " the given nurber was not correct >>ABORDING<<"
		exit_abord
	fi
fi
