MacInitial.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #!/bin/bash
  2. if [ -f "/usr/bin/sudo" ]; then
  3. [ "$(sudo whoami)" == "root" ] || return
  4. # System setting
  5. echo -e "\n# System setting ..."
  6. sudo nvram StartupMute=%01
  7. sudo nvram BootAudio=%00
  8. sudo nvram SystemAudioVolume=%80
  9. sudo defaults write com.apple.systempreferences AttentionPrefBundleIDs 0
  10. sudo defaults write com.apple.loginwindow TALLogoutSavesState -bool FALSE
  11. sudo defaults write com.apple.loginwindow SHOWOTHERUSERS_MANAGED -bool FALSE
  12. fi
  13. # Check SIP
  14. [ -f "/usr/bin/sudo" ] && [ "$(csrutil status |cut -d':' -f2 |grep -io 'enable\|disable')" != "disable" ] && echo "Please disable SIP. (command + r; csrutil disable)" && exit 1
  15. # Mount
  16. if [ -f "/usr/bin/sudo" ]; then
  17. sudo mount -uw /
  18. else
  19. mount -uw /
  20. fi
  21. [ $? -ne 0 ] && echo "Mount root fail." && exit 1
  22. DISABLE(){
  23. [ -n "$1" ] && [ -n "$2" ] && [ -d "$1" ] || return
  24. for item in `find "$1" -type f -maxdepth 1 -name "${2}*"`
  25. do
  26. [ -n "$item" ] || continue
  27. echo "$item" |grep -q "\.plist$"
  28. [ $? -eq 0 ] || continue
  29. echo "Disable: ${item}"
  30. if [ -f "/usr/bin/sudo" ]; then
  31. sudo mv "${item}" "${item}.bak"
  32. else
  33. mv "${item}" "${item}.bak"
  34. fi
  35. done
  36. }
  37. ENABLEALL(){
  38. [ -n "$1" ] && [ -d "$1" ] || return
  39. for item in `find "$1" -type f -maxdepth 1 -name "*.bak"`
  40. do
  41. [ -n "$item" ] || continue
  42. echo "$item" |grep -q "\.bak$"
  43. [ $? -eq 0 ] || continue
  44. newItem=`echo "${item}" |sed "s/.\bak$//"`
  45. echo "Enable: ${newItem}"
  46. if [ -f "/usr/bin/sudo" ]; then
  47. sudo mv "${item}" "${newItem}"
  48. else
  49. mv "${item}" "${newItem}"
  50. fi
  51. done
  52. }
  53. RENAMEBIN(){
  54. [ -f "/usr/bin/sudo" ] && [ -n "$1" ] || return
  55. if [ ! -f "${1}.bak" ]; then
  56. echo "${1} --> ${1}.bak"
  57. sudo mv "${1}" "${1}.bak"
  58. fi
  59. if [ -f "${1}.bak" ]; then
  60. echo "/usr/bin/true --> ${1}"
  61. sudo ln -sf "/usr/bin/true" "$1"
  62. fi
  63. }
  64. RMAPP(){
  65. [ -n "$1" ] && [ -n "$2" ] && [ -d "$1" ] || return
  66. for item in `find "$1" -type d -maxdepth 1 -name "${2}"`
  67. do
  68. [ -n "$item" ] || continue
  69. echo "RM APP '$2'"
  70. if [ -f "/usr/bin/sudo" ]; then
  71. sudo rm -rf "${item}"
  72. else
  73. rm -rf "${item}"
  74. fi
  75. done
  76. }
  77. DEAMONS=()
  78. # Disable Analytic
  79. DEAMONS+=("com.apple.analyticsd.plist")
  80. # Disable AirPlay
  81. #DEAMONS+=("com.apple.AirPlayXPCHelper.plist")
  82. # Disable Updates
  83. DEAMONS+=("com.apple.softwareupdate.plist")
  84. # Disable DVD
  85. DEAMONS+=("com.apple.dvdplayback.setregion.plist")
  86. # Disable Feedback
  87. DEAMONS+=("com.apple.SubmitDiagInfo.plist" \
  88. "com.apple.CrashReporterSupportHelper.plist" \
  89. "com.apple.ReportCrash.Root.plist"\
  90. "com.apple.GameController.gamecontrollerd.plist")
  91. # Disable FTP
  92. DEAMONS+=("com.apple.ftp-proxy.plist")
  93. # Disable APSD
  94. #DEAMONS+=("com.apple.apsd")
  95. # Disable spindump
  96. DEAMONS+=("com.apple.spindump.plist")
  97. # Disable systemstats
  98. DEAMONS+=("com.apple.systemstats.daily.plist" \
  99. "com.apple.systemstats.analysis.plist" \
  100. "com.apple.systemstats.microstackshot_periodic.plist")
  101. AGENTS=()
  102. # Disable iCloud
  103. AGENTS+=("com.apple.cloud" \
  104. "com.apple.icloud.fmfd.plist" \
  105. "com.apple.iCloudUserNotifications.plist")
  106. # Disable AddressBook
  107. AGENTS+=("com.apple.AddressBook")
  108. # Disable Safari
  109. AGENTS+=("com.apple.safaridavclient.plist" \
  110. "com.apple.SafariNotificationAgent.plist" \
  111. "com.apple.SafariCloudHistoryPushAgent.plist")
  112. # Disable Facetime
  113. AGENTS+=("com.apple.imagent.plist" \
  114. "com.apple.IMLoggingAgent.plist")
  115. # Quicklook
  116. AGENTS+=("com.apple.quicklook.ui.helper.plist" \
  117. "com.apple.quicklook.ThumbnailsAgent.plist" \
  118. "com.apple.quicklook.plist")
  119. # Disable Game Center / Apple TV / Homekit
  120. AGENTS+=("com.apple.gamed.plist" \
  121. "com.apple.videosubscriptionsd.plist" \
  122. "com.apple.homed.plist"
  123. "com.apple.AMPArtworkAgent.plist")
  124. # Disable Siri
  125. AGENTS+=("com.apple.siriknowledged.plist" \
  126. "com.apple.assistant_service.plist" \
  127. "com.apple.assistantd.plist" \
  128. "com.apple.Siri.agent.plist")
  129. # Disable Airplay
  130. #AGENTS+=("com.apple.AirPlayUIAgent.plist")
  131. # Disable Sidecar
  132. #AGENTS+=("com.apple.sidecar-hid-relay.plist" \
  133. # "com.apple.sidecar-relay.plist")
  134. # Disable Ad
  135. AGENTS+=("com.apple.ap.adprivacyd.plist" \
  136. "com.apple.ap.adservicesd.plist")
  137. # Disable Debug
  138. AGENTS+=("com.apple.spindump_agent.plist" \
  139. "com.apple.ReportCrash.plist" \
  140. "com.apple.ReportGPURestart.plist" \
  141. "com.apple.ReportPanic.plist")
  142. # Disable Others
  143. AGENTS+=("com.apple.AirPortBaseStationAgent.plist" \
  144. "com.apple.photoanalysisd.plist" \
  145. "com.apple.familycircled.plist" \
  146. "com.apple.familycontrols.useragent.plist" \
  147. "com.apple.familynotificationd.plist" \
  148. "com.apple.parentalcontrols.check.plist" \
  149. "com.apple.podcasts.PodcastContentService.plist" \
  150. "com.apple.macos.studentd.plist" \
  151. "com.apple.suggestd.plist" \
  152. "com.apple.facebook.xpc.plist" \
  153. "com.apple.linkedin.xpc.plist" \
  154. "com.apple.twitter.xpc.plist" \
  155. "com.apple.soagent.plist" \
  156. "com.apple.SocialPushAgent.plist" \
  157. "com.apple.Maps.pushdaemon.plist" \
  158. "com.apple.DictationIM.plist" \
  159. "com.apple.java.updateSharing.plist" \
  160. "com.apple.softwareupdate_notify_agent.plist")
  161. APPS=()
  162. APPS+=("TV.app" \
  163. "News.app" \
  164. "Home.app" \
  165. "Books.app" \
  166. "Chess.app" \
  167. "Podcasts.app" \
  168. "Stocks.app")
  169. # Volume
  170. cd "/Volumes/$(ls -1 /Volumes|head -n1)"
  171. # Enable /System/Library/LaunchDaemons
  172. ENABLEALL "./System/Library/LaunchDaemons"
  173. # Enable /System/Library/LaunchAgents
  174. ENABLEALL "./System/Library/LaunchAgents"
  175. # Enable and Exit
  176. # exit 0
  177. # Disable /System/Library/LaunchDaemons
  178. echo -e "\n# Disable Daemons ..."
  179. for deamon in "${DEAMONS[@]}"; do DISABLE "./System/Library/LaunchDaemons" "$deamon"; done
  180. # Disable /System/Library/LaunchAgents
  181. echo -e "\n# Disable Agents ..."
  182. for agent in "${AGENTS[@]}"; do DISABLE "./System/Library/LaunchAgents" "$agent"; done
  183. # Remove System APP
  184. echo -e "\n# Remove System APP ..."
  185. for app in "${APPS[@]}"; do RMAPP "./System/Applications" "$app"; done
  186. # Replace spindump
  187. echo -e "\n# Replace spindump ..."
  188. RENAMEBIN "/usr/sbin/spindump"
  189. # Disable Update Notice
  190. echo -e "\n# Disable Update Notice ..."
  191. if [ -f "/usr/bin/sudo" ]; then
  192. sudo find "./System/Library/PrivateFrameworks/SoftwareUpdate.framework" -type f -name "SoftwareUpdateNotificationManager" |xargs -t -I "{}" sudo chmod 644 "{}"
  193. else
  194. find "./System/Library/PrivateFrameworks/SoftwareUpdate.framework" -type f -name "SoftwareUpdateNotificationManager" |xargs -t -I "{}" chmod 644 "{}"
  195. fi
  196. # Finish
  197. echo -e "\n# Finish! \n"