MacInitial.sh 6.5 KB

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