Forced Font Management

#! /bin/sh
#####################################################################
# Thom Rosario                                                      #
# 4.29.2008                                                         #
# thom@Acme.net                                                     #
#                                                                   #
# This script manages fonts and font cache files for the user at    #
# 3am.  The name of the script reflects the intent to use this      #
# script for more generalized tasks in the future.                  #
#####################################################################



#============ Variables ============
osxVersion='10.4'
case "$osxVersion" in
   '10.4')
      stockFonts='/Users/Shared/Acme/Fonts/10.4';
      ;;
   '10.5')
      stockFonts='/Users/Shared/Acme/Fonts/10.5';
      ;;
esac
csInDesignFonts='/Applications/Adobe\ InDesign\ CS/Fonts'
cs2InDesignFonts='/Applications/Adobe\ InDesign\ CS2/Fonts'
cs3InDesignFonts='/Applications/Adobe\ InDesign\ CS3/Fonts'
csIllustratorFonts='/Applications/Adobe\ Illustrator\ CS/Fonts'
cs2IllustratorFonts='/Applications/Adobe\ Illustrator\ CS2/Fonts'
cs3IllustratorFonts='/Applications/Adobe\ Illustrator\ CS3/Fonts'
acmeDir='/Users/Shared/Acme'
extraFontDir='/Users/Shared/Acme/Fonts/Extras'
appSup='/Library/Application\ Support'
prefs='/Library/Preferences'
cach='/Library/Caches'
appCach='/Contents/MacOS/Required/Fonts/AdobeFnt*.lst'
fonts='/Library/Fonts'
userFile='/Users/Shared/Acme/Fonts/users.txt'
#------------

#============ Create necessary directories ============
if test -e $acmeDir
   then echo "Acme directory already exists."
else
   /bin/mkdir $acmeDir
   /bin/chmod 777 $acmeDir
fi
if test -e $extraFontDir
      then echo "Acme font directory already exists."
else
   /bin/mkdir $extraFontDir
   /bin/chmod 777 $extraFontDir
fi
/bin/echo "Done creating directories."
#------------

#============ System Font Cache ============
# Clean the system font caches:  requires reboot
/bin/rm /System$cach/com.apple.ATS.System
/bin/rm /System$cach/fcache
/bin/rm /System$cach/com.apple.ATSServer.FODB_System
/bin/rm /System$cach/fontTablesAnnex
/bin/rm -dr $cach/com.apple.ATS
/bin/rm /var/tmp/ATSServer_*
/bin/rm -dr $cach/com.apple.ATS/
/bin/echo "Done deleting system font caches."
#------------

#============ Remove Adobe Fonts ============
# Quit all open Adobe apps before starting
/usr/bin/killall "InDesign CS"
/usr/bin/killall "Illustrator CS"
/usr/bin/killall "Photoshop CS"
/usr/bin/killall "Adobe InDesign CS2"
/usr/bin/killall "Adobe Illustrator CS2"
/usr/bin/killall "Adobe Photoshop CS2"
/usr/bin/killall "Adobe InDesign CS3"
/usr/bin/killall "Adobe Illustrator CS3"
/usr/bin/killall "Adobe Photoshop CS3"

