#!/usr/bin/env bash set -euo pipefail if [[ $# -ne 1 ]]; then echo "Использование: check_signature.sh PATH" >&2 exit 2 fi target="$1" if [[ "$target" == "~"* ]]; then target="$HOME/${target#\~}" fi if [[ ! -e "$target" ]]; then echo "Файл не найден: $target" >&2 exit 1 fi section() { printf '\n== %s ==\n' "$1" } section "Объект" ls -ld "$target" section "Тип" if [[ -d "$target" ]]; then echo "Каталог или приложение" elif [[ -f "$target" ]]; then file "$target" fi case "$target" in *.app) section "codesign verify" codesign --verify --deep --strict --verbose=2 "$target" 2>&1 || true section "codesign details" codesign -dv --verbose=4 "$target" 2>&1 || true section "Gatekeeper assess" spctl --assess --type execute --verbose=4 "$target" 2>&1 || true ;; *.pkg|*.mpkg) section "pkgutil signature" pkgutil --check-signature "$target" 2>&1 || true section "Gatekeeper assess" spctl --assess --type install --verbose=4 "$target" 2>&1 || true ;; *.dmg) section "Gatekeeper assess" spctl --assess --type open --context context:primary-signature --verbose=4 "$target" 2>&1 || true ;; *) section "codesign details" codesign -dv --verbose=4 "$target" 2>&1 || true ;; esac section "Нотаризация" if command -v xcrun >/dev/null 2>&1; then xcrun stapler validate "$target" 2>&1 || true else echo "xcrun не найден. Установите Command Line Tools." fi echo echo "Проверка завершена. Ненулевой код в выводе означает, что соответствующий тест не пройден."