#/bin/sh
clear
echo "Tiger Sierra Theme - Version 2"
echo "by swamprock -- AmazingHenry -- AphoticD -- zappaesque"
echo "with help from the members of the MacRumors PowerPC forum"
echo "https://forums.macrumors.com/forums/powerpc-macs.145"
echo " "
echo "Please close ALL applications other than Terminal while your files are restored."
echo "ONCE THE RESTORATION STARTS, DO NOT STOP THE PROCESS!"
echo "YOUR SYSTEM WILL BE HOSED IF YOU DO!"
echo "Your system will reboot automatically when the restoration is finished."
echo " "

while true
do
	read -p "Are you sure that you want to uninstall the Tiger Sierra Theme (y/n)?" answer

	case $answer in
		[yY]* )
clear 
echo "Removing Tiger Sierra Theme and restoring Aqua resources..."
cd "$(dirname "$0")"
# Restore Extras.rsrc
sudo rm /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Resources/Extras.rsrc

sudo mv  /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Resources/Extras.rsrc.backup /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Resources/Extras.rsrc

# Restore Finder.rsrc
sudo rm /System/Library/CoreServices/Finder.app/Contents/Resources/Finder.rsrc 

sudo mv /System/Library/CoreServices/Finder.app/Contents/Resources/Finder.rsrc.backup /System/Library/CoreServices/Finder.app/Contents/Resources/Finder.rsrc

# Restore Spotlight icons
sudo rm /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Normal-1.tiff

sudo mv /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Normal-1.tiff.backup /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Normal-1.tiff

sudo rm /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Normal-6.tiff

sudo mv /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Normal-6.tiff.backup /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Normal-6.tiff 

sudo rm /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Pressed-1.tiff

sudo mv /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Pressed-1.tiff.backup /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Pressed-1.tiff

sudo rm /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Pressed-6.tiff

sudo mv /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Pressed-6.tiff.backup /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Pressed-6.tiff

# Restore AboutThisMac nib and strings

sudo rm /System/Library/CoreServices/loginwindow.app/Contents/Resources/English.lproj/AboutThisMac.nib/classes.nib

sudo rm /System/Library/CoreServices/loginwindow.app/Contents/Resources/English.lproj/AboutThisMac.nib/info.nib

sudo rm /System/Library/CoreServices/loginwindow.app/Contents/Resources/English.lproj/AboutThisMac.nib/keyedobjects.nib

sudo rm /System/Library/CoreServices/loginwindow.app/Contents/Resources/English.lproj/AboutThisMac.strings

sudo mv /System/Library/CoreServices/loginwindow.app/Contents/Resources/English.lproj/AboutThisMac.nib/classes.nib.backup /System/Library/CoreServices/loginwindow.app/Contents/Resources/English.lproj/AboutThisMac.nib/classes.nib

sudo mv /System/Library/CoreServices/loginwindow.app/Contents/Resources/English.lproj/AboutThisMac.nib/info.nib.backup /System/Library/CoreServices/loginwindow.app/Contents/Resources/English.lproj/AboutThisMac.nib/info.nib

sudo mv /System/Library/CoreServices/loginwindow.app/Contents/Resources/English.lproj/AboutThisMac.nib/keyedobjects.nib.backup /System/Library/CoreServices/loginwindow.app/Contents/Resources/English.lproj/AboutThisMac.nib/keyedobjects.nib

sudo mv /System/Library/CoreServices/loginwindow.app/Contents/Resources/English.lproj/AboutThisMac.strings.backup /System/Library/CoreServices/loginwindow.app/Contents/Resources/English.lproj/AboutThisMac.strings

# Restore SecurityAgent tifs

sudo rm /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/applelogo.tif

sudo rm /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/gotoH.tif

sudo rm /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/gotoN.tif

sudo rm /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/homeH.tif

sudo rm /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/homeN.tif

sudo rm /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/MacOSX.tif

sudo rm /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/restartH.tif

sudo rm /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/restartN.tif

sudo rm /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/shutdownH.tif

sudo rm /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/shutdownN.tif

sudo rm /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/sleepH.tif

sudo rm /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/sleepN.tif

sudo mv /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/applelogo.tif.backup /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/applelogo.tif

sudo mv /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/gotoH.tif.backup /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/gotoH.tif

sudo mv /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/gotoN.tif.backup /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/gotoN.tif

sudo mv /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/homeH.tif.backup /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/homeH.tif

sudo mv /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/homeN.tif.backup /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/homeN.tif

sudo mv /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/MacOSX.tif.backup /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/MacOSX.tif

sudo mv /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/restartH.tif.backup /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/restartH.tif

sudo mv /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/restartN.tif.backup /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/restartN.tif

sudo mv /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/shutdownH.tif.backup /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/shutdownH.tif

