#/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 the theme installs."
echo "ONCE THE INSTALLATION STARTS, DO NOT STOP THE PROCESS!"
echo "YOUR SYSTEM WILL BE HOSED IF YOU DO!"
echo "Your system will reboot automatically when the installation is finished."
echo " "

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

	case $answer in
		[yY]* )
clear 
cd "$(dirname "$0")"
echo "Backing up original resources and installing files..."
# Backup and Install Extras.rsrc
sudo mv /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Resources/Extras.rsrc /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Resources/Extras.rsrc.backup

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

# Backup and Install Finder.rsrc
sudo mv /System/Library/CoreServices/Finder.app/Contents/Resources/Finder.rsrc /System/Library/CoreServices/Finder.app/Contents/Resources/Finder.rsrc.backup

sudo cp ./Finder.rsrc /System/Library/CoreServices/Finder.app/Contents/Resources/Finder.rsrc

# Backup and install Spotlight icons
sudo mv /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Normal-1.tiff /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Normal-1.tiff.backup

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

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

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

sudo cp ./searchbundle/MDSearchWidget_Normal-1.tiff /System/Library/CoreServices/Search.bundle/Contents/Resources/MDSearchWidget_Normal-1.tiff

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

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

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

# Backup and Install AboutThisMac nib and strings

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

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

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

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

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

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

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

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

# Backup and Install SecurityAgent tifs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Backup and Install loginwindow tif

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

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

# Backup and Install System Preferences Back/Forward Arrows
sudo mv /Applications/System\ Preferences.app/Contents/Resources/BackAdorn.png /Applications/System\ Preferences.app/Contents/Resources/BackAdorn.png.backup

sudo cp ./sysprefarrows/BackAdorn.png /Applications/System\ Preferences.app/Contents/Resources/BackAdorn.png

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

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

# Backup and Install PrefPane icons

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

sudo cp ./preficons/DateAndTime.icns /System/Library/PreferencePanes/DateAndTime.prefPane/Contents/Resources/DateAndTime.icns

sudo cp ./preficons/DateAndTime.icns /System/Library/PreferencePanes/DateAndTime.prefPane/Contents/Resources/DateAndTime.icns

sudo cp ./preficons/DesktopScreenEffectsPref.icns /System/Library/PreferencePanes/DesktopScreenEffectsPref.prefPane/Contents/Resources/DesktopScreenEffectsPref.icns

sudo cp ./preficons/Displays.icns /System/Library/PreferencePanes/Displays.prefPane/Contents/Resources/Displays.icns

sudo cp ./preficons/Dock.icns /System/Library/PreferencePanes/Dock.prefPane/Contents/Resources/Dock.icns

sudo cp ./preficons/EnergySaver.icns /System/Library/PreferencePanes/EnergySaver.prefPane/Contents/Resources/EnergySaver.icns

sudo cp ./preficons/Expose.icns /System/Library/PreferencePanes/Expose.prefPane/Contents/Resources/Expose.icns

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

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

sudo cp ./preficons/Keyboard.icns /System/Library/PreferencePanes/Keyboard.prefPane/Contents/Resources/Keyboard.icns

sudo cp ./preficons/Localization.icns /System/Library/PreferencePanes/Localization.prefPane/Contents/Resources/Localization.icns

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

sudo cp ./preficons/SharingPref.icns /System/Library/PreferencePanes/SharingPref.prefPane/Contents/Resources/SharingPref.icns

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

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

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

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

sudo cp ./preficons/UniversalAccessPref.icns /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
sudo chown -R root:wheel /System/Library/PreferencePanes

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

# Additions by z970
# Install Sierra desktop pictures
sudo mv -f /Library/Desktop\ Pictures /Library/Desktop\ Pictures\ Original
sudo cp -rf Desktop\ Pictures /Library
sudo chown -R root:admin /Library/Desktop\ Pictures

# Install Sierra user pictures
sudo mv -f /Library/User\ Pictures /Library/User\ Pictures\ Original
sudo cp -rf User\ Pictures /Library
sudo chown -R root:admin /Library/User\ Pictures

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

echo "Main files are finished."
break;;

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

while true
do
	read -p "Do you wish to install the San Francisco font? This replaces the LucidaGrande font and you lose usage of it (y/n)" answer

	case $answer in
		[yY]* )
clear
echo "Backing up original font and installing replacement..."
# Change font
sudo mv /System/Library/Fonts/LucidaGrande.dfont /System/Library/Fonts/LucidaGrande.dfont.backup

sudo cp ./font/LucidaGrande.dfont /System/Library/Fonts/LucidaGrande.dfont
echo "Font installed."
break;;



		[nN]* ) 
sudo diskutil repairPermissions /
clear
echo "Installation is finished. Rebooting..."
sleep 5
sudo reboot
exit;;
* ) echo "y/n answer please.";;
esac
done

# Repair disk permissions
sudo diskutil repairPermissions /
clear
echo "Installation is finished. Rebooting..."
sleep 5
sudo reboot