Skip to content

Instantly share code, notes, and snippets.

@nl5887
Last active May 22, 2018 21:30
Show Gist options
  • Select an option

  • Save nl5887/36969dc461e4dc69c2e88203d9d1088a to your computer and use it in GitHub Desktop.

Select an option

Save nl5887/36969dc461e4dc69c2e88203d9d1088a 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: John Doe (AB12DEF34G)" $FILENAME
else
go build -ldflags "$LDFLAGS" ${@:2}
fi
else
go $@
fi
#!/bin/bash
codesign -f -s "Mac Developer: John Doe (AB12DEF34G)" $FILENAME
$@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment