@@ -29,74 +29,80 @@ const getBraveCoreInstallerPath = () => {
29
29
}
30
30
31
31
function InstallBraveCore ( ) {
32
- // TODO(bsclifton): uncomment
33
- // const fs = require('fs')
32
+ const fs = require ( 'fs' )
34
33
const homedir = os . homedir ( )
35
-
36
- console . log ( 'InstallBraveCore START' )
37
-
38
- // expected install paths
34
+ const appName = 'Brave Browser.app'
39
35
const braveCoreInstallLocations = [
40
- `${ homedir } /Applications/Brave Browser.app /` ,
41
- ' /Applications/Brave Browser.app/'
36
+ `${ homedir } /Applications/${ appName } /` ,
37
+ ` /Applications/${ appName } /`
42
38
]
43
39
40
+ console . log ( 'InstallBraveCore\n----------------' )
41
+
44
42
// check for existing installations
45
43
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
+ }
51
48
}
52
49
53
- // TODO(bsclifton): change back to const
54
- let installerPath = getBraveCoreInstallerPath ( )
50
+ // get path to the bundled brave-core binary
51
+ const installerPath = getBraveCoreInstallerPath ( )
55
52
if ( ! installerPath ) {
56
53
return false
57
54
}
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
64
55
65
56
// brave-core is not installed; go ahead with silent install
57
+ const tempDir = path . join ( os . tmpdir ( ) , 'brave-upgrade' )
66
58
try {
67
59
console . log ( `Extracting brave-core binaries from "${ installerPath } " into temp directory "${ tempDir } "` )
68
60
execSync ( `pkgutil --expand-full "${ installerPath } " "${ tempDir } "` )
69
61
70
62
let installedPath = '/Applications'
71
63
try {
72
64
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 } /."` )
74
66
} catch ( globalPathException ) {
75
67
installedPath = `${ homedir } /Applications`
76
68
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 } /."` )
78
70
}
79
71
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
+ } )
82
85
83
86
console . log ( 'Launching brave-core' )
84
- execSync ( `open -a "${ installedPath } /Brave Browser.app/" ` )
87
+ execSync ( `open -a "${ installedPath } /${ appName } /" --args --upgrade-from-muon ` )
85
88
} catch ( e ) {
86
89
return false
87
90
} finally {
88
91
console . log ( `Removing temp directory "${ tempDir } "` )
89
92
try {
90
93
execSync ( `rm -rf ${ tempDir } ` )
91
94
} catch ( e ) { }
92
- console . log ( 'InstallBraveCore END' )
93
95
}
94
96
95
97
return true
96
98
}
97
99
98
- // TODO(bsclifton): only execute if updating?
99
100
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----------------' )
101
108
}
102
- app . exit ( )
0 commit comments