#!/bin/bash

#This script will automate adding all of our additions and changes on top of a vanilla intallation of Kali Linux.
#It has not been tested with Parrot.

function pause(){
    read -p "$*"
}

#Root check!
if [ "$EUID" -ne 0 ]
then
    whiptail --backtitle "Pentest Conversion Script" --title "Welcome" --msgbox "You are not signed in as root.  This script will prompt for sudo as needed." 7 79
fi

whiptail --backtitle "Pentest Conversion Script" --title "Welcome" --msgbox "This script will add our changes on top of your Kali installation." 7 70

REPO=$(whiptail --backtitle "Pentest Conversion Script" --title "Repository" --menu "Which repository are you going to use?" 10 60 2 \
    "default" "The distribution's default repository" \
    "local" "A repository hosted on your local network" 3>&1 1>&2 2>&3)

if [ $REPO == "local" ];
then
    REPO=$(whiptail --backtitle "Pentest Conversion Script" --title "Local Repository" --inputbox "What is the IP address of your local repository?" \
    10 60 3>&1 1>&2 2>&3)
fi

if [ $REPO != "default" ];
then
	sudo cp /etc/apt/sources.list /etc/apt/sources.list.original
    sudo sed -i "s|archive.kali.org|$REPO|g" /etc/apt/sources.list
fi

sudo apt update
sudo apt upgrade -y

xargs -a <(awk '! /^ *(#|$)/' "./config/software.list.chroot") -r -- sudo apt install -y
bash ./debs/get-debs.sh
rm ./build/.gitignore
sudo dpkg -i ./build/

sudo rsync -HAXav ./filesystem/ /
if [ "$EUID" -ne 0 ]
then
    cp -rv /etc/skel/ $HOME
fi

sudo bash ./config/pentest-distro-builder.chroot

if (whiptail --backtitle "Pentest Conversion Script" --title "Complete" --yesno "The script is now complete.  A reboot is recommended.\nWould you like to reboot now?" 10 60)
then
    whiptail --backtitle "Pentest Conversion Script" --title "Rebooting!" --msgbox "Thank you for using this script.  Enjoy your new Kali!" 8 60
    sudo reboot
else
    whiptail --backtitle "Pentest Conversion Script" --title "Finished!" --msgbox "Thank you for using this script.  Enjoy your new Kali!" 8 30
    exit 1
fi
