Files
brave-core/build/mac/create_pkg_install_scripts.py
T
Emerick Rogul 3f7d98d11f [cr146] Mac pkg now has a preinstall script
We already supported the postinstall script. This just adds support for the new
preinstall script.

Chromium changes:
https://chromium.googlesource.com/chromium/src/+/020f74a05f2bfde21ea239cea02e53671c6ae506

commit 020f74a05f2bfde21ea239cea02e53671c6ae506
Author: Avi Drissman <avi@chromium.org>
Date:   Fri Feb 6 10:54:22 2026 -0800

    Harden the pkg with a pre-install script

    If Installer.app finds an app with the correct name but an incorrect
    bundle ID in the target installation directory, it misbehaves. Add a
    pre-install script to the pkg to fail early if that is the case.

    Fixed: 481590122
    Change-Id: I47017e17d1506e0e0a17083842d3e4201710e127
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7544462
    Reviewed-by: Mark Mentovai <mark@chromium.org>
    Commit-Queue: Mark Mentovai <mark@chromium.org>
    Auto-Submit: Avi Drissman <avi@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#1580983}
2026-02-26 14:14:54 +00:00

71 lines
2.0 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright (c) 2026 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.
from argparse import ArgumentParser
from os import makedirs, chmod
from os.path import dirname
import os
import re
import stat
def main():
args = parse_args()
with open(args.install_template_path) as f:
script = f.read()
replacements = {
'@APP_DIR@': args.app_dir_name,
'@APP_PRODUCT@': '',
'@BRAND_CODE@': '',
'@BUNDLE_ID@': args.bundle_identifier,
'@FRAMEWORK_DIR@': args.app_dir_name + '/' +
args.framework_dir_in_app_dir,
'@SHEBANG_GUARD@': '',
'GoogleUpdater': 'BraveUpdater',
'KSProductID': 'CFBundleIdentifier',
'KSVersion': 'CFBundleShortVersionString',
'/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/'
'Contents/MacOS/ksadmin': '/Library/Application Support/BraveSoftware'
'/BraveUpdater/Current/BraveUpdater.app/'
'Contents/Helpers/BraveSoftwareUpdate.bundle/'
'Contents/Helpers/ksadmin'
}
for key, value in replacements.items():
assert key in script, key
script = script.replace(key, value)
m = re.search(r'@[^@\n]+@', script)
assert not m, 'Unexpected placeholder: ' + m.group(0)
makedirs(dirname(args.out_file), exist_ok=True)
with open(args.out_file, 'w') as f:
f.write(script)
make_executable(args.out_file)
def parse_args():
parser = ArgumentParser()
parser.add_argument('install_template_path')
parser.add_argument('app_dir_name')
parser.add_argument('framework_dir_in_app_dir')
parser.add_argument('bundle_identifier')
parser.add_argument('out_file')
return parser.parse_args()
def make_executable(file_path):
chmod(file_path, os.stat(file_path).st_mode | stat.S_IEXEC)
if __name__ == '__main__':
main()