sudo mv /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/shutdownN.tif.backup /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/shutdownN.tif

sudo mv /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/sleepH.tif.backup /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/sleepH.tif

sudo mv /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/sleepN.tif.backup /System/Library/CoreServices/SecurityAgent.app/Contents/Resources/sleepN.tif

# Restore loginwindow tif
sudo rm /System/Library/CoreServices/loginwindow.app/Contents/Resources/MacOSX.tif

sudo mv /System/Library/CoreServices/loginwindow.app/Contents/Resources/MacOSX.tif.backup /System/Library/CoreServices/loginwindow.app/Contents/Resources/MacOSX.tif

# Restore System Preferences Back/Forward Arrows
sudo rm /Applications/System\ Preferences.app/Contents/Resources/BackAdorn.png

sudo rm /Applications/System\ Preferences.app/Contents/Resources/ForwardAdorn.png

sudo mv /Applications/System\ Preferences.app/Contents/Resources/BackAdorn.png.backup /Applications/System\ Preferences.app/Contents/Resources/BackAdorn.png

sudo mv /Applications/System\ Preferences.app/Contents/Resources/ForwardAdorn.png.backup /Applications/System\ Preferences.app/Contents/Resources/ForwardAdorn.png

# Backup and Install PrefPane icons

sudo rm /System/Library/PreferencePanes/Accounts.prefPane/Contents/Resources/AccountsPref.icns

sudo rm /System/Library/PreferencePanes/Bluetooth.prefPane/Contents/Resources/BluetoothPref.icns

sudo rm /System/Library/PreferencePanes/DateAndTime.prefPane/Contents/Resources/DateAndTime.icns

sudo rm /System/Library/PreferencePanes/DesktopScreenEffectsPref.prefPane/Contents/Resources/DesktopScreenEffectsPref.icns

sudo rm /System/Library/PreferencePanes/Displays.prefPane/Contents/Resources/Displays.icns

sudo rm /System/Library/PreferencePanes/Dock.prefPane/Contents/Resources/Dock.icns

sudo rm /System/Library/PreferencePanes/EnergySaver.prefPane/Contents/Resources/EnergySaver.icns

sudo rm /System/Library/PreferencePanes/Expose.prefPane/Contents/Resources/Expose.icns

sudo rm /System/Library/PreferencePanes/Security.prefPane/Contents/Resources/FileVault.icns

sudo rm /System/Library/PreferencePanes/Appearance.prefPane/Contents/Resources/General.icns

sudo rm /System/Library/PreferencePanes/Keyboard.prefPane/Contents/Resources/Keyboard.icns

sudo rm /System/Library/PreferencePanes/Localization.prefPane/Contents/Resources/Localization.icns

sudo rm /System/Library/PreferencePanes/PrintAndFax.prefPane/Contents/Resources/PrintFaxPref.icns

sudo rm /System/Library/PreferencePanes/SharingPref.prefPane/Contents/Resources/SharingPref.icns

sudo rm /System/Library/PreferencePanes/Sound.prefPane/Contents/Resources/SoundPref.icns

sudo rm /System/Library/PreferencePanes/Spotlight.prefPane/Contents/Resources/SpotlightPref.icns

sudo rm /System/Library/PreferencePanes/Spotlight.prefPane/Contents/Resources/SpotlightPref.tiff

sudo rm /System/Library/PreferencePanes/StartupDisk.prefPane/Contents/Resources/StartupDiskPref.icns

sudo rm /System/Library/PreferencePanes/UniversalAccessPref.prefPane/Contents/Resources/UniversalAccessPref.icns

sudo mv /System/Library/PreferencePanes/Accounts.prefPane/Contents/Resources/AccountsPref.icns.backup /System/Library/PreferencePanes/Accounts.prefPane/Contents/Resources/AccountsPref.icns

sudo mv /System/Library/PreferencePanes/Bluetooth.prefPane/Contents/Resources/BluetoothPref.icns.backup /System/Library/PreferencePanes/Bluetooth.prefPane/Contents/Resources/BluetoothPref.icns

sudo mv /System/Library/PreferencePanes/DateAndTime.prefPane/Contents/Resources/DateAndTime.icns.backup /System/Library/PreferencePanes/DateAndTime.prefPane/Contents/Resources/DateAndTime.icns

sudo mv /System/Library/PreferencePanes/DesktopScreenEffectsPref.prefPane/Contents/Resources/DesktopScreenEffectsPref.icns.backup /System/Library/PreferencePanes/DesktopScreenEffectsPref.prefPane/Contents/Resources/DesktopScreenEffectsPref.icns

sudo mv /System/Library/PreferencePanes/Displays.prefPane/Contents/Resources/Displays.icns.backup /System/Library/PreferencePanes/Displays.prefPane/Contents/Resources/Displays.icns

