Last active
August 31, 2017 11:46
-
-
Save n8felton/e45e5eb585b0a9df4d93 to your computer and use it in GitHub Desktop.
OS X Cleanup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://github.com/n8felton/DeployStudio/blob/master/DeployStudio%20Admin.app/Contents/Frameworks/DSCore.framework/Versions/A/Resources/Tools/osxcleanup.sh | |
# https://managingosx.wordpress.com/2009/01/23/image-cleanup-script/ | |
# https://wikis.uit.tufts.edu/confluence/display/exchange2010/Remove+account+in+Single+User+mode | |
# Copy this script to /private/var/root/.profile | |
echo Check and mount disk | |
/sbin/fsck -fy | |
/sbin/mount -uw / | |
echo Remove volume info db | |
/bin/rm -fv /private/var/db/volinfo.database 2>&1 | |
echo Remove system keychain. Regenerated with systemkeychain | |
/bin/rm -fv /Library/Keychains/System.keychain | |
echo Clean up global caches and temp data | |
/bin/rm -rfv /Library/Caches/* | |
/bin/rm -rfv /System/Library/Caches/* | |
/bin/rm -rfv /Users/Shared/* | |
/bin/rm -fv /private/etc/ssh_host* | |
echo Network interfaces | |
echo This is regenerated on reboot and can differ on different hardware | |
/bin/rm -fv /private/var/db/NetworkInterfaces.xml 2>&1 | |
echo Kerberos cleanup | |
/bin/rm -fv /etc/krb5.keytab 2>&1 | |
/bin/rm -rfv /var/db/krb5kdc 2>&1 | |
/bin/rm -fv /var/db/dslocal/nodes/Default/config/KerberosKDC.plist 2>&1 | |
echo Clean up other random files and directories | |
/bin/rm -rfv /Library/Preferences/* 2>&1 | |
/bin/rm -fv /System/Library/Extensions.kextcache 2>&1 | |
/bin/rm -fv /System/Library/Extensions.mkext 2>&1 | |
/bin/rm -fv /private/var/db/BootCache.playlist 2>&1 | |
/bin/rm -fv /var/db/dhcpclient/leases/* 2>&1 | |
/bin/rm -fv /var/db/dyld/dyld* 2>&1 | |
/bin/rm -fv /var/pcast/server/krb_cc 2>&1 | |
/bin/rm -fv /var/vm/sleepimage 2>&1 | |
echo Remove the local user | |
/bin/rm -r /Users/itsadmin | |
/bin/rm -fv /var/db/dslocal/nodes/Default/users/itsadmin.plist | |
echo Generate new system keychain | |
/usr/sbin/systemkeychain -k /Library/Keychains/System.keychain -C -f | |
echo Seal the system | |
/bin/rm -fv /var/db/.AppleSetupDone | |
echo Cleanup roots home dir | |
rm -rfv /private/var/root/Desktop/* | |
rm -rfv /private/var/root/Documents/* | |
rm -rfv /private/var/root/Downloads/* | |
rm -rfv /private/var/root/Library/Caches/* | |
rm -rfv /private/var/root/Library/Recent\ Servers/* | |
rm -rfv /private/var/root/Library/Logs/* | |
rm -rfv /private/var/root/Library/Keychains/* | |
rm -rfv /private/var/root/Library/Preferences/ByHost/* | |
rm -fv /private/var/root/Library/Preferences/com.apple.recentitems.plist | |
echo Remove this script | |
srm -fv /private/var/root/.profile | |
srm -fv /private/var/root/.sh_history |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment