Skip to content
This repository was archived by the owner on Sep 25, 2018. It is now read-only.

Commit

Permalink
Remove outdated package 'runas'
Browse files Browse the repository at this point in the history
The 'runas` package is no longer maintained and it depends on a deprecated macOS
API `AuthorizationExecuteWithPrivileges`, which doesn't seem to be available on
latest macOS versions.

Replace it with sudo-prompt, which executes the commands with sudo.

fbshipit-source-id: b0eeb46
  • Loading branch information
fson authored and expbot committed Mar 9, 2018
1 parent 3853eeb commit 933e6cd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 47 deletions.
3 changes: 2 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@
"redux-actions": "^0.12.0",
"redux-logger": "^2.7.0",
"redux-thunk": "^2.1.0",
"runas": "^3.1.1",
"source-map-support": "^0.4.6",
"sudo-prompt": "^8.1.0",
"tree-kill": "^1.1.0",
"util.promisify": "^1.0.0",
"xdl": "47.0.4"
}
}
72 changes: 26 additions & 46 deletions src/utils/binaries.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
import fs from 'fs';
import mkdirp from 'mkdirp';
import path from 'path';
import promisify from 'util.promisify';
import spawnAsync from '@expo/spawn-async';
import sudo from 'sudo-prompt';

import { Binaries, ErrorCode, Logger, NotificationCode, UserSettings, Utils, XDLError } from 'xdl';
let runas = null; // defer until used

const sudoAsync = promisify(sudo.exec);
const sudoOptions = {
name: 'Expo XDE',
};
const INSTALL_PATH = '/usr/local/bin';

export async function installShellCommandsAsync() {
if (process.platform !== 'darwin') {
throw new XDLError(ErrorCode.PLATFORM_NOT_SUPPORTED, 'Platform not supported.');
}

await Binaries.sourceBashLoginScriptsAsync();
await _copyBinariesToExpoDirAsync();

let binaries = ['adb', 'watchman', 'xde'];
let installedBinaries = [];
let commands = [];
for (let i = 0; i < binaries.length; i++) {
if (await _installBinaryAsync(binaries[i])) {
installedBinaries.push(binaries[i]);
let name = binaries[i];
if (!await _binaryInstalledAsync(name) && !await _binaryExistsAsync(name)) {
installedBinaries.push(name);
commands.push(
`rm -f ${path.join(INSTALL_PATH, name)};`,
`mkdir -p ${INSTALL_PATH};`,
`ln -s ${path.join(_expoBinaryDirectory(), name, name)} ${path.join(INSTALL_PATH, name)};`
);
}
}

Expand All @@ -25,61 +41,25 @@ export async function installShellCommandsAsync() {
{ code: NotificationCode.INSTALL_SHELL_COMMANDS_RESULT },
`Shell commands ${binaries.join(', ')} are already installed`
);
} else {
Logger.notifications.info(
{ code: NotificationCode.INSTALL_SHELL_COMMANDS_RESULT },
`Installed ${installedBinaries.join(', ')} to your shell`
);
}
}

// Only called on darwin
async function _installBinaryAsync(name) {
if ((await _binaryInstalledAsync(name)) || (await _binaryExistsAsync(name))) {
return false;
return;
}

try {
if (!runas) {
runas = require('runas');
}

// adb lives at ~/.expo/adb/adb
try {
runas('/bin/rm', ['-f', path.join(INSTALL_PATH, name)], { admin: true });
} catch (e) {
// Don't worry if we can't rm the file, we'll just get an error later
}

if (runas('/bin/mkdir', ['-p', INSTALL_PATH], { admin: true }) !== 0) {
throw new Error(`Could not run \`mkdir -p ${INSTALL_PATH}\`.`);
}

if (
runas(
'/bin/ln',
['-s', path.join(_expoBinaryDirectory(), name, name), path.join(INSTALL_PATH, name)],
{ admin: true }
) !== 0
) {
throw new Error(`Could not symlink \`${name}\`.`);
}

return true;
await sudoAsync(commands.join('\n'), sudoOptions);
} catch (e) {
Logger.notifications.error(
{ code: NotificationCode.INSTALL_SHELL_COMMANDS_RESULT },
`Error installing ${name}: ${e.message}`
'Error installing shell commands'
);
throw e;
}
Logger.notifications.info(
{ code: NotificationCode.INSTALL_SHELL_COMMANDS_RESULT },
`Installed ${installedBinaries.join(', ')} to your shell`
);
}

async function _copyBinariesToExpoDirAsync() {
if (process.platform !== 'darwin') {
throw new XDLError(ErrorCode.PLATFORM_NOT_SUPPORTED, 'Platform not supported.');
}

await Utils.ncpAsync(Binaries.OSX_SOURCE_PATH, _expoBinaryDirectory());
}

Expand Down

0 comments on commit 933e6cd

Please sign in to comment.