# Remove system level Adobe font caches and move fonts
if test -e "$csInDesignFonts":
   then
      /bin/rm "$csinDesignFonts"/AdobeFnt*.lst
      /bin/mv -f "$csInDesignFonts"/*  $extraFontDir/
      /bin/rm "$appSup"/Adobe/PDFL/6.0/Fonts/AdobeFnt*.lst
      /bin/rm "$appSup"/Adobe/PDFL/6.0/CMaps/AdobeFnt*.lst
      /bin/rm /Applications/"Adobe InDesign CS"/"Adobe InDesign CS.app"/$appCach
else
   echo "Skippping InDesign CS folder."
fi
if test -e "$cs2InDesignFonts"
   then 
      /bin/rm "$cs2inDesignFonts"/AdobeFnt*.lst
      /bin/mv -f "$cs2InDesignFonts"/*  $extraFontDir/
      /bin/rm "$appSup"/Adobe/PDFL/7.0/Fonts/AdobeFnt*.lst
      /bin/rm "$appSup"/Adobe/PDFL/7.0/CMaps/AdobeFnt*.lst
      /bin/rm /Applications/"Adobe InDesign CS2"/"Adobe InDesign CS2.app"/$appCach
else
   echo "Skippping InDesign CS2 folder."
fi
if test -e "$cs3InDesignFonts"
   then 
      /bin/rm "$cs3inDesignFonts"/AdobeFnt*.lst
      /bin/mv -f "$cs3InDesignFonts"/*  $extraFontDir/
      /bin/rm "$appSup"/Adobe/PDFL/8.0/Fonts/AdobeFnt*.lst
      /bin/rm "$appSup"/Adobe/PDFL/8.0/CMaps/AdobeFnt*.lst
      /bin/rm /Applications/"Adobe InDesign CS3"/"Adobe InDesign CS3.app"/$appCach
else
   echo "Skippping InDesign CS3 folder."
fi
if test -e "$csIllustratorFonts"
   then 
      /bin/rm "$csIllustratorFonts"/AdobeFnt*.lst
      /bin/mv -f "$csIllustratorFonts"/*  $extraFontDir/
else
   echo "Skippping Illustrator CS folder."
fi
if test -e "$cs2IllustratorFonts"
   then 
      /bin/rm "$cs2IllustratorFonts"/AdobeFnt*.lst
      /bin/mv -f "$cs2IllustratorFonts"/*  $extraFontDir/
else
   echo "Skippping Illustrator CS2 folder."
fi
if test -e "$cs3IllustratorFonts"
   then 
      /bin/rm "$cs3IllustratorFonts"/AdobeFnt*.lst
      /bin/mv -f "$cs3IllustratorFonts"/*  $extraFontDir/
else
   echo "Skippping Illustrator CS3 folder."
fi

/bin/rm "$appSup"/Adobe/Fonts/Reqrd/CMaps/AdobeFnt*.lst


#------------

#============ Manage User Fonts ============

#== Create a file listing all of the system's users ==
if test -e $userFile
   then 
      /bin/rm $userFile
else
   echo "No pre-existing userfile -- creating it now."
fi
/bin/ls -l /Users/ | /usr/bin/awk '/d/ {print $9}' >> $userFile

cat $userFile | while read uName; do

   #== Change Permissions ==
   /bin/chmod 757 /Users/$uName
   /bin/chmod 707 /Users/$uName/Library
   /bin/chmod 707 /Users/$uName$prefs
   /bin/chmod 707 /Users/$uName$cach
   /bin/chmod 707 /Users/$uName$cach/Adobe
   /bin/chmod 707 /Users/$uName$cach/Adobe/Fonts
   /bin/chmod 757 /Users/$uName$cach/Adobe/TypeSpt
   /bin/chmod 757 /Users/$uName"$appSup"
   /bin/chmod 757 /Users/$uName"$appSup"/Adobe
   /bin/chmod 757 /Users/$uName"$appSup"/Adobe/Fonts
   /bin/chmod 757 /Users/$uName"$appSup"/Adobe/TypeSpt
   #---------------------

   #== Remove problematic user font caches ==
   /bin/rm /Users/$uName$prefs/com.apple.ATS.plist
   /bin/rm /Users/$uName"$appSup"/Adobe/Fonts/AdobeFnt*.lst
   /bin/rm /Users/$uName"$appSup"/Adobe/TypeSpt/AdobeFnt*.lst
   /bin/rm /Users/$uName$cach/Adobe/Fonts/AdobeFnt*.lst
   /bin/rm /Users/$uName$cach/Adobe/TypeSpt/AdobeFnt*.lst
   #-----------------------------------------

   #== Restore original permissions ==
   /bin/chmod 755 /Users/$uName"$appSup"/Adobe/TypeSpt
   /bin/chmod 755 /Users/$uName"$appSup"/Adobe/Fonts
   /bin/chmod 755 /Users/$uName"$appSup"/Adobe
   /bin/chmod 755 /Users/$uName"$appSup"
   /bin/chmod 755 /Users/$uName$cach/Adobe/TypeSpt
   /bin/chmod 700 /Users/$uName$cach/Adobe/Fonts
   /bin/chmod 700 /Users/$uName$cach/Adobe
   /bin/chmod 700 /Users/$uName$cach
   /bin/chmod 700 /Users/$uName$prefs
   /bin/chmod 700 /Users/$uName/Library
   /bin/chmod 755 /Users/$uName
   #----------------------------------
done
#-------------------------------------------

#============ Remove Unnecessary System Fonts ============
/bin/rm -dr /System$fonts/*.*
/bin/cp $stockFonts/* /System$fonts/
/bin/rm $fonts/*
/bin/rm -dr "$appSup"/Adobe/Reqrd/Base
#------------

reboot


Leave a Reply

Your email address will not be published. Required fields are marked *