| 001 | #!/bin/bash |
|---|
| 002 | #com.cocolog-nifty.quicktimer.icefloe |
|---|
| 003 | # 参考 |
|---|
| 004 | # https://eclecticlight.co/ |
|---|
| 005 | # |
|---|
| 006 | # 15.2でスキャンに時間がかかるようになったので |
|---|
| 007 | # 開始時間と終了時間をechoするように変更した |
|---|
| 008 | # XProtect.bundleのバージョンでiCloud経由のアップデートで |
|---|
| 009 | # バージョンに差異が出るのに対応した |
|---|
| 010 | # 15.3.1 対応 xprotectコマンドをフルパス指定にした |
|---|
| 011 | # 15.3.1 XProtect update をsoftwareupdateの後にした |
|---|
| 012 | # 15.4 対応 dateの環境変数がリセットされるのに対応 |
|---|
| 013 | # 15.4.1 dateコマンドの不具合対応 スペルミスを修正 |
|---|
| 014 | # 15.6 sudoの延命処理を追加した |
|---|
| 015 | # 26 macOS26で/usr/sbin/softwareupdateでパスワード要求されるようになった回避方法検討中 |
|---|
| 016 | # 26.0.1 アップデートに時間がかかるタイミングがあるためアップデート開始時間を入れた |
|---|
| 017 | # 26.0.1 XProtect updateを先に softwareupdateを後に実行するように戻した(迷走中) |
|---|
| 018 | # 26.3 restrict-software-update-require-admin-to-installの設定に依存があるのが判明対応 |
|---|
| 019 | # falseにしてからアップデートを実行して 実行後にtrueに戻す方法に落ち着いた |
|---|
| 020 | # |
|---|
| 021 | #注意 |
|---|
| 022 | #macOS26で softwareupdate --installの処理に『2時間』かかるケースがあります |
|---|
| 023 | #途中終了せずに 放置してください 2時間ぐらいしたら終わります苦笑 |
|---|
| 024 | # |
|---|
| 025 | #[macos15]ターミナル sudo でタッチID指紋認証を有効にする |
|---|
| 026 | # https://quicktimer.cocolog-nifty.com/icefloe/2024/11/post-f93c3a.html |
|---|
| 027 | #を設定すると便利です |
|---|
| 028 | # |
|---|
| 029 | ################################################# |
|---|
| 030 | ###管理者インストールしているか?チェック |
|---|
| 031 | USER_WHOAMI=$(/usr/bin/whoami) |
|---|
| 032 | /bin/echo "ExecPriv(whoami): $USER_WHOAMI" |
|---|
| 033 | |
|---|
| 034 | ###実行しているユーザー名 |
|---|
| 035 | CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }') |
|---|
| 036 | /bin/echo "ConsoleUser(scutil): $CONSOLE_USER" |
|---|
| 037 | |
|---|
| 038 | ###STAT |
|---|
| 039 | STAT_USR=$(/usr/bin/stat -f%Su /dev/console) |
|---|
| 040 | /bin/echo "STAT_USR(console): $STAT_USR" |
|---|
| 041 | |
|---|
| 042 | ##SUDO延長 |
|---|
| 043 | while true; do |
|---|
| 044 | /usr/bin/sudo -v |
|---|
| 045 | sleep 60 |
|---|
| 046 | done & |
|---|
| 047 | SUDO_KEEPALIVE_PID=$! |
|---|
| 048 | |
|---|
| 049 | |
|---|
| 050 | #com.apple.SoftwareUpdateの設定を変更してから実行する |
|---|
| 051 | STR_PREF_PATH="/Library/Preferences/com.apple.SoftwareUpdate.plist" |
|---|
| 052 | /usr/libexec/PlistBuddy -c "Print:restrict-software-update-require-admin-to-install" "${STR_PREF_PATH}" |
|---|
| 053 | /usr/bin/sudo /usr/bin/defaults write "${STR_PREF_PATH}" restrict-software-update-require-admin-to-install -bool false |
|---|
| 054 | /usr/bin/sudo /usr/libexec/PlistBuddy -c "Add:restrict-software-update-require-admin-to-install bool false" "${STR_PREF_PATH}" |
|---|
| 055 | /usr/bin/sudo /usr/libexec/PlistBuddy -c "Set:restrict-software-update-require-admin-to-install bool false" "${STR_PREF_PATH}" |
|---|
| 056 | /usr/libexec/PlistBuddy -c "Print:restrict-software-update-require-admin-to-install" "${STR_PREF_PATH}" |
|---|
| 057 | |
|---|
| 058 | STR_PREF_PATH="/Library/Managed Preferences/com.apple.SoftwareUpdate.plist" |
|---|
| 059 | /usr/libexec/PlistBuddy -c "Print:restrict-software-update-require-admin-to-install" "${STR_PREF_PATH}" |
|---|
| 060 | /usr/bin/sudo /usr/bin/defaults write "${STR_PREF_PATH}" restrict-software-update-require-admin-to-install -bool false |
|---|
| 061 | /usr/bin/sudo /usr/libexec/PlistBuddy -c "Add:restrict-software-update-require-admin-to-install bool false" "${STR_PREF_PATH}" |
|---|
| 062 | /usr/bin/sudo /usr/libexec/PlistBuddy -c "Set:restrict-software-update-require-admin-to-install bool false" "${STR_PREF_PATH}" |
|---|
| 063 | /usr/libexec/PlistBuddy -c "Print:restrict-software-update-require-admin-to-install" "${STR_PREF_PATH}" |
|---|
| 064 | |
|---|
| 065 | |
|---|
| 066 | #OS |
|---|
| 067 | STR_PLIST_FILEPATH="/System/Library/CoreServices/.SystemVersionPlatform.plist" |
|---|
| 068 | STR_OSVER=$(/usr/bin/defaults read "${STR_PLIST_FILEPATH}" ProductUserVisibleVersion) |
|---|
| 069 | /bin/echo "OSver: ${STR_OSVER}" |
|---|
| 070 | |
|---|
| 071 | #CUPS(これは私用) |
|---|
| 072 | STR_CUPS_VER=$(/usr/bin/cups-config --version) |
|---|
| 073 | /bin/echo "CUPS: ${STR_CUPS_VER}" |
|---|
| 074 | |
|---|
| 075 | #バージョン os15 |
|---|
| 076 | STR_PLIST_FILEPATH="/private/var/protected/xprotect/XProtect.bundle/Contents/Info.plist" |
|---|
| 077 | STR_XVER=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "${STR_PLIST_FILEPATH}") |
|---|
| 078 | /bin/echo "iCloud XProtect: /private/var/protected/xprotect" |
|---|
| 079 | /bin/echo "In var XProtect.bundle Ver: $STR_XVER" |
|---|
| 080 | |
|---|
| 081 | #iCloud経由のアップデートの遅延対応でこちらのバージョンも取得 |
|---|
| 082 | STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/XProtect.bundle/Contents/Info.plist" |
|---|
| 083 | STR_XVER=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "$STR_PLIST_FILEPATH") |
|---|
| 084 | /bin/echo "Legacy XProtect: /Library/Apple/System/Library/CoreServices" |
|---|
| 085 | /bin/echo "In Library XProtect.bundle Ver: $STR_XVER" |
|---|
| 086 | |
|---|
| 087 | #バージョン |
|---|
| 088 | STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/XProtect.app/Contents/Info.plist" |
|---|
| 089 | STR_XVER=$(/usr/bin/defaults read "$STR_PLIST_FILEPATH" CFBundleShortVersionString) |
|---|
| 090 | /bin/echo "XProtect.app: $STR_XVER" |
|---|
| 091 | |
|---|
| 092 | #XProtectPluginService.xpcバージョン |
|---|
| 093 | STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/XProtect.app/Contents/XPCServices/XProtectPluginService.xpc/Contents/Info.plist" |
|---|
| 094 | STR_XVER=$(/usr/bin/defaults read "$STR_PLIST_FILEPATH" CFBundleShortVersionString) |
|---|
| 095 | /bin/echo "XProtectPluginService.xpc: $STR_XVER" |
|---|
| 096 | |
|---|
| 097 | #MRT.appバージョン |
|---|
| 098 | STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/MRT.app/Contents/Info.plist" |
|---|
| 099 | STR_XVER=$(/usr/bin/defaults read "$STR_PLIST_FILEPATH" CFBundleShortVersionString) |
|---|
| 100 | /bin/echo "MRT.app: $STR_XVER" |
|---|
| 101 | |
|---|
| 102 | #AppleKextExcludeListバージョン |
|---|
| 103 | STR_PLIST_FILEPATH="/Library/Apple/System/Library/Extensions/AppleKextExcludeList.kext/Contents/Info.plist" |
|---|
| 104 | STR_XVER=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "$STR_PLIST_FILEPATH") |
|---|
| 105 | /bin/echo "AppleKextExcludeList.kext: $STR_XVER" |
|---|
| 106 | |
|---|
| 107 | #チェック |
|---|
| 108 | /bin/echo "/usr/bin/sudo /usr/bin/xprotect check" |
|---|
| 109 | /usr/bin/sudo /usr/bin/xprotect check |
|---|
| 110 | #バージョン |
|---|
| 111 | /bin/echo "/usr/bin/xprotect version" |
|---|
| 112 | /usr/bin/xprotect version |
|---|
| 113 | #アップデート |
|---|
| 114 | /bin/echo "/usr/bin/sudo /usr/bin/xprotect update" |
|---|
| 115 | /usr/bin/sudo /usr/bin/xprotect update |
|---|
| 116 | #チェック |
|---|
| 117 | /bin/echo "/usr/bin/sudo /usr/bin/xprotect check" |
|---|
| 118 | /usr/bin/sudo /usr/bin/xprotect check |
|---|
| 119 | #バージョン |
|---|
| 120 | /bin/echo "/usr/bin/xprotect version" |
|---|
| 121 | /usr/bin/xprotect version |
|---|
| 122 | #ステータス |
|---|
| 123 | /bin/echo "/usr/bin/xprotect status" |
|---|
| 124 | /usr/bin/xprotect status |
|---|
| 125 | # 戻り値を選んで後処理に使う場合 |
|---|
| 126 | # /usr/bin/xprotect status --json |
|---|
| 127 | # /usr/bin/xprotect check --json |
|---|
| 128 | # /usr/bin/xprotect version --json |
|---|
| 129 | # /usr/bin/sudo /usr/bin/xprotect update --prerelease |
|---|
| 130 | # man xprotect |
|---|
| 131 | # |
|---|
| 132 | #ソフトウェアアップデート |
|---|
| 133 | #/usr/sbin/softwareupdate --list |
|---|
| 134 | #/usr/sbin/softwareupdate --list --all |
|---|
| 135 | #/usr/sbin/softwareupdate --list --os-only |
|---|
| 136 | #/usr/sbin/softwareupdate --list --safari-only |
|---|
| 137 | #/usr/sbin/softwareupdate --list --include-config-data |
|---|
| 138 | #/usr/sbin/softwareupdate --list-full-installers |
|---|
| 139 | #/usr/sbin/softwareupdate --fetch-full-installer --full-installer-version 15.3.2 |
|---|
| 140 | #/usr/sbin/softwareupdate --list --recommended --include-config-data |
|---|
| 141 | #/usr/sbin/softwareupdate --download --recommended --include-config-data |
|---|
| 142 | #/usr/sbin/softwareupdate --download --include-config-data |
|---|
| 143 | # |
|---|
| 144 | /bin/echo "この後" |
|---|
| 145 | /bin/echo "softwareupdateコマンドでパスワード要求がある場合" |
|---|
| 146 | /bin/echo "restrict-software-update-require-admin-to-install設定がされていると" |
|---|
| 147 | /bin/echo "softwareupdateが失敗します" |
|---|
| 148 | # |
|---|
| 149 | /bin/echo "/usr/sbin/softwareupdate --list --recommended --include-config-data" |
|---|
| 150 | /bin/date -u +"%Y-%m-%dT%H:%M:%SZ" |
|---|
| 151 | /usr/sbin/softwareupdate --list --recommended --include-config-data |
|---|
| 152 | /bin/date -u +"%Y-%m-%dT%H:%M:%SZ" |
|---|
| 153 | # |
|---|
| 154 | /bin/echo "/usr/sbin/softwareupdate --download --recommended --include-config-data" |
|---|
| 155 | /bin/date -u +"%Y-%m-%dT%H:%M:%SZ" |
|---|
| 156 | /usr/sbin/softwareupdate --download --recommended --include-config-data |
|---|
| 157 | /bin/date -u +"%Y-%m-%dT%H:%M:%SZ" |
|---|
| 158 | # |
|---|
| 159 | #とりあえずここまでの場合はここで停止 |
|---|
| 160 | #exit 0 |
|---|
| 161 | ############ |
|---|
| 162 | STR_DATE=$(/bin/date "+%Y年 %-m月%-d日 %A %k時%M分%S秒 %Z") |
|---|
| 163 | /bin/echo "softwareupdateを実行します、最大2時間かかるケースもあります" |
|---|
| 164 | /bin/echo "softwareupdate開始: ${STR_DATE}" |
|---|
| 165 | # |
|---|
| 166 | #macOS26でパスワードを要求されるように変更になったので中止 |
|---|
| 167 | /bin/echo "/usr/bin/sudo /usr/sbin/softwareupdate --install --recommended --include-config-data" |
|---|
| 168 | /usr/bin/sudo /usr/sbin/softwareupdate --install --recommended --include-config-data |
|---|
| 169 | |
|---|
| 170 | STR_DATE=$(/bin/date "+%Y年 %-m月%-d日 %A %k時%M分%S秒 %Z") |
|---|
| 171 | /bin/echo "softwareupdate終了: ${STR_DATE}" |
|---|
| 172 | /bin/echo "" |
|---|
| 173 | |
|---|
| 174 | ############ |
|---|
| 175 | #必要になったらログ取るように準備だけ |
|---|
| 176 | #ログ用のディレクトリ等 現時点では何もしないので コメントアウトしても問題ない |
|---|
| 177 | /usr/bin/sudo -u "$STAT_USR" /bin/mkdir -p "/Users/${STAT_USR}/Library/Logs/XProtect" |
|---|
| 178 | PATH_EXEC_LOG_FILE="/Users/${STAT_USR}/Library/Logs/XProtect/ExecLog.log" |
|---|
| 179 | /usr/bin/sudo -u "$STAT_USR" /usr/bin/touch "${PATH_EXEC_LOG_FILE}" |
|---|
| 180 | /bin/rm "${PATH_EXEC_LOG_FILE}" |
|---|
| 181 | /usr/bin/sudo -u "$STAT_USR" /usr/bin/touch "${PATH_EXEC_LOG_FILE}" |
|---|
| 182 | #JSONの戻り値確認用 コメントアウトしても問題ない |
|---|
| 183 | /usr/bin/sudo -u "$STAT_USR" /usr/bin/xprotect status --json >"/Users/${STAT_USR}/Library/Logs/XProtect/status.json" |
|---|
| 184 | /usr/bin/sudo -u "$STAT_USR" /usr/bin/xprotect version --json >"/Users/${STAT_USR}/Library/Logs/XProtect/version.json" |
|---|
| 185 | /usr/bin/xprotect check --json >"/Users/${STAT_USR}/Library/Logs/XProtect/check.json" |
|---|
| 186 | |
|---|
| 187 | #日付の環境変数がリセットされた場合の対応 |
|---|
| 188 | STR_DATE=$(/bin/date "+%Y年 %-m月%-d日 %A %k時%M分%S秒 %Z") |
|---|
| 189 | /bin/echo "スキャン開始します 少し時間がかかります(約10分)" |
|---|
| 190 | /bin/echo "スキャン開始: ${STR_DATE}" |
|---|
| 191 | #スキャン実行 |
|---|
| 192 | /bin/echo "/Library/Apple/System/Library/CoreServices/XProtect.app/Contents/MacOS/XProtect" |
|---|
| 193 | /Library/Apple/System/Library/CoreServices/XProtect.app/Contents/MacOS/XProtect |
|---|
| 194 | |
|---|
| 195 | # 以下のフォルダにある各種バイナリーが順番に呼び出されて処理する |
|---|
| 196 | # /Library/Apple/System/Library/CoreServices/XProtect.app/Contents/MacOS |
|---|
| 197 | # 20250326時点で26点バイナリーがある |
|---|
| 198 | # 20250806 macOS15.6で1つ減って25点あるバイナリー |
|---|
| 199 | # 20260318 macOS26 で26点に戻る |
|---|
| 200 | # XProtect |
|---|
| 201 | # XProtectRemediatorAdload |
|---|
| 202 | # XProtectRemediatorBadGacha |
|---|
| 203 | # XProtectRemediatorBlueTop |
|---|
| 204 | # XProtectRemediatorBundlore |
|---|
| 205 | # XProtectRemediatorCardboardCutout |
|---|
| 206 | # XProtectRemediatorColdSnap |
|---|
| 207 | # XProtectRemediatorConductor |
|---|
| 208 | # XProtectRemediatorCrapyrator |
|---|
| 209 | # XProtectRemediatorDolittle |
|---|
| 210 | # XProtectRemediatorDubRobber |
|---|
| 211 | # XProtectRemediatorEicar |
|---|
| 212 | # XProtectRemediatorFloppyFlipper |
|---|
| 213 | # XProtectRemediatorGenieo |
|---|
| 214 | # XProtectRemediatorGreenAcre |
|---|
| 215 | # XProtectRemediatorKeySteal |
|---|
| 216 | # XProtectRemediatorMRTv3 |
|---|
| 217 | # XProtectRemediatorPirrit |
|---|
| 218 | # XProtectRemediatorRankStank |
|---|
| 219 | # XProtectRemediatorRoachFlight |
|---|
| 220 | # XProtectRemediatorSheepSwap |
|---|
| 221 | # XProtectRemediatorSnowBeagle |
|---|
| 222 | # XProtectRemediatorSnowDrift |
|---|
| 223 | # XProtectRemediatorToyDrop |
|---|
| 224 | # XProtectRemediatorTrovi |
|---|
| 225 | # XProtectRemediatorWaterNet |
|---|
| 226 | |
|---|
| 227 | STR_DATE=$(/bin/date "+%Y年 %-m月%-d日 %A %k時%M分%S秒 %Z") |
|---|
| 228 | /bin/echo "スキャン終了しました" |
|---|
| 229 | /bin/echo "スキャン終了: ${STR_DATE}" |
|---|
| 230 | #icloud経由の場合に備えて再実行 |
|---|
| 231 | /usr/bin/sudo XProtect update |
|---|
| 232 | |
|---|
| 233 | #バージョン os15 /private/var のXProtect.bundle |
|---|
| 234 | STR_PLIST_FILEPATH="/private/var/protected/xprotect/XProtect.bundle/Contents/Info.plist" |
|---|
| 235 | STR_XVER=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "$STR_PLIST_FILEPATH") |
|---|
| 236 | /bin/echo "In var XProtect.bundle Ver: $STR_XVER" |
|---|
| 237 | |
|---|
| 238 | #iCloud経由のアップデートの遅延対応でこちらのバージョンも取得 |
|---|
| 239 | #/Library/Apple の XProtect.bundle |
|---|
| 240 | STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/XProtect.bundle/Contents/Info.plist" |
|---|
| 241 | STR_XVER=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "$STR_PLIST_FILEPATH") |
|---|
| 242 | /bin/echo "In Library XProtect.bundle Ver: $STR_XVER" |
|---|
| 243 | |
|---|
| 244 | #バージョン XProtect.app os14 |
|---|
| 245 | STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/XProtect.app/Contents/Info.plist" |
|---|
| 246 | STR_XVER=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "$STR_PLIST_FILEPATH") |
|---|
| 247 | /bin/echo "XprotectAppVer: $STR_XVER" |
|---|
| 248 | |
|---|
| 249 | #バージョン XProtect.appのXPCServices |
|---|
| 250 | STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/XProtect.app/Contents/XPCServices/XProtectPluginService.xpc/Contents/Info.plist" |
|---|
| 251 | STR_XVER=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "$STR_PLIST_FILEPATH") |
|---|
| 252 | /bin/echo "XPC: $STR_XVER" |
|---|
| 253 | |
|---|
| 254 | #バージョン MRT.app |
|---|
| 255 | STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/MRT.app/Contents/Info.plist" |
|---|
| 256 | STR_XVER=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "$STR_PLIST_FILEPATH") |
|---|
| 257 | /bin/echo "MRT: $STR_XVER" |
|---|
| 258 | |
|---|
| 259 | #バージョン AppleKextExcludeList |
|---|
| 260 | STR_PLIST_FILEPATH="/Library/Apple/System/Library/Extensions/AppleKextExcludeList.kext/Contents/Info.plist" |
|---|
| 261 | STR_XVER=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "$STR_PLIST_FILEPATH") |
|---|
| 262 | /bin/echo "AppleKextExcludeList: $STR_XVER" |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | #com.apple.SoftwareUpdateの設定を戻す |
|---|
| 266 | STR_PREF_PATH="/Library/Preferences/com.apple.SoftwareUpdate.plist" |
|---|
| 267 | /bin/echo "${STR_PREF_PATH}" |
|---|
| 268 | /usr/libexec/PlistBuddy -c "Print :restrict-software-update-require-admin-to-install" "${STR_PREF_PATH}" |
|---|
| 269 | /usr/bin/sudo /usr/bin/defaults write "${STR_PREF_PATH}" restrict-software-update-require-admin-to-install -bool true |
|---|
| 270 | /usr/libexec/PlistBuddy -c "Print :restrict-software-update-require-admin-to-install" "${STR_PREF_PATH}" |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | #SURO終了 |
|---|
| 275 | /bin/kill "$SUDO_KEEPALIVE_PID" |
|---|
| 276 | |
|---|
| 277 | exit 0 |
|---|