Skip to content

Instantly share code, notes, and snippets.

@nl5887
Created May 22, 2018 21:28
Show Gist options
  • Select an option

  • Save nl5887/8dca8785bcab239a88a8ae990e65e895 to your computer and use it in GitHub Desktop.

Select an option

Save nl5887/8dca8785bcab239a88a8ae990e65e895 to your computer and use it in GitHub Desktop.
Codesigning wrapper for Go
#!/bin/bash
if [ "$#" -eq 0 ]; then
$GOROOT/bin/go $@
exit
fi
LDFLAGS=""
if [ -e scripts/gen-ldflags.go ]; then
LDFLAGS="$(go run -exec ~/.gopath/bin/sign-wrapper.sh scripts/gen-ldflags.go) $LDFLAGS"
fi
if [ $1 == "run" ]; then
shift
echo $@
$GOROOT/bin/go run -ldflags "$LDFLAGS" --exec ~/.gopath/bin/sign-wrapper.sh $@
elif [ $1 == "test" ]; then
$GOROOT/bin/go test -ldflags "$LDFLAGS" --exec ~/.gopath/bin/sign-wrapper.sh ${@:2}
elif [ $1 == "build" ]; then
echo "Compiling binary ${@:2}"
if [ $? -eq 0 ]; then
FILENAME=$(echo $OUTPUT|tr ' ' '\n'|tail -n1|head -n1)
echo "Signing $FILENAME..."
codesign -f -s "Mac Developer: Remco Verhoef (KN95SHF89R)" $FILENAME
else
go build -ldflags "$LDFLAGS" ${@:2}
fi
else
go $@
fi
#!/bin/bash
codesign -f -s "Mac Developer: Remco Verhoef (KN95SHF89R)" $1
$@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment