20260317

XProtectアップデート 5334



XProtectアップデート  XProtectPlistConfigData_10_15-5334

doXProtect4Sudo.bash

サンプルコード

サンプルソース(参考)
行番号ソース
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###管理者インストールしているか?チェック
031USER_WHOAMI=$(/usr/bin/whoami)
032/bin/echo "ExecPriv(whoami): $USER_WHOAMI"
033
034###実行しているユーザー名
035CONSOLE_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
039STAT_USR=$(/usr/bin/stat -f%Su /dev/console)
040/bin/echo "STAT_USR(console): $STAT_USR"
041
042##SUDO延長
043while true; do
044  /usr/bin/sudo -v
045  sleep 60
046done &
047SUDO_KEEPALIVE_PID=$!
048
049
050#com.apple.SoftwareUpdateの設定を変更してから実行する
051STR_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
058STR_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
067STR_PLIST_FILEPATH="/System/Library/CoreServices/.SystemVersionPlatform.plist"
068STR_OSVER=$(/usr/bin/defaults read "${STR_PLIST_FILEPATH}" ProductUserVisibleVersion)
069/bin/echo "OSver: ${STR_OSVER}"
070
071#CUPS(これは私用)
072STR_CUPS_VER=$(/usr/bin/cups-config --version)
073/bin/echo "CUPS: ${STR_CUPS_VER}"
074
075#バージョン os15
076STR_PLIST_FILEPATH="/private/var/protected/xprotect/XProtect.bundle/Contents/Info.plist"
077STR_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経由のアップデートの遅延対応でこちらのバージョンも取得
082STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/XProtect.bundle/Contents/Info.plist"
083STR_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#バージョン
088STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/XProtect.app/Contents/Info.plist"
089STR_XVER=$(/usr/bin/defaults read "$STR_PLIST_FILEPATH" CFBundleShortVersionString)
090/bin/echo "XProtect.app: $STR_XVER"
091
092#XProtectPluginService.xpcバージョン
093STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/XProtect.app/Contents/XPCServices/XProtectPluginService.xpc/Contents/Info.plist"
094STR_XVER=$(/usr/bin/defaults read "$STR_PLIST_FILEPATH" CFBundleShortVersionString)
095/bin/echo "XProtectPluginService.xpc: $STR_XVER"
096
097#MRT.appバージョン
098STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/MRT.app/Contents/Info.plist"
099STR_XVER=$(/usr/bin/defaults read "$STR_PLIST_FILEPATH" CFBundleShortVersionString)
100/bin/echo "MRT.app: $STR_XVER"
101
102#AppleKextExcludeListバージョン
103STR_PLIST_FILEPATH="/Library/Apple/System/Library/Extensions/AppleKextExcludeList.kext/Contents/Info.plist"
104STR_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############
162STR_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
170STR_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"
178PATH_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#日付の環境変数がリセットされた場合の対応
188STR_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
227STR_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
234STR_PLIST_FILEPATH="/private/var/protected/xprotect/XProtect.bundle/Contents/Info.plist"
235STR_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
240STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/XProtect.bundle/Contents/Info.plist"
241STR_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
245STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/XProtect.app/Contents/Info.plist"
246STR_XVER=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "$STR_PLIST_FILEPATH")
247/bin/echo "XprotectAppVer: $STR_XVER"
248
249#バージョン XProtect.appのXPCServices
250STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/XProtect.app/Contents/XPCServices/XProtectPluginService.xpc/Contents/Info.plist"
251STR_XVER=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "$STR_PLIST_FILEPATH")
252/bin/echo "XPC: $STR_XVER"
253
254#バージョン MRT.app
255STR_PLIST_FILEPATH="/Library/Apple/System/Library/CoreServices/MRT.app/Contents/Info.plist"
256STR_XVER=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "$STR_PLIST_FILEPATH")
257/bin/echo "MRT: $STR_XVER"
258
259#バージョン AppleKextExcludeList
260STR_PLIST_FILEPATH="/Library/Apple/System/Library/Extensions/AppleKextExcludeList.kext/Contents/Info.plist"
261STR_XVER=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "$STR_PLIST_FILEPATH")
262/bin/echo "AppleKextExcludeList: $STR_XVER"
263
264
265#com.apple.SoftwareUpdateの設定を戻す
266STR_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
277exit 0
AppleScriptで生成しました

