ZaStoGram_desktop/Telegram/build/build.sh
John Preston 873b9db7a9 Turn on Enhanced Security for the macOS widget helper
Task: 2026/11/20/turn-on-enhanced-security-for-the-macos-widget-helper
2026-11-22 22:36:09 +04:00

667 lines
25 KiB
Shell
Executable file

set -e
FullExecPath=$PWD
pushd `dirname $0` > /dev/null
FullScriptPath=`pwd`
popd > /dev/null
arg1="$1"
arg2="$2"
arg3="$3"
if [ ! -d "$FullScriptPath/../../../DesktopPrivate" ]; then
echo ""
echo "This script is for building the production version of Telegram Desktop."
echo ""
echo "For building custom versions please visit the build instructions page at:"
echo "https://github.com/telegramdesktop/tdesktop/#build-instructions"
exit
fi
Error () {
cd $FullExecPath
echo "$1"
exit 1
}
if [ ! -f "$FullScriptPath/target" ]; then
Error "Build target not found!"
fi
while IFS='' read -r line || [[ -n "$line" ]]; do
BuildTarget="$line"
done < "$FullScriptPath/target"
if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "macstore" ]; then
python3 "$FullScriptPath/build_mac.py" --check \
|| Error "macOS releases require preserved Command Line Tools 26.6 and macOS SDK 26.5."
fi
UpdateKeysLoc="$FullScriptPath/../Resources/update"
# Update signing settings. Edit these directly when rotating keys, they are
# the single source of truth (no environment overrides).
ReleaseLocalKey="$FullScriptPath/../../../DesktopPrivate/modern/release-local-2026b.pem"
ReleaseLocalKeyId="rl-2026b"
ReleaseCloudVault="tdesktop-release-kv"
ReleaseCloudKeyId="rc-2026a"
ReleaseCloudKeyName="release-2026a"
if [ "$BuildTarget" != "macstore" ]; then
if [ ! -f "$ReleaseLocalKey" ]; then
Error "Release local key not found: $ReleaseLocalKey"
fi
python3 "$FullScriptPath/sign_update.py" --check \
--az-vault "$ReleaseCloudVault" \
--az-key "$ReleaseCloudKeyName" \
--keys-loc "$UpdateKeysLoc" \
--key-id "$ReleaseCloudKeyId" \
|| Error "Cloud update signing is not ready, fix the setup above before building."
fi
while IFS='' read -r line || [[ -n "$line" ]]; do
set $line
eval $1="$2"
done < "$FullScriptPath/version"
if [ "$AppVersion" -lt 7002000 ]; then
Error "The v2 update format requires version 7.2 or newer."
fi
VersionForPacker="$AppVersion"
if [ "$AlphaVersion" != "0" ]; then
AppVersion="$AlphaVersion"
AppVersionStrFull="${AppVersionStr}_${AlphaVersion}"
AlphaBetaParam="-alpha $AlphaVersion"
AlphaKeyFile="talpha_${AppVersion}_key"
elif [ "$BetaChannel" == "0" ]; then
AppVersionStrFull="$AppVersionStr"
AlphaBetaParam=''
else
AppVersionStrFull="$AppVersionStr.beta"
AlphaBetaParam='-beta'
fi
if [ "$AlphaVersion" != "0" ]; then
Error "The v2 update format has no alpha channel."
fi
case "$AppVersionStr" in
*.*.*) ;;
*) Error "AppVersionStr '$AppVersionStr' must have three components for the v2 names." ;;
esac
UpdateChannel="stable"
ArtifactSuffix=""
if [ "$BetaChannel" != "0" ]; then
UpdateChannel="beta"
ArtifactSuffix="-beta"
fi
BackupFolder="t$BuildTarget"
if [ "$BuildTarget" == "linux" ]; then
BackupFolder="linux-x64"
elif [ "$BuildTarget" == "mac" ]; then
BackupFolder="mac"
fi
SignUpdate() {
until python3 "$FullScriptPath/sign_update.py" \
--input signing-input.bin \
--output release-cloud.sig \
--az-vault "$ReleaseCloudVault" \
--az-key "$ReleaseCloudKeyName"; do
echo "Cloud signing of $UpdateFile failed, retrying in 10 seconds (fix az login / network in another terminal).."
sleep 10
done
}
PackUpdate() {
"./Packer" "$@" -version $VersionForPacker -channel $UpdateChannel \
-keys-loc "$UpdateKeysLoc" -emit-signing-input signing-input.bin
SignUpdate
"./Packer" -channel $UpdateChannel -keys-loc "$UpdateKeysLoc" \
-unsigned "$UpdateFile.unsigned" \
-embed-signatures "$ReleaseCloudKeyId:release-cloud.sig" \
-local-key "$ReleaseLocalKey" \
-local-key-id "$ReleaseLocalKeyId"
rm signing-input.bin release-cloud.sig "$UpdateFile.unsigned"
}
CheckWidgetHelper() {
if [ ! -f "$1/Contents/Helpers/TelegramWidgetHelper" ]; then
echo "TelegramWidgetHelper not found in $1!"
return 1
fi
python3 "$FullScriptPath/sign_mac.py" --check "$1"
}
Sha256() {
local Digest
[ -f "$1" ] && Digest=`shasum -a 256 < "$1"` || return 1
Digest="${Digest%% *}"
case "$Digest" in
*[!0-9a-f]*) return 1 ;;
esac
[ ${#Digest} -eq 64 ] && echo "$Digest"
}
PolicyDigest() {
Sha256 "$HomePath/Telegram/TelegramWidgetHelperDirect.entitlements"
}
echo ""
HomePath="$FullScriptPath/.."
if [ "$BuildTarget" == "linux" ]; then
echo "Building version $AppVersionStrFull for Linux 64bit.."
UpdateFile="td-update-linux-x64-$AppVersion$ArtifactSuffix"
SetupFile="td-setup-linux-x64-$AppVersionStr$ArtifactSuffix.tar.xz"
ProjectPath="$HomePath/../out"
ReleasePath="$ProjectPath/Release"
BinaryName="Telegram"
elif [ "$BuildTarget" == "mac" ] ; then
if [ "$arg1" == "x86_64" ] || [ "$arg1" == "arm64" ]; then
echo "Building version $AppVersionStrFull for macOS 10.13+ ($arg1).."
MacArch="$arg1"
if [ "$arg2" == "request_uuid" ] && [ "$arg3" != "" ]; then
NotarizeRequestId="$arg3"
fi
else
echo "Building version $AppVersionStrFull for macOS 10.13+.."
if [ "$arg2" != "" ]; then
if [ "$arg1" == "request_uuid_x86_64" ]; then
NotarizeRequestIdAMD64="$arg2"
elif [ "$arg1" == "request_uuid_arm64" ]; then
NotarizeRequestIdARM64="$arg2"
elif [ "$arg1" == "request_uuid" ]; then
NotarizeRequestId="$arg2"
fi
fi
fi
if [ "$AC_USERNAME" == "" ]; then
Error "AC_USERNAME not found!"
fi
UpdateFileAMD64="td-update-mac-x64-$AppVersion$ArtifactSuffix"
UpdateFileARM64="td-update-mac-arm-$AppVersion$ArtifactSuffix"
if [ "$MacArch" == "arm64" ]; then
UpdateFile="$UpdateFileARM64"
elif [ "$MacArch" == "x86_64" ]; then
UpdateFile="$UpdateFileAMD64"
fi
ProjectPath="$HomePath/../out"
ReleasePath="$ProjectPath/Release"
BinaryName="Telegram"
if [ "$MacArch" != "" ]; then
BundleName="$BinaryName.$MacArch.app"
if [ "$MacArch" == "arm64" ]; then
SetupFile="td-setup-mac-arm-$AppVersionStr$ArtifactSuffix.dmg"
else
SetupFile="td-setup-mac-x64-$AppVersionStr$ArtifactSuffix.dmg"
fi
else
BundleName="$BinaryName.app"
SetupFile="td-setup-mac-$AppVersionStr$ArtifactSuffix.dmg"
fi
elif [ "$BuildTarget" == "macstore" ]; then
if [ "$AlphaVersion" != "0" ]; then
Error "Can't build macstore alpha version!"
fi
echo "Building version $AppVersionStrFull for Mac App Store.."
ProjectPath="$HomePath/../out"
ReleasePath="$ProjectPath/Release"
BinaryName="Telegram Lite"
BundleName="$BinaryName.app"
else
Error "Invalid target!"
fi
if [ "$AlphaVersion" != "0" ]; then
if [ -d "$ReleasePath/deploy/$AppVersionStrMajor/$AppVersionStrFull" ]; then
Error "Deploy folder for version $AppVersionStrFull already exists!"
fi
else
if [ -d "$ReleasePath/deploy/$AppVersionStrMajor/$AppVersionStr.alpha" ]; then
Error "Deploy folder for version $AppVersionStr.alpha already exists!"
fi
if [ -d "$ReleasePath/deploy/$AppVersionStrMajor/$AppVersionStr.beta" ]; then
Error "Deploy folder for version $AppVersionStr.beta already exists!"
fi
if [ -d "$ReleasePath/deploy/$AppVersionStrMajor/$AppVersionStr" ]; then
Error "Deploy folder for version $AppVersionStr already exists!"
fi
if [ -f "$ReleasePath/$UpdateFile" ]; then
Error "Update file for version $AppVersion already exists!"
fi
fi
if [ "$MacArch" == "" ]; then
LockDir="$ProjectPath/.build.lock"
if ! mkdir -p "$ProjectPath" || ! mkdir "$LockDir" 2> /dev/null; then
Error "Another build.sh seems to be running (found $LockDir, remove it if stale)."
fi
trap 'rmdir "$LockDir"' EXIT
fi
if [ "$BuildTarget" == "mac" ] && [ "$MacArch" == "" ]; then
ExistingUpdates=""
if [ -e "$ReleasePath/$UpdateFileARM64" ] || [ -L "$ReleasePath/$UpdateFileARM64" ]; then
ExistingUpdates="arm64 $UpdateFileARM64"
fi
if [ -e "$ReleasePath/$UpdateFileAMD64" ] || [ -L "$ReleasePath/$UpdateFileAMD64" ]; then
ExistingUpdates="${ExistingUpdates:+$ExistingUpdates, }x86_64 $UpdateFileAMD64"
fi
if [ "$ExistingUpdates" != "" ]; then
Error "Update files already exist in $ReleasePath ($ExistingUpdates), set them aside before rerunning!"
fi
ParentPolicy=`PolicyDigest` || Error "TelegramWidgetHelperDirect.entitlements could not be read!"
fi
DeployPath="$ReleasePath/deploy/$AppVersionStrMajor/$AppVersionStrFull"
if [ "$BuildTarget" == "linux" ]; then
DropboxSymbolsPath="/media/psf/Dropbox/Telegram/symbols"
if [ ! -d "$DropboxSymbolsPath" ]; then
DropboxSymbolsPath="/mnt/c/Telegram/Dropbox/Telegram/symbols"
if [ ! -d "$DropboxSymbolsPath" ]; then
Error "Dropbox path not found!"
fi
fi
BackupPath="/media/psf/backup/tdesktop/$AppVersionStrMajor/$AppVersionStrFull/$BackupFolder"
if [ ! -d "/media/psf/backup/tdesktop" ]; then
BackupPath="/mnt/c/Telegram/Projects/backup/tdesktop/$AppVersionStrMajor/$AppVersionStrFull/$BackupFolder"
if [ ! -d "/mnt/c/Telegram/Projects/backup/tdesktop" ]; then
Error "Backup folder not found!"
fi
fi
./build/docker/centos_env/run.sh /usr/src/tdesktop/Telegram/build/docker/build.sh
echo "Copying from docker result folder."
cp "$ReleasePath/root/$BinaryName" "$ReleasePath/$BinaryName"
cp "$ReleasePath/root/Updater" "$ReleasePath/Updater"
cp "$ReleasePath/root/Packer" "$ReleasePath/Packer"
mkdir -p "$ReleasePath/TelegramHelpers"
cp "$ReleasePath/root/TelegramHelpers/TelegramWidgetHelper" "$ReleasePath/TelegramHelpers/TelegramWidgetHelper"
echo "Dumping debug symbols.."
"$ReleasePath/dump_syms" "$ReleasePath/$BinaryName" > "$ReleasePath/$BinaryName.sym"
echo "Done!"
echo "Stripping the executable.."
"$FullScriptPath/minidebug.sh" "$ReleasePath/$BinaryName"
echo "Done!"
echo "Preparing version $AppVersionStrFull, executing Packer.."
cd "$ReleasePath"
PackUpdate -path "$BinaryName" -path Updater -path TelegramHelpers/TelegramWidgetHelper
echo "Packer done!"
if [ "$AlphaVersion" != "0" ]; then
if [ ! -f "$ReleasePath/$AlphaKeyFile" ]; then
Error "Alpha version key file not found!"
fi
while IFS='' read -r line || [[ -n "$line" ]]; do
AlphaSignature="$line"
done < "$ReleasePath/$AlphaKeyFile"
UpdateFile="${UpdateFile}_${AlphaSignature}"
SetupFile="talpha${AlphaVersion}_${AlphaSignature}.tar.xz"
fi
SymbolsHash=`head -n 1 "$ReleasePath/$BinaryName.sym" | awk -F " " 'END {print $4}'`
echo "Copying $BinaryName.sym to $DropboxSymbolsPath/$BinaryName/$SymbolsHash"
mkdir -p "$DropboxSymbolsPath/$BinaryName/$SymbolsHash"
cp "$ReleasePath/$BinaryName.sym" "$DropboxSymbolsPath/$BinaryName/$SymbolsHash/"
echo "Done!"
if [ ! -d "$ReleasePath/deploy" ]; then
mkdir "$ReleasePath/deploy"
fi
if [ ! -d "$ReleasePath/deploy/$AppVersionStrMajor" ]; then
mkdir "$ReleasePath/deploy/$AppVersionStrMajor"
fi
echo "Copying $BinaryName, Updater, TelegramWidgetHelper and $UpdateFile to deploy/$AppVersionStrMajor/$AppVersionStrFull..";
mkdir "$DeployPath"
mkdir "$DeployPath/$BinaryName"
mkdir "$DeployPath/$BinaryName/TelegramHelpers"
mv "$ReleasePath/$BinaryName" "$DeployPath/$BinaryName/"
mv "$ReleasePath/Updater" "$DeployPath/$BinaryName/"
mv "$ReleasePath/TelegramHelpers/TelegramWidgetHelper" "$DeployPath/$BinaryName/TelegramHelpers/"
mv "$ReleasePath/$UpdateFile" "$DeployPath/"
if [ "$AlphaVersion" != "0" ]; then
mv "$ReleasePath/$AlphaKeyFile" "$DeployPath/"
fi
cd "$DeployPath"
tar -cJvf "$SetupFile" "$BinaryName/"
mkdir -p $BackupPath
cp "$SetupFile" "$BackupPath/"
cp "$UpdateFile" "$BackupPath/"
if [ "$AlphaVersion" != "0" ]; then
cp -v "$AlphaKeyFile" "$BackupPath/"
fi
fi
if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "macstore" ]; then
DropboxSymbolsPath="$HOME/Dropbox/Telegram/symbols"
if [ ! -d "$DropboxSymbolsPath" ]; then
Error "Dropbox path not found!"
fi
BackupPath="$HOME/Projects/backup/tdesktop/$AppVersionStrMajor/$AppVersionStrFull"
if [ ! -d "$HOME/Projects/backup/tdesktop" ]; then
Error "Backup path not found!"
fi
if [ "$MacArch" != "" ]; then
cd $ReleasePath
echo "Preparing single $MacArch .app.."
rm -rf $BundleName
cp -R $BinaryName.app $BundleName
python3 "$FullScriptPath/sign_mac.py" --check-layout "$ReleasePath/$BundleName" || Error "Checking the widget helper in $BundleName failed!"
lipo -thin $MacArch $BinaryName.app/Contents/MacOS/$BinaryName -output $BundleName/Contents/MacOS/$BinaryName
lipo -thin $MacArch $BinaryName.app/Contents/Frameworks/Updater -output $BundleName/Contents/Frameworks/Updater
lipo -thin $MacArch $BinaryName.app/Contents/Helpers/crashpad_handler -output $BundleName/Contents/Helpers/crashpad_handler
lipo -thin $MacArch $BinaryName.app/Contents/Helpers/TelegramWidgetHelper -output $BundleName/Contents/Helpers/TelegramWidgetHelper
echo "Done!"
else
if [ "$NotarizeRequestId" == "" ] && [ "$NotarizeRequestIdAMD64" == "" ] && [ "$NotarizeRequestIdARM64" == "" ]; then
if [ -f "$ReleasePath/$BinaryName.app/Contents/Info.plist" ]; then
rm "$ReleasePath/$BinaryName.app/Contents/Info.plist"
fi
if [ -f "$ProjectPath/Telegram/CMakeFiles/Telegram.dir/Info.plist" ]; then
rm "$ProjectPath/Telegram/CMakeFiles/Telegram.dir/Info.plist"
fi
rm -rf "$ReleasePath/$BinaryName.app/Contents/_CodeSignature"
rm -rf "$ReleasePath/Updater"
python3 "$FullScriptPath/build_mac.py" --configuration Release --output "$ReleasePath"
fi
if [ ! -d "$ReleasePath/$BinaryName.app" ]; then
Error "$BinaryName.app not found!"
fi
cd $FullExecPath
if [ "$BuildTarget" == "mac" ]; then
trap 'Error "Interrupted while preparing the single updates!"' HUP INT TERM
echo "Preparing single arm64 update.."
"$FullScriptPath/build.sh" arm64 request_uuid "$NotarizeRequestIdARM64"
echo "Preparing single x86_64 update.."
"$FullScriptPath/build.sh" x86_64 request_uuid "$NotarizeRequestIdAMD64"
trap - HUP INT TERM
echo "Done."
fi
cd $ReleasePath
fi
if [ "$NotarizeRequestId" == "" ] || [ "$NotarizeRequestId" == "go" ]; then
if [ "$BuildTarget" == "mac" ]; then
if [ ! -f "$ReleasePath/$BundleName/Contents/Frameworks/Updater" ]; then
Error "Updater not found!"
fi
if [ ! -f "$ReleasePath/$BundleName/Contents/Helpers/crashpad_handler" ]; then
Error "crashpad_handler not found!"
fi
if [ ! -f "$ReleasePath/$BundleName/Contents/Helpers/TelegramWidgetHelper" ]; then
Error "TelegramWidgetHelper not found!"
fi
fi
if [ "$BuildTarget" == "macstore" ]; then
if [ ! -d "$ReleasePath/$BundleName/Contents/Frameworks/Breakpad.framework" ]; then
Error "Breakpad.framework not found!"
fi
if [ ! -f "$ReleasePath/$BundleName/Contents/XPCServices/TelegramWidgetHelper.xpc/Contents/MacOS/TelegramWidgetHelper" ]; then
Error "TelegramWidgetHelper.xpc not found!"
fi
fi
if [ "$MacArch" == "" ]; then
echo "Dumping debug symbols x86_64 from universal.."
"$HomePath/../../Libraries/breakpad/src/tools/mac/dump_syms/build/Release/dump_syms" "-a" "x86_64" "$ReleasePath/$BinaryName.app/Contents/MacOS/$BinaryName" > "$ReleasePath/$BinaryName.x86_64.sym" 2>/dev/null
echo "Done!"
SymbolsHash=`head -n 1 "$ReleasePath/$BinaryName.x86_64.sym" | awk -F " " 'END {print $4}'`
echo "Copying $BinaryName.x86_64.sym to $DropboxSymbolsPath/$BinaryName/$SymbolsHash"
mkdir -p "$DropboxSymbolsPath/$BinaryName/$SymbolsHash"
cp "$ReleasePath/$BinaryName.x86_64.sym" "$DropboxSymbolsPath/$BinaryName/$SymbolsHash/$BinaryName.sym"
echo "Done!"
echo "Dumping debug symbols arm64 from universal.."
"$HomePath/../../Libraries/breakpad/src/tools/mac/dump_syms/build/Release/dump_syms" "-a" "arm64" "$ReleasePath/$BinaryName.app/Contents/MacOS/$BinaryName" > "$ReleasePath/$BinaryName.arm64.sym" 2>/dev/null
echo "Done!"
SymbolsHash=`head -n 1 "$ReleasePath/$BinaryName.arm64.sym" | awk -F " " 'END {print $4}'`
echo "Copying $BinaryName.arm64.sym to $DropboxSymbolsPath/$BinaryName/$SymbolsHash"
mkdir -p "$DropboxSymbolsPath/$BinaryName/$SymbolsHash"
cp "$ReleasePath/$BinaryName.arm64.sym" "$DropboxSymbolsPath/$BinaryName/$SymbolsHash/$BinaryName.sym"
echo "Done!"
fi
echo "Stripping the executable.."
strip "$ReleasePath/$BundleName/Contents/MacOS/$BinaryName"
if [ "$BuildTarget" == "mac" ]; then
strip "$ReleasePath/$BundleName/Contents/Frameworks/Updater"
strip "$ReleasePath/$BundleName/Contents/Helpers/crashpad_handler"
strip "$ReleasePath/$BundleName/Contents/Helpers/TelegramWidgetHelper"
fi
echo "Done!"
echo "Signing the application.."
if [ "$BuildTarget" == "mac" ]; then
python3 "$FullScriptPath/sign_mac.py" --identity "Developer ID Application: Telegram FZ-LLC (C67CF9S4VU)" --entitlements "$HomePath/Telegram/Telegram.entitlements" --timestamp --runtime "$ReleasePath/$BundleName"
elif [ "$BuildTarget" == "macstore" ]; then
codesign --force --timestamp --options runtime --sign "3rd Party Mac Developer Application: Telegram FZ-LLC (C67CF9S4VU)" "$ReleasePath/$BundleName/Contents/Frameworks/Breakpad.framework/Versions/A/Resources/breakpadUtilities.dylib" --entitlements "$HomePath/Telegram/Breakpad.entitlements"
python3 "$FullScriptPath/sign_mac.py" --identity "3rd Party Mac Developer Application: Telegram FZ-LLC (C67CF9S4VU)" --entitlements "$HomePath/Telegram/Telegram Lite.entitlements" --timestamp --runtime "$ReleasePath/$BundleName"
echo "Making an installer.."
productbuild --sign "3rd Party Mac Developer Installer: Telegram FZ-LLC (C67CF9S4VU)" --component "$ReleasePath/$BundleName" /Applications "$ReleasePath/$BinaryName.pkg"
fi
echo "Done!"
if [ ! -f "$ReleasePath/$BundleName/Contents/Resources/Icon.icns" ]; then
Error "Icon.icns not found in Resources!"
fi
if [ ! -f "$ReleasePath/$BundleName/Contents/MacOS/$BinaryName" ]; then
Error "$BinaryName not found in MacOS!"
fi
if [ ! -d "$ReleasePath/$BundleName/Contents/_CodeSignature" ]; then
Error "$BinaryName signature not found!"
fi
if [ "$BuildTarget" == "macstore" ]; then
if [ ! -f "$ReleasePath/$BinaryName.pkg" ]; then
Error "$BinaryName.pkg not found!"
fi
fi
fi
if [ "$BuildTarget" == "mac" ]; then
cd "$ReleasePath"
if [ "$NotarizeRequestId" == "" ] || [ "$NotarizeRequestId" == "go" ]; then
if [ "$AlphaVersion" == "0" ]; then
cp -f tsetup_template.dmg tsetup.temp.dmg
until TempDiskPath=`hdiutil attach -nobrowse -noautoopenrw -readwrite tsetup.temp.dmg | awk -F "\t" 'END {print $3}'` && [ "$TempDiskPath" != "" ]; do
echo "Attaching tsetup.temp.dmg failed, retrying in 3 seconds.."
sleep 3
done
cp -R "./$BundleName" "$TempDiskPath/"
rm -f "$TempDiskPath/$BundleName/Contents/Resources/AppIcon.icns"
bless --folder "$TempDiskPath/"
until hdiutil detach "$TempDiskPath"; do
echo "Detaching $TempDiskPath failed, retrying in 3 seconds.."
sleep 3
done
until hdiutil convert tsetup.temp.dmg -format UDBZ -ov -o "$SetupFile"; do
echo "Converting tsetup.temp.dmg failed, retrying in 3 seconds.."
sleep 3
done
rm tsetup.temp.dmg
fi
fi
if [ "$AlphaVersion" != "0" ]; then
cd $ReleasePath
"./Packer" -path "$BundleName" -target "$BuildTarget" -version $VersionForPacker $AlphaBetaParam -alphakey
if [ ! -f "$AlphaKeyFile" ]; then
Error "Alpha version key file not found!"
fi
while IFS='' read -r line || [[ -n "$line" ]]; do
AlphaSignature="$line"
done < "$ReleasePath/$AlphaKeyFile"
UpdateFile="${UpdateFile}_${AlphaSignature}"
UpdateFileAMD64="${UpdateFileAMD64}_${AlphaSignature}"
UpdateFileARM64="${UpdateFileARM64}_${AlphaSignature}"
if [ "$MacArch" != "" ]; then
SetupFile="talpha${AlphaVersion}_${MacArch}_${AlphaSignature}.zip"
else
SetupFile="talpha${AlphaVersion}_${AlphaSignature}.zip"
fi
if [ "$NotarizeRequestId" == "" ] || [ "$NotarizeRequestId" == "go" ]; then
rm -rf "$ReleasePath/AlphaTemp"
mkdir "$ReleasePath/AlphaTemp"
mkdir "$ReleasePath/AlphaTemp/$BinaryName"
cp -r "$ReleasePath/$BundleName" "$ReleasePath/AlphaTemp/$BinaryName/"
cd "$ReleasePath/AlphaTemp"
zip -r "$SetupFile" "$BinaryName"
mv "$SetupFile" "$ReleasePath/"
cd "$ReleasePath"
fi
fi
if [ "$NotarizeRequestId" != "" ] && [ "$NotarizeRequestId" != "go" ]; then
CheckWidgetHelper "$ReleasePath/$BundleName" || Error "Checking the widget helper in $BundleName failed!"
if [ ! -f "$ReleasePath/$SetupFile" ] || [ ! -r "$ReleasePath/$SetupFile" ]; then
Error "$SetupFile not found or not readable!"
fi
trap 'Error "Interrupted while checking $SetupFile!"' HUP INT TERM
if ! (
Result=0
trap 'Result=1' HUP INT TERM
InOwnGroup() {
python3 -c 'import os, sys; os.setpgrp(); os.execvp(sys.argv[1], sys.argv[1:])' "$@" < /dev/null > /dev/null
}
CheckPath=`mktemp -d -t tdesktop-check` || exit 1
if [ $Result == 0 ] && InOwnGroup hdiutil attach -readonly -nobrowse -noautoopen -mountpoint "$CheckPath" "$ReleasePath/$SetupFile"; then
if [ $Result == 0 ] && [ -L "$CheckPath/$BundleName" ]; then
echo "$BundleName in $SetupFile is a link!"
Result=1
elif [ $Result == 0 ] && ! CheckWidgetHelper "$CheckPath/$BundleName"; then
Result=1
fi
else
Result=1
fi
if [ "$(stat -f %d "$CheckPath")" != "$(stat -f %d "$CheckPath/..")" ]; then
InOwnGroup hdiutil detach "$CheckPath" || InOwnGroup hdiutil detach -force "$CheckPath" || Result=1
fi
rmdir "$CheckPath" || Result=1
exit $Result
); then
Error "Checking the widget helper in $SetupFile failed!"
fi
trap - HUP INT TERM
fi
echo "Beginning notarization process."
xcrun notarytool submit "$SetupFile" --keychain-profile "preston" --wait
xcrun stapler staple "$ReleasePath/$BundleName"
if [ "$MacArch" == "" ] && [ "$AlphaVersion" != "0" ]; then
rm -rf "$ReleasePath/AlphaTemp"
mkdir "$ReleasePath/AlphaTemp"
mkdir "$ReleasePath/AlphaTemp/$BinaryName"
cp -r "$ReleasePath/$BinaryName.app" "$ReleasePath/AlphaTemp/$BinaryName/"
cd "$ReleasePath/AlphaTemp"
zip -r "$SetupFile" "$BinaryName"
mv "$SetupFile" "$ReleasePath/"
cd "$ReleasePath"
echo "Alpha archive re-created."
elif [ "$MacArch" == "" ]; then
xcrun stapler staple "$ReleasePath/$SetupFile"
fi
if [ "$MacArch" != "" ]; then
UpdatePackPath="$ReleasePath/update_pack_${MacArch}"
rm -rf "$UpdatePackPath"
mkdir "$UpdatePackPath"
mv "$ReleasePath/$BundleName" "$UpdatePackPath/$BinaryName.app"
cp "$ReleasePath/Packer" "$UpdatePackPath/"
cd "$UpdatePackPath"
PackUpdate -path "$BinaryName.app" -target "$BuildTarget" -arch $MacArch
echo "Packer done!"
mv "$UpdateFile" "$ReleasePath/"
cd "$ReleasePath"
rm -rf "$UpdatePackPath"
rm "$ReleasePath/$SetupFile"
echo "Setup file $SetupFile removed."
exit
fi
FinalPolicy=`PolicyDigest` || Error "TelegramWidgetHelperDirect.entitlements could not be read!"
if [ "$FinalPolicy" != "$ParentPolicy" ]; then
Error "TelegramWidgetHelperDirect.entitlements changed during the build!"
fi
fi
if [ ! -d "$ReleasePath/deploy" ]; then
mkdir "$ReleasePath/deploy"
fi
if [ ! -d "$ReleasePath/deploy/$AppVersionStrMajor" ]; then
mkdir "$ReleasePath/deploy/$AppVersionStrMajor"
fi
if [ "$BuildTarget" == "mac" ]; then
echo "Copying $BinaryName.app, $UpdateFileAMD64 and $UpdateFileARM64 to deploy/$AppVersionStrMajor/$AppVersionStr..";
mkdir "$DeployPath"
mkdir "$DeployPath/$BinaryName"
cp -r "$ReleasePath/$BinaryName.app" "$DeployPath/$BinaryName/"
if [ "$AlphaVersion" != "0" ]; then
mv "$ReleasePath/$AlphaKeyFile" "$DeployPath/"
fi
rm "$ReleasePath/$BinaryName.app/Contents/MacOS/$BinaryName"
rm "$ReleasePath/$BinaryName.app/Contents/Frameworks/Updater"
mv "$ReleasePath/$UpdateFileAMD64" "$DeployPath/"
mv "$ReleasePath/$UpdateFileARM64" "$DeployPath/"
mv "$ReleasePath/$SetupFile" "$DeployPath/"
if [ "$BuildTarget" == "mac" ]; then
mkdir -p "$BackupPath/$BackupFolder"
cp "$DeployPath/$UpdateFileAMD64" "$BackupPath/$BackupFolder/"
cp "$DeployPath/$UpdateFileARM64" "$BackupPath/$BackupFolder/"
cp "$DeployPath/$SetupFile" "$BackupPath/$BackupFolder/"
if [ "$AlphaVersion" != "0" ]; then
cp -v "$DeployPath/$AlphaKeyFile" "$BackupPath/$BackupFolder/"
fi
fi
elif [ "$BuildTarget" == "macstore" ]; then
echo "Copying $BinaryName.app to deploy/$AppVersionStrMajor/$AppVersionStr..";
mkdir "$DeployPath"
cp -r "$ReleasePath/$BinaryName.app" "$DeployPath/"
mv "$ReleasePath/$BinaryName.pkg" "$DeployPath/"
rm "$ReleasePath/$BinaryName.app/Contents/MacOS/$BinaryName"
fi
fi
echo "Version $AppVersionStrFull is ready!";
echo -en "\007";
sleep 1;
echo -en "\007";
sleep 1;
echo -en "\007";