#!/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_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_BLANK='\033[0m'      C_FLASH='\033[1;5m'

TOOLKIT_PATH="$(pwd)" # "${HOME}/ps4"

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

echo -e "${C_GRN_BLD}PS4 HDD Unmounter v1.5 by Berion"
echo -e "${C_YLW}Script allows to unmount all HDD partitions."
echo
echo -e "${C_RED_BLD}Confirm root permissions every time You will be asked for!${C_BLANK}"
echo

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

# For current umount method:
sudo umount -l /dev/mapper/ps4hdd_01							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_02							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_03							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_04							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_05							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_06							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_07							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_08							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_09							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_10							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_11							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_12							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_13							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_14							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_15							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_16							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_17							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_18							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_19							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_20							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_21							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_22							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_23							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_24							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_25							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_26							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_27							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_28							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_29							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_30							&> /dev/null
sudo umount -l /dev/mapper/ps4hdd_31							&> /dev/null

# For old umount method:
sudo umount -l ${TOOLKIT_PATH}/storage/hdd/app_reserved	&> /dev/null
sudo umount -l ${TOOLKIT_PATH}/storage/hdd/app_temp		&> /dev/null
sudo umount -l ${TOOLKIT_PATH}/storage/hdd/eap_user		&> /dev/null
sudo umount -l ${TOOLKIT_PATH}/storage/hdd/eap_vsh			&> /dev/null
sudo umount -l ${TOOLKIT_PATH}/storage/hdd/preinst			&> /dev/null
sudo umount -l ${TOOLKIT_PATH}/storage/hdd/preinst2		&> /dev/null
sudo umount -l ${TOOLKIT_PATH}/storage/hdd/system			&> /dev/null
sudo umount -l ${TOOLKIT_PATH}/storage/hdd/system_b		&> /dev/null
sudo umount -l ${TOOLKIT_PATH}/storage/hdd/system_ex		&> /dev/null
sudo umount -l ${TOOLKIT_PATH}/storage/hdd/system_ex_b	&> /dev/null
sudo umount -l ${TOOLKIT_PATH}/storage/hdd/system_data	&> /dev/null
sudo umount -l ${TOOLKIT_PATH}/storage/hdd/update			&> /dev/null
sudo umount -l ${TOOLKIT_PATH}/storage/hdd/user				&> /dev/null

sudo cryptsetup remove ps4hdd_01									&> /dev/null
sudo cryptsetup remove ps4hdd_03									&> /dev/null
sudo cryptsetup remove ps4hdd_05									&> /dev/null
sudo cryptsetup remove ps4hdd_07									&> /dev/null
sudo cryptsetup remove ps4hdd_09									&> /dev/null
sudo cryptsetup remove ps4hdd_10									&> /dev/null
sudo cryptsetup remove ps4hdd_11									&> /dev/null
sudo cryptsetup remove ps4hdd_12									&> /dev/null
sudo cryptsetup remove ps4hdd_13									&> /dev/null
sudo cryptsetup remove ps4hdd_17									&> /dev/null
sudo cryptsetup remove ps4hdd_19									&> /dev/null
sudo cryptsetup remove ps4hdd_25									&> /dev/null
sudo cryptsetup remove ps4hdd_27									&> /dev/null
sudo cryptsetup remove ps4hdd_29									&> /dev/null
sudo cryptsetup remove ps4hdd_31									&> /dev/null

sudo losetup -d /dev/loop27										&> /dev/null
sudo rmmod ufs															&> /dev/null

echo
echo -e "Now you ${C_YLW_BLD}must${C_BLANK} see that all PS4 HDD partitions are ${C_YLW_BLD}NOT${C_BLANK} mounted!"
echo
echo -e "${C_RED}If some still are, you ${C_RED_BLD}CANNOT${C_RED} disconnect drive or turn off Linux"
echo -e "without risk of ${C_RED_BLD}DAMAGE${C_RED} logic structure on HDD! In such case, try"
echo -e "\"sync\" and after that \"sudo umount -f <mount point>\"${C_BLANK}"
echo
lsblk -p -o MODEL,NAME,SIZE,MOUNTPOINT
echo

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

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