forked from othercat/CJKFontScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore.sh
113 lines (95 loc) · 4.12 KB
/
restore.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
# Source Hans TC Restore Script
# Restore those backups made by installer scripts.
#
# @(#) Replace System Fallbacks Font to SourceHans TC in the project plist.
# Original Script for SHS was composed by Richard Li, Modified by Shiki Suen
# Enjoy!
# Tested by Shiki Suen on Feb, 01, 2015, MST.
# Reference: http://shikisuen.github.io/OSXCJKFontPlists/CTPresetFallbackAnalysis.html
# Latest Scripts could be found here: https://github.com/othercat/CJKFontScript
#============================================
# Public Instant Variables
#============================================
fdrGarage="/tmp/FontInstallationWorkingDir"
BackupPath="${HOME}/.FactorialCJKFontSettingsBackup"
SystemFontsPath="/System/Library/Fonts"
LibraryFontsPath="/Library/Fonts"
SysPlistsDir="/System/Library/Frameworks/CoreText.framework/Versions/A/Resources/"
Plutil="plutil"
PlistFileRegx="${fdrGarage}/plistFileRegx"
plisttoolhash="f4f6b442d93cda35a1aec25121318482"
#============================================
# Privileges Requirements
#============================================
if [ $(id -u) != 0 ]; then
echo "[SUDO command needed to execute this BASH script, ABORT MISSION.]"
exit
fi
#============================================
# Checking Backup Folder's Existence
#============================================
if [ ! -d "${BackupPath}" ]
then
echo "[NO Backup Folder EXISTS, ABORT MISSION.]"
exit
fi
#============================================
# Restore Backup Plists, Exit if any File Missing
#============================================
if [ -f "${BackupPath}/CTPresetFallbacks.plist.bak" ];
then
cp "${BackupPath}/CTPresetFallbacks.plist.bak" "${SysPlistsDir}/CTPresetFallbacks.plist"
chown root:wheel "${SysPlistsDir}/CTPresetFallbacks.plist"
chmod 644 "${SysPlistsDir}/CTPresetFallbacks.plist"
else
echo "[CTPresetFallbacks Backup is MISSING, ABORT MISSION.]"
exit
fi
if [ -f "${BackupPath}/DefaultFontFallbacks.plist.bak" ];
then
cp "${BackupPath}/DefaultFontFallbacks.plist.bak" "${SysPlistsDir}/DefaultFontFallbacks.plist"
chown root:wheel "${SysPlistsDir}/DefaultFontFallbacks.plist"
chmod 644 "${SysPlistsDir}/DefaultFontFallbacks.plist"
else
echo "[DefaultFontFallbacks.plist.bak is MISSING, ABORT MISSION.]"
exit
fi
#============================================
# Restore SinoType Gothic Fonts
#============================================
cp "${BackupPath}/STHeiti Light.ttc.bak" "${SystemFontsPath}/STHeiti Light.ttc"
chown root:wheel "${SystemFontsPath}/STHeiti Light.ttc"
chmod 644 "${SystemFontsPath}/STHeiti Light.ttc"
cp "${BackupPath}/STHeiti Medium.ttc.bak" "${SystemFontsPath}/STHeiti Medium.ttc"
chown root:wheel "${SystemFontsPath}/STHeiti Medium.ttc"
chmod 644 "${SystemFontsPath}/STHeiti Medium.ttc"
cp "${BackupPath}/STHeiti Thin.ttc.bak" "${SystemFontsPath}/STHeiti Thin.ttc"
chown root:wheel "${SystemFontsPath}/STHeiti Thin.ttc"
chmod 644 "${SystemFontsPath}/STHeiti Thin.ttc"
cp "${BackupPath}/STHeiti UltraLight.ttc.bak" "${SystemFontsPath}/STHeiti UltraLight.ttc"
chown root:wheel "${SystemFontsPath}/STHeiti UltraLight.ttc"
chmod 644 "${SystemFontsPath}/STHeiti UltraLight.ttc"
cp "${BackupPath}/KabunGothic-Light.ttf.bak" "/Library/Fonts/华文细黑.ttf"
cp "${BackupPath}/KabunGothic-Medium.ttf.bak" "/Library/Fonts/华文黑体.ttf"
#===========================================
# Killing Finder
#===========================================
echo "===================================="
echo "We have to kill Finder, clean the font cache and reboot your Mac."
echo "Please restart all applications running after this reboot."
echo "------------------------------------"
echo -e "Press ENTER(RETURN) key to continue:\c "
read
killall Finder
#=============================================================
# Remove SHSDeskInterface
#=============================================================
rm -f "/System/Library/Fonts/SHSDeskInterface.ttc"
rm -f "/Library/Fonts/SHSDeskInterface.ttc"
rm -f "/Library/SourceHanSansUI.ttc"
#=============================================================
# Clean Font Cache and Force Reboot
#=============================================================
atsutil databases -remove
reboot