#!/bin/bash # Exit if we don't have a ~/.unison folder if [ ! -d ~/.unison ]; then exit 0 fi # Local unison hostname if [ -r ~/.unison/name ]; then source ~/.unison/name fi # Exit if root trys to run us if [ "`id -un`" = "root" ]; then echo "${0}: I refuse to run as root" exit 255 fi # Decide what to sync me="`basename "${0}"`" home=0 apps=0 appsup=0 real=0 gnucash=0 wow=0 plex=0 # If we're called as syncNow if echo "${me}" | grep -i "now" >/dev/null 2>&1; then home=1 apps=1 appsup=1 real=1 gnucash=1 wow=1 plex=1 fi # If we're called as syncQuiet quiet="" if echo "${me}" | grep -i "quiet" >/dev/null 2>&1; then quiet="-contactquietly -silent -batch" home=1 apps=1 appsup=1 real=1 gnucash=1 wow=1 # Avoids slow syncs while the system is in use # unless we are called manually hour="`date '+%H'`" if [ $hour -lt 4 ] || [ $hour -gt 6 ]; then apps=0 appsup=0 fi fi # If we're called as syncHome if echo "${me}" | grep -i "home" >/dev/null 2>&1; then home=1 fi # If we're called as syncApps if echo "${me}" | grep -i "apps" >/dev/null 2>&1; then apps=1 fi # If we're called as syncSup if echo "${me}" | grep -i "sup" >/dev/null 2>&1; then appsup=1 fi # If we're called as syncReal if echo "${me}" | grep -i "real" >/dev/null 2>&1; then real=1 fi # If we're called as syncCash if echo "${me}" | grep -i "cash" >/dev/null 2>&1; then gnucash=1 fi # If we're called as syncWow if echo "${me}" | grep -i "wow" >/dev/null 2>&1; then wow=1 fi # If we're called as syncPlex if echo "${me}" | grep -i "plex" >/dev/null 2>&1; then plex=1 fi # Exit if anyone else is running sync* if [ "`ps auwx | grep sync | grep /bin/bash | wc -l | awk '{print $1}'`" -gt 2 ]; then if [ -n "${quiet}" ]; then exit 0 fi echo -e "${0}: sync* already running\n" 1>&2 echo -e "`ps auwx | grep sync | grep /bin/bash`\n" 1>&2 exit 254 fi # Exit if anyone else is running unison if [ "`ps auwx | grep unison | grep -v grep | wc -l | awk '{print $1}'`" != "0" ]; then if [ -n "${quiet}" ]; then exit 0 fi echo "${0}: Unison already running" 1>&2 exit 254 fi # Sync our home folder if [ $home -gt 0 ] && [ -r ~/.unison/home.prf ]; then if [ -z "${quiet}" ]; then unison home ${quiet} else unison home ${quiet} 2>&1 | \ grep -Ev 'Failed \[Library/Cookies/Cookies\.plist\]:' | \ grep -Ev 'Failed \[Library/Safari/HistoryIndex\.sk\]: ' | \ grep -Ev 'Failed \[Library/Preferences/com\.apple\.mail\.plist\]:' | \ grep -Ev 'Failed \[Library/Preferences/iCalExternalSync\.plist\]: ' | \ grep -Ev 'Failed \[Library/Calendars/.*\.calendar/Events/.*\.ics\]: ' | \ grep -Ev 'Failed \[Library/Calendars/.*\.calendar/Info\.plist\]: ' | \ grep -Ev 'Failed \[Library/Caches/com\.apple\.iCal/Cache\.db\]: ' | \ grep -Ev 'Library/Calendars/.*.calendar/Events/.*\.ics: No such file or directory' | \ grep -Ev 'Failed \[Library/Preferences/com.apple.sidebarlists.plist\]: ' | \ grep -Ev 'Failed \[.*\]: Error in rsync sender:' | \ grep -Ev ': No such file or directory' | \ grep -Ev 'has been modified during synchronization\. Transfer aborted\.' fi fi # Sync Applications if [ $apps -gt 0 ] && [ -r ~/.unison/apps.prf ]; then sudo chown -R "${USER}":admin /Applications/Zach chmod -R ugo+r /Applications/Zach chmod -R ug+w /Applications/Zach chmod -R o-w /Applications/Zach find /Applications/Zach -type d -exec chmod ugo+rx {} \; if [ -r ~/.unison/wow.prf ]; then find /Applications/Zach/Games/World\ of\ Warcraft/Interface -type f -exec chmod ugo-x {} \; fi unison apps ${quiet} fi # Sync Application Support if [ $appsup -gt 0 ] && [ -r ~/.unison/appsup.prf ]; then sudo chown -R "${USER}":admin /Library/Application\ Support chmod -R ugo+r /Library/Application\ Support chmod -R ug+w /Library/Application\ Support chmod -R o-w /Library/Application\ Support find /Library/Application\ Support -type d -exec chmod ugo+rx {} \; # Fix SilverLight DRM (if installed) if [ -d /Library/Application\ Support/Microsoft/PlayReady ]; then find /Library/Application\ Support/Microsoft/PlayReady -type f -mtime +1h -delete find /Library/Application\ Support/Microsoft/PlayReady -mindepth 1 -type d -empty -delete sudo chmod -R -N /Library/Application\ Support/Microsoft/PlayReady sudo chmod -R ugo+rwx /Library/Application\ Support/Microsoft/PlayReady if id -g tv > /dev/null 2>&1; then sudo chown -R tv /Library/Application\ Support/Microsoft/PlayReady fi fi # Fix VMware (if installed) if [ -e /Library/Application\ Support/VMware\ Fusion/vmware-vmx ]; then sudo pkgutil --repair com.vmware.fusion.application >/dev/null 2>&1 fi sudo chown -R "${USER}":admin /Library/Contextual\ Menu\ Items chmod -R ugo+r /Library/Contextual\ Menu\ Items chmod -R ug+w /Library/Contextual\ Menu\ Items chmod -R o-w /Library/Contextual\ Menu\ Items find /Library/Contextual\ Menu\ Items -type d -exec chmod ugo+rx {} \; sudo chown -R "${USER}":admin /Library/Documentation chmod -R ugo+r /Library/Documentation chmod -R ug+w /Library/Documentation chmod -R o-w /Library/Documentation find /Library/Documentation -type d -exec chmod ugo+rx {} \; sudo chown -R "${USER}":admin /Library/Fonts chmod -R ugo+r /Library/Fonts chmod -R ug+w /Library/Fonts chmod -R o-w /Library/Fonts chmod 0644 /Library/Fonts/encodings.dir find /Library/Fonts -type d -exec chmod ugo+rx {} \; sudo chown -R "${USER}":admin /Library/Frameworks chmod -R ugo+r /Library/Frameworks chmod -R ug+w /Library/Frameworks chmod -R o-w /Library/Frameworks find /Library/Frameworks -type d -exec chmod ugo+rx {} \; sudo chown -R "${USER}":admin /Library/Printers chmod -R ugo+r /Library/Printers chmod -R ug+w /Library/Printers chmod -R o-w /Library/Printers find /Library/Printers -type d -exec chmod ugo+rx {} \; # Filters need special perms sudo chown -R root:admin /Library/Printers/*/filter* sudo chown -R root:admin /Library/Printers/*/Filter* sudo chown -R "${USER}":admin /Library/PreferencePanes chmod -R ugo+r /Library/PreferencePanes chmod -R ug+w /Library/PreferencePanes chmod -R o-w /Library/PreferencePanes find /Library/PreferencePanes -type d -exec chmod ugo+rx {} \; sudo chown -R "${USER}":admin /Library/Spotlight chmod -R ugo+r /Library/Spotlight chmod -R ug+w /Library/Spotlight chmod -R o-w /Library/Spotlight find /Library/Spotlight -type d -exec chmod ugo+rx {} \; sudo chown -R "${USER}":admin /Library/QuickLook chmod -R ugo+r /Library/QuickLook chmod -R ug+w /Library/QuickLook chmod -R o-w /Library/QuickLook find /Library/QuickLook -type d -exec chmod ugo+rx {} \; sudo chown -R "${USER}":admin /Library/QuickTime chmod -R ugo+r /Library/QuickTime chmod -R ug+w /Library/QuickTime chmod -R o-w /Library/QuickTime find /Library/QuickTime -type d -exec chmod ugo+rx {} \; sudo chown -R "${USER}":admin /Library/Widgets chmod -R ugo+r /Library/Widgets chmod -R ug+w /Library/Widgets chmod -R o-w /Library/Widgets find /Library/Widgets -type d -exec chmod ugo+rx {} \; unison appsup ${quiet} fi # Sync Aliases if [ $real -gt 0 ] && [ -r ~/.unison/real.prf ]; then sudo chown -R "${USER}":admin /The\ Real\ Thing chmod -R ugo+r /The\ Real\ Thing chmod -R ug+w /The\ Real\ Thing chmod -R o-w /The\ Real\ Thing find /The\ Real\ Thing -type d -exec chmod ugo+rx {} \; unison real ${quiet} fi # Sync WoW if [ $wow -gt 0 ] && [ -r ~/.unison/wow.prf ] && ! ps axc | grep 'World of Warcraft' | grep -v 'grep' >/dev/null 2>&1; then sudo chown -R "${USER}":admin /Applications/Zach/Games/World\ of\ Warcraft chmod -R ugo+r /Applications/Zach/Games/World\ of\ Warcraft chmod -R ug+w /Applications/Zach/Games/World\ of\ Warcraft chmod -R o-w /Applications/Zach/Games/World\ of\ Warcraft find /Applications/Zach/Games/World\ of\ Warcraft -type d -exec chmod 0775 {} \; find /Applications/Zach/Games/World\ of\ Warcraft/WTF/Account -type f -exec chmod 0664 {} \; find /Applications/Zach/Games/World\ of\ Warcraft/Interface -type f -exec chmod 0664 {} \; unison wow ${quiet} fi # Sync Plex if [ $plex -gt 0 ] && [ -r ~/.unison/plex.prf ]; then unison plex ${quiet} fi # Sync Gnucash if [ $gnucash -gt 0 ] && [ -r ~/.unison/gnucash.prf ]; then unison gnucash ${quiet} fi # Copy syncNow to ~/bin/sync.backup if # /usr/local/syncNow and ~/bin exist if [ -r /usr/local/bin/syncNow ]; then if [ -d ~/bin ]; then cp /usr/local/bin/syncNow ~/bin/sync.backup fi fi