Skip to content

Commit

Permalink
Merge pull request #497 from prey/node-update-for-mac
Browse files Browse the repository at this point in the history
Update node version and sqlite3 library on macOS
  • Loading branch information
javo authored Jun 8, 2021
2 parents 820ce2e + 3896a12 commit 400ec61
Show file tree
Hide file tree
Showing 9 changed files with 387 additions and 190 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
os: osx
node_js:
- 10.20.1
- 14.16.0
notifications:
slack:
secure: EZrbgZ2IaICLs4THyZil3bUS+cvRMx2QKqv2Vb6CcwAZO3Or3l89q/Wqspn1+eeHWJbdOEs0wyAkQgLO2A1NrPmSoeBc+wsJSYqDLieTZDh8wNKonWPoyu4rvGEjst/bC9QrMiFHW8XS0GmcvIl5t+d513N6Phu15Sl65giK6d4=
8 changes: 5 additions & 3 deletions lib/conf/tasks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ var fs = require('fs'),
os_name = process.platform.replace('win32', 'windows').replace('darwin', 'mac'),
is_mac = os_name == 'mac',
is_windows = os_name == 'windows',
api = require('./../../agent/plugins/control-panel/api'),
chela = require('chela');
chmodr = require('chmodr'),
api = require('./../../agent/plugins/control-panel/api');

/////////////////////////////////////////////////////////////////
// local requires

exports.chmodr = chmodr;

var os_hooks = require('./os/' + os_name),
daemon = require('./daemon'),
prey_user = require('./prey_user');
Expand Down Expand Up @@ -50,7 +52,7 @@ var set_up_version = function(version, cb) {
// first, ensure that /current path is readable by non-prey users
// so that impersonated commands within path work as expected.
log('Setting permissions on ' + paths.current);
chela.mod(paths.current, '0755', function(err) {
exports.chmodr(paths.current, 0o755, function(err) {
if (err) return cb(err);

// call post_activation hooks (e.g. firewall toggling in Windows)
Expand Down
29 changes: 26 additions & 3 deletions lib/conf/tasks/prey_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var fs = require('fs'),
exec = require('child_process').exec,
async = require('async'),
ocelot = require('ocelot'),
chown = require('chela').own;
chownr = require('chownr'),
uid_number = require('uid-number');

var shared = require('../shared'),
paths = require('./../../system/paths'),
Expand All @@ -16,7 +17,9 @@ var shared = require('../shared'),
config_dir = paths.config,
is_windows = process.platform === 'win32';

var prey_user = 'prey';
var prey_user = 'prey',
uids = {},
gids = {};

var debugging = true, // process.env.DEBUG;
debug = debugging ? log : function() { /* noop */ };
Expand Down Expand Up @@ -60,6 +63,24 @@ function create_user(cb) {
});
}

function get_ids(user, group, cb) {
// if group is null, default to user name
var group = group || (process.platform == 'darwin' ? 'wheel' : user);

if (uids[user] && gids[group])
return cb(null, uids[user], gids[group]);

debug('Getting IDs for user ' + user + ' and group ' + group);
uid_number(user, group, function(err, uid, gid) {
if (err) return cb(err);

uids[user] = uid;
gids[group] = gid;

cb(null, uid, gid);
})
}

function setup_permissions(cb) {
var paths = [install_dir, config_dir, log_file];

Expand All @@ -82,7 +103,9 @@ function setup_permissions(cb) {
var fx = paths.map(function(path) {
return function(cb) {
debug('Setting permissions on ' + path);
chown(path, prey_user, cb)
get_ids(prey_user, null, (err, uid, gid) => {
chownr(path, uid, gid, cb)
});
}
})

Expand Down
2 changes: 1 addition & 1 deletion lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var log = function(str) {
var checksum_for = function(file, cb) {
var error,
hash = createHash('sha1'),
stream = fs.ReadStream(file);
stream = fs.createReadStream(file);

stream.on('data', function(chunk) {
hash.update(chunk);
Expand Down
Loading

0 comments on commit 400ec61

Please sign in to comment.