#!/bin/bash
post_install() {
THEME_NAME="Fallout"
# title			:uno pre installation
	# author		:Glenn Cady <theemahn@ultimateedition.info>
	# date			:03/08/2018
	# ============================================================================
	#Pull info we will use to compare against later
	IUSER=${SUDO_USER:-$USER}
	HOME="/home/$IUSER"
	# Check inode of rootfs if anything other then 2 we are in a chroot environment
	# use above IUSER results to further our cause.& guarantee our success ;)
	# Inform user of current findings:
	root_inode=$(stat -c %i /);
	if [ $root_inode -ne 2 ]; then echo "Chroot environment detected."; else echo "We are NOT in a chroot environment.  User detected as ${IUSER}"; fi
CONFIG_FILE="${HOME}/.config/gtk-3.0/settings.ini"
if [[ -f "${CONFIG_FILE}" ]]; then
# Use sed to replace the line containing gtk-theme-name
	sed -i "s/^gtk-theme-name=.*/gtk-theme-name=${THEME_NAME}/" "${CONFIG_FILE}"
fi
# If the file or the entry doesn't exist, you might need to add it:
if ! grep -q "gtk-theme-name=" "${CONFIG_FILE}"; then
	echo "gtk-theme-name=${THEME_NAME}" >> "${CONFIG_FILE}"
fi

CONFIG_FILE="${HOME}/.gtkrc-2.0"

if [[ -f "${CONFIG_FILE}" ]]; then
# Use sed to replace the line containing gtk-theme-name
	sed -i "s/^gtk-theme-name=.*/gtk-theme-name=${THEME_NAME}/" "${CONFIG_FILE}"
fi
# If the file or the entry doesn't exist, you might need to add it:
if ! grep -q "gtk-theme-name=" "${CONFIG_FILE}"; then
	echo "gtk-theme-name=${THEME_NAME}" >> "${CONFIG_FILE}"
fi

CONFIG_FILE="${HOME}/.config/gtk-4.0/settings.ini"
if [[ -f "${CONFIG_FILE}" ]]; then
# Use sed to replace the line containing gtk-theme-name
	sed -i "s/^gtk-theme-name=.*/gtk-theme-name=${THEME_NAME}/" "${CONFIG_FILE}"
fi
# If the file or the entry doesn't exist, you might need to add it:
if ! grep -q "gtk-theme-name=" "${CONFIG_FILE}"; then
	echo "gtk-theme-name=${THEME_NAME}" >> "${CONFIG_FILE}"
fi

CONFIG_FILE="${HOME}/.config/plasmarc"
if [[ -f "${CONFIG_FILE}" ]]; then
# Use sed to replace the line containing gtk-theme-name
	sed -i "s/^name=.*/name=${THEME_NAME}/" "${CONFIG_FILE}"
fi
# If the file or the entry doesn't exist, you might need to add it:
if ! grep -q "name=" "${CONFIG_FILE}"; then
	echo "name=${THEME_NAME}" >> "${CONFIG_FILE}"
fi

CONFIG_FILE="${HOME}/.config/gtk-4.0/settings.ini"
if [[ -f "${CONFIG_FILE}" ]]; then
# Use sed to replace the line containing gtk-theme-name
	sed -i "s/^gtk-sound-theme-name=.*/gtk-sound-theme-name=${THEME_NAME}/" "${CONFIG_FILE}"
fi
# If the file or the entry doesn't exist, you might need to add it:

# SDDM
CONFIG_FILE="/etc/sddm.conf"
if [[ -f "${CONFIG_FILE}" ]]; then
	sed -i "s/^Current=.*/Current=${THEME_NAME}/" /etc/sddm.conf
fi
CONFIG_FILE="/etc/sddm.conf.d/kde_settings.conf"
if [[ -f "${CONFIG_FILE}" ]]; then
	sed -i "s/^Current=.*/Current=${THEME_NAME}/" /etc/sddm.conf.d/kde_settings.conf
fi

# SPLASH
CONFIG_FILE="${HOME}/.config/ksplashrc"
if [[ -f "${CONFIG_FILE}" ]]; then
# Use sed to replace the line containing gtk-theme-name
	sed -i "s/^Theme=.*/Theme=${THEME_NAME}/" "${CONFIG_FILE}"
fi

# Plasmarc
CONFIG_FILE="${HOME}/.config/plasmarc"
if [[ -f "${CONFIG_FILE}" ]]; then
# Use sed to replace the line containing gtk-theme-name
	sed -i "s/^name=.*/name=${THEME_NAME}/" "${CONFIG_FILE}"
fi
# Sound Theme
SOUNDTHEME="Fallout Sound Scheme"
CONFIG_FILE="${HOME}/.config/gtk-3.0/settings.ini"
if [[ -f "${CONFIG_FILE}" ]]; then
# Use sed to replace the line containing gtk-theme-name
	sed -i "s/^gtk-sound-theme-name=.*/gtk-sound-theme-name=${THEME_NAME}/" "${CONFIG_FILE}"
fi
CONFIG_FILE="${HOME}/.config/kdeglobals"
if [[ -f "${CONFIG_FILE}" ]]; then
# Use sed to replace the line containing gtk-theme-name
	sed -i "s/^gtk-sound-theme-name=.*/gtk-sound-theme-name=${THEME_NAME}/" "${CONFIG_FILE}"
fi
if [[ -f "${CONFIG_FILE}" ]]; then
# Use sed to replace the line containing gtk-theme-name
	sed -i "s/^LookAndFeelPackage=.*/LookAndFeelPackage=${THEME_NAME}/" "${CONFIG_FILE}"
fi
if [[ -f "${CONFIG_FILE}" ]]; then
# Use sed to replace the line containing gtk-theme-name
	sed -i "s/^ColorScheme=.*/ColorScheme=${THEME_NAME}/" "${CONFIG_FILE}"
fi
QTHEME="\"${THEME_NAME}"\"
CONFIG_FILE="${HOME}/.config/xsettingsd/xsettingsd.conf"
if [[ -f "${CONFIG_FILE}" ]]; then
	sed -i "s/^Net\/SoundThemeName.*/Net\/SoundThemeName ${QTHEME}/" "${CONFIG_FILE}"
fi
echo "Please Reboot for Fallout theme to take effect."
}
post_upgrade() {
post_install
}
