Skip to content

Commit 40432dc

Browse files
authored
Merge pull request brave#13033 from brave/fix/13032
macOS: sign pkg installer
2 parents 8e796ee + b13b275 commit 40432dc

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

tools/buildInstaller.js

+37-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ var VersionInfo = require('./lib/versionInfo')
22
var execute = require('./lib/execute')
33
var format = require('util').format
44
var path = require('path')
5+
var fs = require('fs')
6+
7+
const fileExists = (path) => new Promise((resolve, reject) => fs.access(path, (err, exists) => {
8+
resolve(!err)
9+
}))
10+
const execPromise = (cmd) => new Promise((resolve, reject) => {
11+
execute(cmd, {}, err => {
12+
if (err) return reject(err)
13+
resolve()
14+
})
15+
})
516

617
const isWindows = process.platform === 'win32'
718
const isDarwin = process.platform === 'darwin'
@@ -105,27 +116,48 @@ if (isDarwin) {
105116
'python tools/signature_generator.py --input_file "' + wvBundle + '" --output_file "' + wvBundleSig + '" --flag 1',
106117
'python tools/signature_generator.py --input_file "' + wvPlugin + '"',
107118

108-
// Sign it
119+
// Sign it (requires Apple 'Developer ID Application' certificate installed in keychain)
109120
'cd ' + buildDir + `/${appName}.app/Contents/Frameworks`,
110121
'codesign --deep --force --strict --verbose --sign $IDENTIFIER *',
111122
'cd ../../..',
112123
`codesign --deep --force --strict --verbose --sign $IDENTIFIER ${appName}.app/`,
113124

114-
// Package it into a dmg or package
125+
// Package it into a dmg and/or package
115126
'cd ..',
116127
'build ' +
117-
'--prepackaged="' + buildDir + `/${appName}.app" ` +
118-
` --config=res/${channel}/builderConfig.json `,
128+
`--prepackaged="${buildDir}/${appName}.app" ` +
129+
`--config=res/${channel}/builderConfig.json `,
119130

120131
// Create an update zip
121132
'ditto -c -k --sequesterRsrc --keepParent ' + buildDir + `/${appName}.app dist/${appName}-` + VersionInfo.braveVersion + '.zip'
122133
]
123-
execute(cmds, {}, (err) => {
134+
execute(cmds, {}, async (err) => {
124135
if (err) {
125136
raiseError('building installer failed: ' + JSON.stringify(err))
126137
return
127138
}
128139

140+
// sign pkg if it exists (requires Apple 'Developer ID Installer' certificate installed in keychain)
141+
const fileName = `${appName}-${VersionInfo.braveVersion}`
142+
const packagePath = path.join(outDir, `${fileName}.pkg`)
143+
const packagePathUnsigned = path.join(outDir, `${fileName}_unsigned.pkg`)
144+
145+
const pkgExists = await fileExists(packagePath)
146+
if (pkgExists) {
147+
console.log(`Signing pkg at ${packagePath}`)
148+
try {
149+
await execPromise([
150+
`mv ${packagePath} ${packagePathUnsigned}`,
151+
`productsign --sign ${identifier} ${packagePathUnsigned} ${packagePath}`,
152+
`rm ${packagePathUnsigned}`
153+
])
154+
console.log(`pkg signing complete`)
155+
} catch (e) {
156+
console.error('Error signing pkg:')
157+
raiseError(e)
158+
return
159+
}
160+
}
129161
console.log('done')
130162
})
131163
} else if (isWindows) {

0 commit comments

Comments
 (0)