forked from MoeClub/Note
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MacInitial.sh
227 lines (197 loc) · 6.62 KB
/
MacInitial.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/bash
if [ -f "/usr/bin/sudo" ]; then
[ "$(sudo whoami)" == "root" ] || return
# System setting
echo -e "\n# System setting ..."
sudo nvram StartupMute=%01
sudo nvram BootAudio=%00
sudo nvram SystemAudioVolume=%80
sudo defaults write com.apple.systempreferences AttentionPrefBundleIDs 0
sudo defaults write com.apple.loginwindow TALLogoutSavesState -bool FALSE
sudo defaults write com.apple.loginwindow SHOWOTHERUSERS_MANAGED -bool FALSE
fi
# Check SIP
[ -f "/usr/bin/sudo" ] && [ "$(csrutil status |cut -d':' -f2 |grep -io 'enable\|disable')" != "disable" ] && echo "Please disable SIP. (command + r; csrutil disable)" && exit 1
# Mount
if [ -f "/usr/bin/sudo" ]; then
sudo mount -uw /
else
mount -uw /
fi
[ $? -ne 0 ] && echo "Mount root fail." && exit 1
DISABLE(){
[ -n "$1" ] && [ -n "$2" ] && [ -d "$1" ] || return
for item in `find "$1" -type f -maxdepth 1 -name "${2}*"`
do
[ -n "$item" ] || continue
echo "$item" |grep -q "\.plist$"
[ $? -eq 0 ] || continue
echo "Disable: ${item}"
if [ -f "/usr/bin/sudo" ]; then
sudo mv "${item}" "${item}.bak"
else
mv "${item}" "${item}.bak"
fi
done
}
ENABLEALL(){
[ -n "$1" ] && [ -d "$1" ] || return
for item in `find "$1" -type f -maxdepth 1 -name "*.bak"`
do
[ -n "$item" ] || continue
echo "$item" |grep -q "\.bak$"
[ $? -eq 0 ] || continue
newItem=`echo "${item}" |sed "s/.\bak$//"`
echo "Enable: ${newItem}"
if [ -f "/usr/bin/sudo" ]; then
sudo mv "${item}" "${newItem}"
else
mv "${item}" "${newItem}"
fi
done
}
RENAMEBIN(){
[ -f "/usr/bin/sudo" ] && [ -n "$1" ] || return
if [ ! -f "${1}.bak" ]; then
echo "${1} --> ${1}.bak"
sudo mv "${1}" "${1}.bak"
fi
if [ -f "${1}.bak" ]; then
echo "/usr/bin/true --> ${1}"
sudo ln -sf "/usr/bin/true" "$1"
fi
}
RMAPP(){
[ -n "$1" ] && [ -n "$2" ] && [ -d "$1" ] || return
for item in `find "$1" -type d -maxdepth 1 -name "${2}"`
do
[ -n "$item" ] || continue
echo "RM APP '$2'"
if [ -f "/usr/bin/sudo" ]; then
sudo rm -rf "${item}"
else
rm -rf "${item}"
fi
done
}
DEAMONS=()
# Disable Analytic
DEAMONS+=("com.apple.analyticsd.plist")
# Disable AirPlay
#DEAMONS+=("com.apple.AirPlayXPCHelper.plist")
# Disable Updates
DEAMONS+=("com.apple.softwareupdate.plist")
# Disable DVD
DEAMONS+=("com.apple.dvdplayback.setregion.plist")
# Disable Feedback
DEAMONS+=("com.apple.SubmitDiagInfo.plist" \
"com.apple.CrashReporterSupportHelper.plist" \
"com.apple.ReportCrash.Root.plist"\
"com.apple.GameController.gamecontrollerd.plist")
# Disable FTP
DEAMONS+=("com.apple.ftp-proxy.plist")
# Disable APSD
#DEAMONS+=("com.apple.apsd")
# Disable spindump
DEAMONS+=("com.apple.spindump.plist")
# Disable systemstats
DEAMONS+=("com.apple.systemstats.daily.plist" \
"com.apple.systemstats.analysis.plist" \
"com.apple.systemstats.microstackshot_periodic.plist")
AGENTS=()
# Disable iCloud
AGENTS+=("com.apple.cloud" \
"com.apple.icloud.fmfd.plist" \
"com.apple.iCloudUserNotifications.plist")
# Disable AddressBook
AGENTS+=("com.apple.AddressBook")
# Disable Safari
AGENTS+=("com.apple.safaridavclient.plist" \
"com.apple.SafariNotificationAgent.plist" \
"com.apple.SafariCloudHistoryPushAgent.plist")
# Disable Facetime
AGENTS+=("com.apple.imagent.plist" \
"com.apple.IMLoggingAgent.plist")
# Quicklook
AGENTS+=("com.apple.quicklook.ui.helper.plist" \
"com.apple.quicklook.ThumbnailsAgent.plist" \
"com.apple.quicklook.plist")
# Disable Game Center / Apple TV / Homekit
AGENTS+=("com.apple.gamed.plist" \
"com.apple.videosubscriptionsd.plist" \
"com.apple.homed.plist"
"com.apple.AMPArtworkAgent.plist")
# Disable Siri
AGENTS+=("com.apple.siriknowledged.plist" \
"com.apple.assistant_service.plist" \
"com.apple.assistantd.plist" \
"com.apple.Siri.agent.plist")
# Disable Airplay
#AGENTS+=("com.apple.AirPlayUIAgent.plist")
# Disable Sidecar
#AGENTS+=("com.apple.sidecar-hid-relay.plist" \
# "com.apple.sidecar-relay.plist")
# Disable Ad
AGENTS+=("com.apple.ap.adprivacyd.plist" \
"com.apple.ap.adservicesd.plist")
# Disable Debug
AGENTS+=("com.apple.spindump_agent.plist" \
"com.apple.ReportCrash.plist" \
"com.apple.ReportGPURestart.plist" \
"com.apple.ReportPanic.plist")
# Disable Others
AGENTS+=("com.apple.AirPortBaseStationAgent.plist" \
"com.apple.photoanalysisd.plist" \
"com.apple.familycircled.plist" \
"com.apple.familycontrols.useragent.plist" \
"com.apple.familynotificationd.plist" \
"com.apple.parentalcontrols.check.plist" \
"com.apple.podcasts.PodcastContentService.plist" \
"com.apple.macos.studentd.plist" \
"com.apple.suggestd.plist" \
"com.apple.facebook.xpc.plist" \
"com.apple.linkedin.xpc.plist" \
"com.apple.twitter.xpc.plist" \
"com.apple.soagent.plist" \
"com.apple.SocialPushAgent.plist" \
"com.apple.Maps.pushdaemon.plist" \
"com.apple.DictationIM.plist" \
"com.apple.java.updateSharing.plist" \
"com.apple.softwareupdate_notify_agent.plist")
APPS=()
APPS+=("TV.app" \
"News.app" \
"Home.app" \
"Books.app" \
"Chess.app" \
"Podcasts.app" \
"Stocks.app")
# Volume
cd "/Volumes/$(ls -1 /Volumes|head -n1)"
# Enable /System/Library/LaunchDaemons
ENABLEALL "./System/Library/LaunchDaemons"
# Enable /System/Library/LaunchAgents
ENABLEALL "./System/Library/LaunchAgents"
# Enable and Exit
# exit 0
# Disable /System/Library/LaunchDaemons
echo -e "\n# Disable Daemons ..."
for deamon in "${DEAMONS[@]}"; do DISABLE "./System/Library/LaunchDaemons" "$deamon"; done
# Disable /System/Library/LaunchAgents
echo -e "\n# Disable Agents ..."
for agent in "${AGENTS[@]}"; do DISABLE "./System/Library/LaunchAgents" "$agent"; done
# Remove System APP
echo -e "\n# Remove System APP ..."
for app in "${APPS[@]}"; do RMAPP "./System/Applications" "$app"; done
# Replace spindump
echo -e "\n# Replace spindump ..."
RENAMEBIN "/usr/sbin/spindump"
# Disable Update Notice
echo -e "\n# Disable Update Notice ..."
if [ -f "/usr/bin/sudo" ]; then
sudo find "./System/Library/PrivateFrameworks/SoftwareUpdate.framework" -type f -name "SoftwareUpdateNotificationManager" |xargs -t -I "{}" sudo chmod 644 "{}"
else
find "./System/Library/PrivateFrameworks/SoftwareUpdate.framework" -type f -name "SoftwareUpdateNotificationManager" |xargs -t -I "{}" chmod 644 "{}"
fi
# Finish
echo -e "\n# Finish! \n"