#!/bin/zsh

export COPYFILE_DISABLE=true


cd universal-darwin

files=`ls`
  for f in $files; do
 	if ! [[ -L $f ]]; then
 		if  [[ "$(file $f)" = "$f: Mach-O 64-bit executable x86_64" ]]; then
 			codesign -s   "Developer ID Application: Richard Koch" --force --timestamp --options=runtime $f
 		fi
 		
 		if [[ "$(file $f)" == "$f: Mach-O universal binary"* ]]; then
 			codesign -s   "Developer ID Application: Richard Koch" --force --timestamp --options=runtime $f
 		fi
 	fi
  done

codesign -s   "Developer ID Application: Richard Koch"  --force --timestamp --options=runtime --entitlements=../gs-X11.entitlements  mf

codesign -s   "Developer ID Application: Richard Koch"  --force --timestamp --options=runtime --entitlements=../gs-X11.entitlements  xdvi-xaw

codesign -s   "Developer ID Application: Richard Koch"  --force --timestamp --options=runtime --entitlements=../gs-X11.entitlements  dvisvgm

# Fix luatex entitlements

codesign -s   "Developer ID Application: Richard Koch"  --force --timestamp --options=runtime --entitlements=../luahbtex.entitlements  luahbtex

codesign -s   "Developer ID Application: Richard Koch"  --force --timestamp --options=runtime --entitlements=../luahbtex.entitlements  luajithbtex

codesign -s   "Developer ID Application: Richard Koch"  --force --timestamp --options=runtime --entitlements=../luahbtex.entitlements  luatex

codesign -s   "Developer ID Application: Richard Koch"  --force --timestamp --options=runtime --entitlements=../luahbtex.entitlements  luajittex

cd ../
(cd  universal-darwin; tar cf - . ) > universal-darwin.tar

./xz --compress universal-darwin.tar

cp universal-darwin.tar.xz RawCode/universal-darwin.tar.xz