sudo mv /System/Library/PreferencePanes/Dock.prefPane/Contents/Resources/Dock.icns.backup /System/Library/PreferencePanes/Dock.prefPane/Contents/Resources/Dock.icns

sudo mv /System/Library/PreferencePanes/EnergySaver.prefPane/Contents/Resources/EnergySaver.icns.backup /System/Library/PreferencePanes/EnergySaver.prefPane/Contents/Resources/EnergySaver.icns

sudo mv /System/Library/PreferencePanes/Expose.prefPane/Contents/Resources/Expose.icns.backup /System/Library/PreferencePanes/Expose.prefPane/Contents/Resources/Expose.icns

sudo mv /System/Library/PreferencePanes/Security.prefPane/Contents/Resources/FileVault.icns.backup /System/Library/PreferencePanes/Security.prefPane/Contents/Resources/FileVault.icns

sudo mv /System/Library/PreferencePanes/Appearance.prefPane/Contents/Resources/General.icns.backup /System/Library/PreferencePanes/Appearance.prefPane/Contents/Resources/General.icns

sudo mv /System/Library/PreferencePanes/Keyboard.prefPane/Contents/Resources/Keyboard.icns.backup /System/Library/PreferencePanes/Keyboard.prefPane/Contents/Resources/Keyboard.icns

sudo mv /System/Library/PreferencePanes/Localization.prefPane/Contents/Resources/Localization.icns.backup /System/Library/PreferencePanes/Localization.prefPane/Contents/Resources/Localization.icns

sudo mv /System/Library/PreferencePanes/PrintAndFax.prefPane/Contents/Resources/PrintFaxPref.icns.backup /System/Library/PreferencePanes/PrintAndFax.prefPane/Contents/Resources/PrintFaxPref.icns

sudo mv /System/Library/PreferencePanes/SharingPref.prefPane/Contents/Resources/SharingPref.icns.backup /System/Library/PreferencePanes/SharingPref.prefPane/Contents/Resources/SharingPref.icns

sudo mv /System/Library/PreferencePanes/Sound.prefPane/Contents/Resources/SoundPref.icns.backup /System/Library/PreferencePanes/Sound.prefPane/Contents/Resources/SoundPref.icns

sudo mv /System/Library/PreferencePanes/Spotlight.prefPane/Contents/Resources/SpotlightPref.icns.backup /System/Library/PreferencePanes/Spotlight.prefPane/Contents/Resources/SpotlightPref.icns

/System/Library/PreferencePanes/Spotlight.prefPane/Contents/Resources/SpotlightPref.tiff.backup /System/Library/PreferencePanes/Spotlight.prefPane/Contents/Resources/SpotlightPref.tiff

sudo mv /System/Library/PreferencePanes/StartupDisk.prefPane/Contents/Resources/StartupDiskPref.icns.backup /System/Library/PreferencePanes/StartupDisk.prefPane/Contents/Resources/StartupDiskPref.icns

sudo mv /System/Library/PreferencePanes/UniversalAccessPref.prefPane/Contents/Resources/UniversalAccessPref.icns.backup /System/Library/PreferencePanes/UniversalAccessPref.prefPane/Contents/Resources/UniversalAccessPref.icns

# Flush System Preferences icon cache
sudo rm ~/Library/Caches/com.apple.preferencepanes.cache

#Set correct ownership permissions
chown -R root:wheel /System/Library/PreferencePanes

# Restore WaitingForLoginWindow
sudo mv /usr/libexec/WaitingForLoginWindow.backup /usr/libexec/WaitingForLoginWindow

# Additions by z970
# Restore Tiger desktop pictures
sudo rm -rf /Library/Desktop\ Pictures
sudo mv -f /Library/Desktop\ Pictures\ Original /Library/Desktop\ Pictures

# Restore Tiger user pictures
sudo rm -rf /Library/User\ Pictures
sudo mv -f /Library/User\ Pictures\ Original /Library/User\ Pictures

# Clear all cache banks
sudo rm -rf ~/Library/Caches/*
sudo rm -rf /Library/Caches/*
sudo rm -rf /System/Library/Caches/*

echo "Aqua resources are restored."
break;;

[nN]* ) exit;;
* ) echo "y/n answer please.";;
esac
done

# Test if font was replaced and restore if true

file="/System/Library/Fonts/LucidaGrande.dfont.backup"
if [ -f "$file" ]
then
	sudo rm /System/Library/Fonts/LucidaGrande.dfont
	
	sudo mv /System/Library/Fonts/LucidaGrande.dfont.backup /System/Library/Fonts/LucidaGrande.dfont
	echo "Font restored."
else
	echo "Font not changed. No restoration necessary."
fi

# Repair disk permissions
sudo diskutil repairPermissions /
clear
echo "Your system is restored. Rebooting..."
sleep 5
sudo reboot