Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit 7cb4f5d

Browse files
committed
Finish macOS automated install
Fixes brave/brave-browser#1541 Fixes brave/brave-browser#1543
1 parent 4f150cc commit 7cb4f5d

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

app/darwinInit.js

+36-30
Original file line numberDiff line numberDiff line change
@@ -29,74 +29,80 @@ const getBraveCoreInstallerPath = () => {
2929
}
3030

3131
function InstallBraveCore () {
32-
// TODO(bsclifton): uncomment
33-
// const fs = require('fs')
32+
const fs = require('fs')
3433
const homedir = os.homedir()
35-
36-
console.log('InstallBraveCore START')
37-
38-
// expected install paths
34+
const appName = 'Brave Browser.app'
3935
const braveCoreInstallLocations = [
40-
`${homedir}/Applications/Brave Browser.app/`,
41-
'/Applications/Brave Browser.app/'
36+
`${homedir}/Applications/${appName}/`,
37+
`/Applications/${appName}/`
4238
]
4339

40+
console.log('InstallBraveCore\n----------------')
41+
4442
// check for existing installations
4543
for (var i = 0; i < braveCoreInstallLocations.length; i++) {
46-
// console.log(`BSC]] checking ${braveCoreInstallLocations[i]}`)
47-
// if (fs.existsSync(braveCoreInstallLocations[i])) {
48-
// console.log(`BSC]] already installed at "${braveCoreInstallLocations[i]}"`)
49-
// return false
50-
// }
44+
if (fs.existsSync(braveCoreInstallLocations[i])) {
45+
console.log(`brave-core already installed at "${braveCoreInstallLocations[i]}"`)
46+
return false
47+
}
5148
}
5249

53-
// TODO(bsclifton): change back to const
54-
let installerPath = getBraveCoreInstallerPath()
50+
// get path to the bundled brave-core binary
51+
const installerPath = getBraveCoreInstallerPath()
5552
if (!installerPath) {
5653
return false
5754
}
58-
const tempDir = path.join(os.tmpdir(), 'brave-upgrade')
59-
60-
// TODO(bsclifton): BSC- REMOVE ME - START
61-
let cwd = execSync('pwd').toString().trim()
62-
installerPath = path.join(cwd, 'res', 'Brave-Browser-0.55.20.pkg')
63-
// TODO(bsclifton): BSC- REMOVE ME - END
6455

6556
// brave-core is not installed; go ahead with silent install
57+
const tempDir = path.join(os.tmpdir(), 'brave-upgrade')
6658
try {
6759
console.log(`Extracting brave-core binaries from "${installerPath}" into temp directory "${tempDir}"`)
6860
execSync(`pkgutil --expand-full "${installerPath}" "${tempDir}"`)
6961

7062
let installedPath = '/Applications'
7163
try {
7264
console.log(`Attempting to move extracted brave-core binaries into "${installedPath}/."`)
73-
execSync(`mv "${tempDir}/Payload/Brave Browser.app/" "${installedPath}/."`)
65+
execSync(`mv "${tempDir}/Payload/${appName}/" "${installedPath}/."`)
7466
} catch (globalPathException) {
7567
installedPath = `${homedir}/Applications`
7668
console.log(`Attempting to move extracted brave-core binaries into "${installedPath}/."`)
77-
execSync(`mv "${tempDir}/Payload/Brave Browser.app/" "${installedPath}/."`)
69+
execSync(`mv "${tempDir}/Payload/${appName}/" "${installedPath}/."`)
7870
}
7971

80-
// TODO(bsclifton): set permissions
81-
// drwxr-xr-x@ 3 clifton admin 96B Oct 18 09:46 Brave Browser.app
72+
// match expected permissions
73+
// logic borrowed from ./build/pkg-scripts/postinstall
74+
[
75+
`chmod -R 775 "${installedPath}/${appName}"`,
76+
`chown -R $USER "${installedPath}/${appName}"`,
77+
`chgrp -R admin "${installedPath}/${appName}"`
78+
].forEach((cmd) => {
79+
try {
80+
execSync(cmd)
81+
} catch (e) {
82+
console.log(`Failed adjusting permissions with "${cmd}"\nerror: "${e.toString()}"`)
83+
}
84+
})
8285

8386
console.log('Launching brave-core')
84-
execSync(`open -a "${installedPath}/Brave Browser.app/"`)
87+
execSync(`open -a "${installedPath}/${appName}/" --args --upgrade-from-muon`)
8588
} catch (e) {
8689
return false
8790
} finally {
8891
console.log(`Removing temp directory "${tempDir}"`)
8992
try {
9093
execSync(`rm -rf ${tempDir}`)
9194
} catch (e) {}
92-
console.log('InstallBraveCore END')
9395
}
9496

9597
return true
9698
}
9799

98-
// TODO(bsclifton): only execute if updating?
99100
if (InstallBraveCore()) {
100-
console.log('BSC]] install complete')
101+
console.log('brave-core installed\n----------------')
102+
// relaunch and append argument expected in:
103+
// https://github.com/brave/brave-browser/issues/1545
104+
app.exit()
105+
} else {
106+
// in this case, browser-laptop will launch as usual
107+
console.log('brave-core not installed\n----------------')
101108
}
102-
app.exit()

0 commit comments

Comments
 (0)