#!/bin/zsh

# stibizt: https://cmake.org/Bug/view.php?id=15507

code_sign_identity="Developer ID"

if [ -z $1 ]; then
    echo "Usage: codesign_miktex /path/MiKTeX\ Console.app"
    exit 1
fi

app_dir=$1

for d in Frameworks MacOS PlugIns bin libexec miktex-lib; do
    find "$app_dir/Contents/$d" -type f -exec codesign --verbose --force --options runtime --sign "$code_sign_identity" {} \;
done

codesign --verbose --force --options runtime --sign "$code_sign_identity" "$app_dir"

echo "Verifying..."
spctl -a -t exec -vv "$app_dir"
