Deleting Fonts at Imaging time

ssavarese
New Contributor III

Im trying to do two things that I know I'll be told I shouldn't be doing. First, I'm trying to clean out /Library/Fonts/ of all contents. Second, I'm trying to delete select fonts from /System/Library/Fonts. I dont have the ability to use Universal Type Server, as our environment is unsupported. Our current Font management tool as well as fontbook are insufficient for the issues we are having.

I have been doing this manually for years, including on current OS, with no issues at all, so I'm not worried about stability.We are careful. Please understand that I know it's not recommended. That said...

When I run this script as part of an imaging configuration, script set to run "after", it fails with the below debug output.

Script "Delete all Sierra Fonts"
rm /Library/Fonts/.
rm "/System/Library/Fonts/Apple Braille Outline 6 Dot.ttf"

Log
>Result of running Delete all Sierra Fonts was: rm: /Library/Fonts/.: No such file or directory
>rm: /System/Library/Fonts/Apple Braille Outline 6 Dot.ttf: Operation not permitted

So two issues. The first line is straight forward. I've tried it with quotes, with one wildcard all sorts of ways. It just fails. Running it locally works fine, of course I have to change the command to be rm /Volumes/Macintosh HD 1/Library/Fonts/.
For the second, I know system fonts are protected by SIP, which is why I'm doing this "after" while its still in target disk mode. Again, running the command locally works fine. I CAN sudo rm "/Volumes/Macintosh HD 1/System/Library/Fonts/Apple Braille Outline 6 Dot.ttf" successfully and do this manually, which is how I'm handling it now. However, I don't see why it shouldn't work in a script at image time.

Any ideas?

EDIT: The site is removing the asterisks from the commands. It should read: rm /Library/Fonts/(asterisk).(asterisk)

4 REPLIES 4

ssavarese
New Contributor III

ok, if I edit the script to include the full path, as if I were doing it local, it works and removed the fonts after imaging. However, this is assuming that the target disk mode mac is always going to be "Macintosh HD 1". I don't think I should have to do this.

rm "/Volumes/Macintosh HD 1/System/Library/Fonts/Apple Braille Outline 6 Dot.ttf"

The full path doesnt help the first command though. it still says no such file or directory. However, if I address the individual fonts one by one, it does work! This suggests that it is the asterisk(s) that is causing the problem?

Josh_Smith
Contributor III

Determining the right drive...I used this as part of a dockfixup After script during imaging (before reboot). All of the drives were wiped and named "Macintosh HD", but if using Target Mode imaging it would add a "1". You could adapt it if there are other possible outcomes for the name.

#Determine Drive location...this script runs before the reboot and needs to affect the unbooted drive that has just been block copied
if [ -e "/Volumes/Macintosh HD 1" ]
    then
            #Target mode imaging will show two drives named Macintosh HD
            DRIVEPATH="/Volumes/Macintosh HD 1"
    else
            #Netboot will show one drive named Macintosh HD
            DRIVEPATH="/Volumes/Macintosh HD"
fi
#example usage with $DRIVEPATH variable
/usr/libexec/PlistBuddy -c "delete:add-app" "$DRIVEPATH/System/Library/CoreServices/Dock.app/Contents/Resources/com.apple.dockfixup.plist"
/usr/libexec/PlistBuddy -c "delete:add-doc" "$DRIVEPATH/System/Library/CoreServices/Dock.app/Contents/Resources/com.apple.dockfixup.plist" ;;

If you go that route I think you'd want to use this:

rm -R "$DRIVEPATH/Library/Fonts/*"
rm "$DRIVEPATH/System/Library/Fonts/Apple Braille Outline 6 Dot.ttf"

cwaldrip
Valued Contributor

I don't think you can delete the fonts from /System/Library/Fonts, it's protected by SIP. If you only need to delete that one font (/System/Library/Fonts/Apple Braille Outline 6 Dot.ttf) you can turn off SIP from a command in Terminal on the Recovery partition (https://developer.apple.com/library/content/documentation/Security/Conceptual/System_Integrity_Protection_Guide/ConfiguringSystemIntegrityProtection/ConfiguringSystemIntegrityProtection.html). But you shouldn't remove all the fonts from that folder since some are required by the OS - otherwise your menus will be empty for example.

ssavarese
New Contributor III

thank you @Josh.Smith That is a nice way to handle this situation. This works if I list every file individually. However, I'm still having the problem with the asterisk in /Library/ I have a ticket open with JAMF to look at it.

@cwaldrip You can delete the system fonts via target disk mode. SIP doesnt prevent it.