実行結果 ログ


サンプルソース(参考)
行番号ソース
001Last login: Wed Mar 18 10:10:18 on ttys000
002zsh $ /doXProtect4Sudo.bash
003
004Add: ":restrict-software-update-require-admin-to-install" Entry Already Exists
005false
006Print: Entry, ":restrict-software-update-require-admin-to-install", Does Not Exist
007false
008OSver: 26.3
009CUPS: 2.3.4
010iCloud XProtect: /private/var/protected/xprotect
011In var XProtect.bundle Ver: 5333
012Legacy XProtect: /Library/Apple/System/Library/CoreServices
013In Library XProtect.bundle Ver: 5333
014XProtect.app: 157
015XProtectPluginService.xpc: 74
016MRT.app: 1.93
017AppleKextExcludeList.kext: 21.0.0
018/usr/bin/sudo /usr/bin/xprotect check
019Current update: date: 2026-03-17 18:16:27 +0000 version: 5334
020/usr/bin/xprotect  version
021Version: 5333 Installed: 2026-03-11 03:19:31 +0000
022/usr/bin/sudo /usr/bin/xprotect update
023Starting update.
024Update succeeded: Activated update CloudKitUpdate[v5334 - current @ 2026-03-17 18:16:27 +0000]
025/usr/bin/sudo /usr/bin/xprotect check
026Current update: date: 2026-03-17 18:16:27 +0000 version: 5334
027/usr/bin/xprotect version
028Version: 5334 Installed: 2026-03-18 01:11:21 +0000
029/usr/bin/xprotect status
030XProtect launch scans: enabled
031XProtect background scans: enabled
032/usr/sbin/softwareupdate --list --recommended --include-config-data
0332026-03-18T01:11:21Z
034Software Update Tool
035
036Finding available software
037Software Update found the following new or updated software:
038* Label: XProtectPlistConfigData_10_15-5334
039  Title: XProtectPlistConfigData, Version: 5334, Size: 1251KiB, Recommended: YES,
0402026-03-18T01:11:31Z
041/usr/sbin/softwareupdate --download --recommended --include-config-data
0422026-03-18T01:11:31Z
043Software Update Tool
044
045Finding available software
046
047Downloading XProtectPlistConfigData
048Downloaded XProtectPlistConfigData
049Done.
0502026-03-18T01:11:41Z
051softwareupdateを実行します、最大2時間かかるケースもあります
052softwareupdate開始: 2026年 3月18日 水曜日 10時11分41秒 JST
053/usr/bin/sudo /usr/sbin/softwareupdate --install --recommended --include-config-data
054Software Update Tool
055
056Finding available software
057
058Downloaded XProtectPlistConfigData
059Installing XProtectPlistConfigData
060Done with XProtectPlistConfigData
061Done.
062softwareupdate終了: 2026年 3月18日 水曜日 10時11分52秒 JST
063
064スキャン開始: 2026年 3月18日 水曜日 10時11分52秒 JST
065/Library/Apple/System/Library/CoreServices/XProtect.app/Contents/MacOS/XProtect
066スキャン終了しました
067スキャン終了: 2026年 3月18日 水曜日 10時29分57秒 JST
068Starting update.
069No update applied, already up to date
070In var XProtect.bundle Ver: 5334
071In Library XProtect.bundle Ver: 5334
072XprotectAppVer: 157
073XPC: 74
074MRT: 1.93
075AppleKextExcludeList: 21.0.0
076/Library/Preferences/com.apple.SoftwareUpdate.plist
077false
078true
AppleScriptで生成しました