#!/bin/bash

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


#################################################################################
# INCLUDES									#
#################################################################################
#Include of all the scripts required fo the instalation
source $SETUP_SCRIPT_DIR/scripts/colors.sh 
source $SETUP_SCRIPT_DIR/scripts/graphics.sh 
source $SETUP_SCRIPT_DIR/scripts/check_installed.sh 
source $SETUP_SCRIPT_DIR/programs/installCommands.sh

#################################################################################
# DECLARATIONS 									#
#################################################################################
#Varibale to define de defualt dorectories for the installs
DOTFILE_DIR=$MAIN_DIR/dotfiles
USER_DOTFILE_DIR=/home/$USER/.config
FONTS_DIR="/usr/local/share/fonts"
WALLPAPERS_DIR="/home/$USER"

# Gathering the core count of the cpu
CPU_CORE_COUNT=$(grep -c ^processor /proc/cpuinfo)

# Platform, TODO: to make a selection
PLATFORM="laptop"

# Defualt sleep time
sleepTime=0.2

# Declaration of OS and their package managers their nurical order is imporant
os_list=(debian arch raspberry)
pckgmngr_list=('sudo apt -y install' 'sudo pacman -S' 'raspi install')

# Declaration of common packages and their config files forr al linux distros
# These pacakges must be found in the standart repositories
common_programs_list=(htop curl tmux git mc wget sudo unzip cmake make gcc exa scrot acpi)

# These pacakges must not be found in the standart repositories and can be gits or direct installs
custom_installs_debian=(vim fish dmenu fonts wallpaper i3 picom alacritty qownotes sddm)
#custom_installs_arch=(vim fish dmenu fonts wallpaper i3 picom alacritty qownotes sddm)
custom_installs_arch=(dmenu)
custom_installs_raspberry=(vim fish dmenu fonts wallpaper i3 picom qownotes alacritty sddm)

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

OS="NONE"
OS_NO=99


#################################################################################
# FUNTIONS 									#
#################################################################################
# function to be callerd whent he instaltion had an error
exit_abord()
{
	graphics_error "Linux instalation Script Has been aborded"
}

# Function called when the installation has finished
exit_sucsess()
{
	graphics_success "Linux instalation Script Has ended with Sucsess"
}


#################################################################################
# UI	 									#
#################################################################################
cd $SETUP_SCRIPT_DIR

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

# Prints information
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 :"

#Gathering and echoing the commen programms list
color_start "themeFocus"
for i in "${!common_programs_list[@]}"; 
do 
	printf "${common_programs_list[$i]} | "
done
echo ""
echo ""
color_stop

# Os selection menu, each os has his name and his number.
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
	#Gets the os name an nuber which will be used by each install script an installCommand.sh
	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

