2021-12-18 01:06:31 +08:00
#!/bin/bash
function cleanup ( ) {
echo "Cleaning up any existing Telegraf or Telegraf.app"
printf "\n"
rm -rf Telegraf
rm -rf Telegraf.app
}
2021-03-05 23:14:01 +08:00
# Acquire the necessary certificates.
2021-12-18 01:06:31 +08:00
# MacCertificate, MacCertificatePassword, AppleSigningAuthorityCertificate are environment variables, to follow convention they should have been all caps.
# shellcheck disable=SC2154
base64 -D -o MacCertificate.p12 <<< " $MacCertificate "
# shellcheck disable=SC2154
sudo security import MacCertificate.p12 -k /Library/Keychains/System.keychain -P " $MacCertificatePassword " -A
# shellcheck disable=SC2154
base64 -D -o AppleSigningAuthorityCertificate.cer <<< " $AppleSigningAuthorityCertificate "
2021-03-05 23:14:01 +08:00
sudo security import AppleSigningAuthorityCertificate.cer -k '/Library/Keychains/System.keychain' -A
2021-12-18 01:06:31 +08:00
amdFile = $( find " $HOME /project/dist " -name "*darwin_amd64.tar*" )
armFile = $( find " $HOME /project/dist " -name "*darwin_arm64.tar*" )
macFiles = ( " ${ amdFile } " " ${ armFile } " )
for tarFile in " ${ macFiles [@] } " ;
do
cleanup
# Create the .app bundle directory structure
RootAppDir = "Telegraf.app/Contents"
mkdir -p " $RootAppDir "
mkdir -p " $RootAppDir /MacOS "
mkdir -p " $RootAppDir /Resources "
DeveloperID = "Developer ID Application: InfluxData Inc. (M7DN9H35QT)"
# Sign telegraf binary and the telegraf_entry_mac script
echo " Extract $tarFile to $RootAppDir /Resources "
tar -xzvf " $tarFile " --strip-components= 2 -C " $RootAppDir /Resources "
printf "\n"
TelegrafBinPath = " $RootAppDir /Resources/usr/bin/telegraf "
codesign --force -s " $DeveloperID " --timestamp --options= runtime " $TelegrafBinPath "
echo " Verify if $TelegrafBinPath was signed "
codesign -dvv " $TelegrafBinPath "
printf "\n"
cp ~/project/scripts/telegraf_entry_mac " $RootAppDir " /MacOS
EntryMacPath = " $RootAppDir /MacOS/telegraf_entry_mac "
codesign -s " $DeveloperID " --timestamp --options= runtime " $EntryMacPath "
echo " Verify if $EntryMacPath was signed "
codesign -dvv " $EntryMacPath "
printf "\n"
cp ~/project/info.plist " $RootAppDir "
cp ~/project/assets/icon.icns " $RootAppDir /Resources "
chmod +x " $RootAppDir /MacOS/telegraf_entry_mac "
2021-03-05 23:14:01 +08:00
2021-12-16 07:26:59 +08:00
# Sign the entire .app bundle, and wrap it in a DMG.
2021-12-18 01:06:31 +08:00
codesign -s " $DeveloperID " --timestamp --options= runtime --deep --force Telegraf.app
baseName = $( basename " $tarFile " .tar.gz)
echo " $baseName "
2021-12-16 07:26:59 +08:00
hdiutil create -size 500m -volname Telegraf -srcfolder Telegraf.app " $baseName " .dmg
2021-12-18 01:06:31 +08:00
codesign -s " $DeveloperID " --timestamp --options= runtime " $baseName " .dmg
2021-03-05 23:14:01 +08:00
2021-12-16 07:26:59 +08:00
# Send the DMG to be notarized.
2021-12-18 01:06:31 +08:00
# AppleUsername and ApplePassword are environment variables, to follow convention they should have been all caps.
# shellcheck disable=SC2154
2021-12-16 07:26:59 +08:00
uuid = $( xcrun altool --notarize-app --primary-bundle-id "com.influxdata.telegraf" --username " $AppleUsername " --password " $ApplePassword " --file " $baseName " .dmg | awk '/RequestUUID/ { print $NF; }' )
2021-12-18 01:06:31 +08:00
echo " UUID: $uuid "
if [ [ $uuid = = "" ] ] ; then
2021-12-16 07:26:59 +08:00
echo "Could not upload for notarization."
exit 1
fi
2021-03-05 23:14:01 +08:00
2021-12-18 01:06:31 +08:00
printf "\n"
2021-12-16 07:26:59 +08:00
# Wait until the status returns something other than 'in progress'.
request_status = "in progress"
while [ [ " $request_status " = = "in progress" ] ] ; do
sleep 10
2021-12-18 01:06:31 +08:00
request_response = $( xcrun altool --notarization-info " $uuid " --username " $AppleUsername " --password " $ApplePassword " 2>& 1)
request_status = $( echo " $request_response " | awk -F ': ' '/Status:/ { print $2; }' )
2021-12-16 07:26:59 +08:00
done
2021-03-05 23:14:01 +08:00
2021-12-16 07:26:59 +08:00
if [ [ $request_status != "success" ] ] ; then
echo "Failed to notarize."
2021-12-18 01:06:31 +08:00
echo " $request_response "
cleanup
2021-12-16 07:26:59 +08:00
exit 1
fi
# Attach the notarization to the DMG.
xcrun stapler staple " $baseName " .dmg
2021-12-18 01:06:31 +08:00
cleanup
2021-12-23 06:50:55 +08:00
mkdir -p ~/project/build/dist
mv " $baseName " .dmg ~/project/build/dist
2021-12-16 07:26:59 +08:00
2021-12-18 01:06:31 +08:00
echo " $baseName .dmg signed and notarized! "
done