#!/bin/bash
clear

C_RED_BLD='\033[1;31m' C_YLW_BLD='\033[1;93m' C_GRN_BLD='\033[1;32m' C_BLU_BLD='\033[1;94m' C_CYN_BLD='\033[1;36m' C_WHT_BLD='\033[1;37m'	C_GRY_BLD='\033[1;30m'
C_RED='\033[0;91m'	  C_YLW='\033[0;93m'		 C_GRN='\033[0;92m'		C_BLU='\033[0;94m'	  C_CYN='\033[0;36m'		 C_WHT='\033[0;37m'		C_GRY='\033[0;30m'
C_BLANK='\033[0m'      C_FLASH='\033[1;5m'

TOOLKIT_PATH="$(pwd)" # "${HOME}/ps4"
TIME_STAMP=$(date +%Y%m%d%H%M%S)

# ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

echo -e "${C_GRN_BLD}Reporter v1.3 by Berion"
echo -e "${C_YLW}Script helping troubleshooting."
echo
echo -e "${C_RED_BLD}Confirm root permissions every time You will be asked for!${C_BLANK}"
echo

# ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

echo -e "${C_CYN_BLD}STEP 1: Devices${C_BLANK}"
echo -e "Choose your ${C_YLW_BLD}disk from PS4${C_BLANK} (type e.g. /dev/sdx) from below device list:"
echo
lsblk -p -o MODEL,NAME,SIZE,LABEL,FSTYPE,MOUNTPOINT
echo
read DEVICE
echo -e "OK, so you've chosen: \"${C_YLW_BLD}${DEVICE}${C_BLANK}\"."
echo
sudo -v
echo
echo -e "${C_CYN_BLD}STEP 2: Reporting${C_BLANK}"
echo

echo -e "${C_YLW_BLD}System Informations:${C_BLANK}"
hostnamectl | grep "Operating System"
hostnamectl | grep "Kernel"
echo
echo -e "${C_YLW_BLD}Partitions & Mappers:${C_BLANK}"
lsblk -b -p -o MODEL,NAME,SIZE,LABEL,FSTYPE,MOUNTPOINT ${DEVICE}
if [[ -e ${DEVICE}27 ]]; then
	echo -e "${C_WHT_BLD}mini dump from \"${DEVICE}27\":${C_BLANK}"
	sudo hexdump -C ${DEVICE}27 | head -4
fi
echo
if [[ -e /dev/mapper/ps4hdd_27 ]]; then
	echo -e "${C_WHT_BLD}mini dump from \"/dev/mapper/ps4hdd_27\":${C_BLANK}"
	sudo hexdump -C /dev/mapper/ps4hdd_27 | head -12
fi

echo -e "${C_YLW_BLD}Applications:${C_BLANK}"
cd "${TOOLKIT_PATH}/apps/" && ls -1 && echo
echo -e "${C_YLW_BLD}Keys:${C_BLANK}"
cd "${TOOLKIT_PATH}/keys/" && ls -1 && echo
echo -e "${C_YLW_BLD}Scripts:${C_BLANK}"
cd "${TOOLKIT_PATH}/"

echo "PS4 HDD Backuper           $(sed -n '/Berion/p' "PS4 HDD Backuper.sh"				| awk '{print $6}')"
echo "PS4 HDD Keygen             $(sed -n '/Berion/p' "PS4 HDD Keygen.sh"					| awk '{print $6}')"
echo "PS4 HDD Mounter            $(sed -n '/Berion/p' "PS4 HDD Mounter.sh"					| awk '{print $6}')"
echo "PS4 HDD Tasker             $(sed -n '/Berion/p' "PS4 HDD Tasker.sh"					| awk '{print $6}')"
echo "PS4 HDD Unmounter          $(sed -n '/Berion/p' "PS4 HDD Unmounter.sh"				| awk '{print $6}')"
echo "PS4 USB Formatter          $(sed -n '/Berion/p' "PS4 USB Formatter.sh"				| awk '{print $6}')"
echo "Unattended PS4 HDD Mounter $(sed -n '/Berion/p' "Unattended PS4 HDD Mounter.sh"	| awk '{print $6}')"

# ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function function_report() {
	echo "System Informations:"
	hostnamectl | grep "Operating System"
	hostnamectl | grep "Kernel"
	echo
	echo "Partitions & Mappers:"
	lsblk -b -p -o MODEL,NAME,SIZE,LABEL,FSTYPE,MOUNTPOINT ${DEVICE}
	if [[ -e ${DEVICE}27 ]]; then
		echo "mini dump from \"${DEVICE}27\":"
		sudo hexdump -C ${DEVICE}27 | head -4
	fi
	echo
	if [[ -e /dev/mapper/ps4hdd_27 ]]; then
		echo "ini dump from \"/dev/mapper/ps4hdd_27\":"
		sudo hexdump -C /dev/mapper/ps4hdd_27 | head -12
	fi

	echo "APPLICATIONS:"
	cd "${TOOLKIT_PATH}/apps/" && ls -1 && echo
	echo "Keys:"
	cd "${TOOLKIT_PATH}/keys/" && ls -1 && echo
	echo "Scripts:"
	cd "${TOOLKIT_PATH}/"

	echo "PS4 HDD Backuper           $(sed -n '/Berion/p' "PS4 HDD Backuper.sh"				| awk '{print $6}')"
	echo "PS4 HDD Keygen             $(sed -n '/Berion/p' "PS4 HDD Keygen.sh"					| awk '{print $6}')"
	echo "PS4 HDD Mounter            $(sed -n '/Berion/p' "PS4 HDD Mounter.sh"					| awk '{print $6}')"
	echo "PS4 HDD Tasker             $(sed -n '/Berion/p' "PS4 HDD Tasker.sh"					| awk '{print $6}')"
	echo "PS4 HDD Unmounter          $(sed -n '/Berion/p' "PS4 HDD Unmounter.sh"				| awk '{print $6}')"
	echo "PS4 USB Formatter          $(sed -n '/Berion/p' "PS4 USB Formatter.sh"				| awk '{print $6}')"
	echo "Unattended PS4 HDD Mounter $(sed -n '/Berion/p' "Unattended PS4 HDD Mounter.sh"	| awk '{print $6}')"
	}

function_report >> "${TOOLKIT_PATH}/logs/report_${TIME_STAMP}.txt"
echo
echo -e "Log has been created in:"
echo -e "${C_YLW}${TOOLKIT_PATH}/logs/${C_YLW_BLD}report_<time stamp>.txt${C_BLANK}"

# ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

unset DEVICE
unset TIME_STAMP

echo -e ${C_WHT_BLD}
read -p "All done. Press enter key to exit. "
