-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d13c8e
commit 3d70d78
Showing
6 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env osascript -l JavaScript | ||
|
||
/* eslint-disable */ | ||
|
||
ObjC.import('stdlib') | ||
|
||
const app = Application.currentApplication() | ||
app.includeStandardAdditions = true | ||
|
||
const result = app.displayDialog('Space wants to install OSX FUSE and needs privilege access. Enter your password to allow this.', { | ||
defaultAnswer: '', | ||
withIcon: 'note', | ||
buttons: ['Cancel', 'Install OSX FUSE'], | ||
defaultButton: 'Install OSX FUSE', | ||
hiddenAnswer: true, | ||
}) | ||
|
||
if (result.buttonReturned === 'Install OSX FUSE') { | ||
result.textReturned | ||
} else { | ||
$.exit(255) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
const path = require('path'); | ||
const chalk = require('chalk'); | ||
const get = require('lodash/get'); | ||
const { spawn } = require('child_process'); | ||
|
||
const installerName = 'Space FUSE Installer'; | ||
|
||
class FuseInstallerProcess { | ||
constructor() { | ||
this.childProcess = null; | ||
this.handlers = { | ||
ready: [], | ||
failed: [], | ||
pending: [], | ||
}; | ||
} | ||
|
||
on(key, handler) { | ||
const accHandlers = get(this.handlers, key, []) || []; | ||
|
||
this.handlers = { | ||
...this.handlers, | ||
[key]: [ | ||
...accHandlers, | ||
handler, | ||
], | ||
}; | ||
} | ||
|
||
callHandlers(key, args) { | ||
this.handlers[key].forEach((handler) => handler(args)); | ||
} | ||
|
||
start(isDev) { | ||
if (this.childProcess) return; | ||
|
||
if (process.platform !== 'darwin') { | ||
return; | ||
} | ||
|
||
let installerPath = path.join(process.resourcesPath, 'FuseInstaller.pkg'); | ||
if (isDev) { | ||
installerPath = path.join(__dirname, '../../../resources/FuseInstaller.pkg'); | ||
} | ||
|
||
this.childProcess = spawn('sudo', ['-A', 'installer', '-pkg', installerPath, '-target', '/'], { | ||
env: { | ||
PATH: process.env.PATH, | ||
SUDO_ASKPASS: path.join(__dirname, 'askpass.osascript.js'), | ||
}, | ||
}); | ||
this.childProcess.stdout.on('data', (data) => { | ||
const outputLog = data.toString().toLowerCase(); | ||
|
||
// eslint-disable-next-line no-console | ||
console.log(chalk.blue(outputLog)); | ||
|
||
if (outputLog.includes('The install was successful') || outputLog.includes('The upgrade was successful')) { | ||
this.callHandlers('success'); | ||
} | ||
}); | ||
|
||
this.childProcess.stderr.on('data', (data) => { | ||
// eslint-disable-next-line no-console | ||
console.error(chalk.red(data)); | ||
this.callHandlers('error'); | ||
}); | ||
|
||
this.childProcess.on('close', () => { | ||
console.log(chalk.blue(`${installerName} finished`)); | ||
this.stop(); | ||
}); | ||
|
||
this.callHandlers('pending'); | ||
} | ||
|
||
stop() { | ||
if (this.childProcess) { | ||
this.childProcess.kill(); | ||
this.childProcess = null; | ||
} | ||
} | ||
} | ||
|
||
module.exports = FuseInstallerProcess; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* eslint-disable no-console */ | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const axios = require('axios'); | ||
const ProgressBar = require('progress'); | ||
|
||
async function getInstaller() { | ||
const { cwd, platform } = process; | ||
if (platform !== 'darwin') { | ||
return | ||
} | ||
|
||
const resourcesPath = path.resolve(cwd(), 'resources'); | ||
|
||
const fusePkgUrl = `https://space-fuse-asset.s3-us-west-2.amazonaws.com/FUSE+for+macOS+3.11.0.pkg`; | ||
const { data, headers } = await axios({ | ||
method: 'GET', | ||
responseType: 'stream', | ||
url: fusePkgUrl, | ||
}).catch((error) => { | ||
console.error(`\nError when trying to download the package: ${fusePkgUrl}`); | ||
console.error(`Error : ${error.stack || error.message}`); | ||
process.exit(1); | ||
}); | ||
|
||
const totalLength = headers['content-length']; | ||
|
||
console.log(`Downloading Osx Fuse from ${fusePkgUrl}:`); | ||
const progressBar = new ProgressBar(`File: FUSE+for+macOS+3.11.0.pkg [:bar] :percent :etas`, { | ||
width: 40, | ||
complete: '=', | ||
incomplete: ' ', | ||
renderThrottle: 1, | ||
total: parseInt(totalLength, 10), | ||
}); | ||
|
||
if (!fs.existsSync(resourcesPath)) { | ||
fs.mkdirSync(resourcesPath); | ||
} | ||
// save to ./resources/ | ||
const writer = fs.createWriteStream(path.join(resourcesPath, `FuseInstaller.pkg`), { mode: 0o755 }); | ||
|
||
data.on('data', (chunk) => ( | ||
progressBar.tick(chunk.length) | ||
)); | ||
|
||
data.on('error', (error) => { | ||
data.destroy(); | ||
writer.destroy(); | ||
|
||
console.error(`\nError when downloading the Fuse installer binary: ${error.stack || error.message}`); | ||
process.exit(1); | ||
}); | ||
|
||
writer.on('finish', async () => { | ||
process.exit(0); | ||
}); | ||
|
||
writer.on('error', (error) => { | ||
writer.destroy(); | ||
|
||
console.error(`\nError when saving the Fuse installer: ${error.stack || error.message}`); | ||
process.exit(1); | ||
}); | ||
|
||
data.pipe(writer); | ||
} | ||
|
||
getInstaller(); |