diff --git a/src/addons.js b/src/addons.js index cadc0bdaf..8d2e54eb4 100644 --- a/src/addons.js +++ b/src/addons.js @@ -1627,7 +1627,7 @@ function teardownRedis(app, options, callback) { container.remove(removeOptions, function (error) { if (error && error.statusCode !== 404) return callback(new Error('Error removing container:' + error)); - shell.sudo('removeVolume', [ RMADDONDIR_CMD, 'redis', app.id ], function (error) { + shell.sudo('removeVolume', [ RMADDONDIR_CMD, 'redis', app.id ], {}, function (error) { if (error) return callback(new Error('Error removing redis data:' + error)); rimraf(path.join(paths.LOG_DIR, `redis-${app.id}`), function (error) { @@ -1695,7 +1695,7 @@ function statusDocker(callback) { function restartDocker(callback) { assert.strictEqual(typeof callback, 'function'); - shell.sudo('restartdocker', [ path.join(__dirname, 'scripts/restartdocker.sh') ], NOOP_CALLBACK); + shell.sudo('restartdocker', [ path.join(__dirname, 'scripts/restartdocker.sh') ], {}, NOOP_CALLBACK); callback(null); } diff --git a/src/apptask.js b/src/apptask.js index fd4b48548..3fe6ed224 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -210,7 +210,7 @@ function addCollectdProfile(app, callback) { var collectdConf = ejs.render(COLLECTD_CONFIG_EJS, { appId: app.id, containerId: app.containerId }); fs.writeFile(path.join(paths.COLLECTD_APPCONFIG_DIR, app.id + '.conf'), collectdConf, function (error) { if (error) return callback(error); - shell.sudo('addCollectdProfile', [ CONFIGURE_COLLECTD_CMD, 'add', app.id ], callback); + shell.sudo('addCollectdProfile', [ CONFIGURE_COLLECTD_CMD, 'add', app.id ], {}, callback); }); } @@ -220,7 +220,7 @@ function removeCollectdProfile(app, callback) { fs.unlink(path.join(paths.COLLECTD_APPCONFIG_DIR, app.id + '.conf'), function (error) { if (error && error.code !== 'ENOENT') debugApp(app, 'Error removing collectd profile', error); - shell.sudo('removeCollectdProfile', [ CONFIGURE_COLLECTD_CMD, 'remove', app.id ], callback); + shell.sudo('removeCollectdProfile', [ CONFIGURE_COLLECTD_CMD, 'remove', app.id ], {}, callback); }); } @@ -239,7 +239,7 @@ function addLogrotateConfig(app, callback) { var tmpFilePath = path.join(os.tmpdir(), app.id + '.logrotate'); fs.writeFile(tmpFilePath, logrotateConf, function (error) { if (error) return callback(error); - shell.sudo('addLogrotateConfig', [ CONFIGURE_LOGROTATE_CMD, 'add', app.id, tmpFilePath ], callback); + shell.sudo('addLogrotateConfig', [ CONFIGURE_LOGROTATE_CMD, 'add', app.id, tmpFilePath ], {}, callback); }); }); } @@ -248,7 +248,7 @@ function removeLogrotateConfig(app, callback) { assert.strictEqual(typeof app, 'object'); assert.strictEqual(typeof callback, 'function'); - shell.sudo('removeLogrotateConfig', [ CONFIGURE_LOGROTATE_CMD, 'remove', app.id ], callback); + shell.sudo('removeLogrotateConfig', [ CONFIGURE_LOGROTATE_CMD, 'remove', app.id ], {}, callback); } function verifyManifest(manifest, callback) { diff --git a/src/backups.js b/src/backups.js index 60ff8cfa2..89fe1856f 100644 --- a/src/backups.js +++ b/src/backups.js @@ -600,7 +600,7 @@ function runBackupUpload(backupId, format, dataDir, callback) { assert.strictEqual(typeof dataDir, 'string'); assert.strictEqual(typeof callback, 'function'); - shell.sudo(`backup-${backupId}`, [ BACKUP_UPLOAD_CMD, backupId, format, dataDir ], { env: process.env }, function (error) { + shell.sudo(`backup-${backupId}`, [ BACKUP_UPLOAD_CMD, backupId, format, dataDir ], { preserveEnv: true }, function (error) { if (error && (error.code === null /* signal */ || (error.code !== 0 && error.code !== 50))) { // backuptask crashed return callback(new BackupsError(BackupsError.INTERNAL_ERROR, 'Backuptask crashed')); } else if (error && error.code === 50) { // exited with error diff --git a/src/caas.js b/src/caas.js index 38cc98b8b..5c335beb9 100644 --- a/src/caas.js +++ b/src/caas.js @@ -63,7 +63,7 @@ function retire(reason, info, callback) { apiServerOrigin: config.apiServerOrigin(), adminFqdn: config.adminFqdn() }; - shell.sudo('retire', [ RETIRE_CMD, reason, JSON.stringify(info), JSON.stringify(data) ], callback); + shell.sudo('retire', [ RETIRE_CMD, reason, JSON.stringify(info), JSON.stringify(data) ], {}, callback); } function getCaasConfig(callback) { diff --git a/src/cloudron.js b/src/cloudron.js index e3d212e73..c8ce47fc8 100644 --- a/src/cloudron.js +++ b/src/cloudron.js @@ -179,7 +179,7 @@ function getConfig(callback) { } function reboot(callback) { - shell.sudo('reboot', [ REBOOT_CMD ], callback); + shell.sudo('reboot', [ REBOOT_CMD ], {}, callback); } function checkDiskSpace(callback) { diff --git a/src/docker.js b/src/docker.js index 38541929c..238fc9006 100644 --- a/src/docker.js +++ b/src/docker.js @@ -129,7 +129,7 @@ function pullImage(manifest, callback) { // Use docker CLI here to support downloading of private repos. for dockerode, we have to use // https://github.com/apocas/dockerode#pull-from-private-repos - shell.spawn('pullImage', '/usr/bin/docker', [ 'pull', manifest.dockerImage ], { }, function (error) { + shell.spawn('pullImage', '/usr/bin/docker', [ 'pull', manifest.dockerImage ], {}, function (error) { if (error) { debug(`pullImage: Error pulling image ${manifest.dockerImage} of ${manifest.id}: ${error.message}`); return callback(new Error('Failed to pull image')); @@ -543,7 +543,7 @@ function clearVolume(app, name, subdir, callback) { assert.strictEqual(typeof subdir, 'string'); assert.strictEqual(typeof callback, 'function'); - shell.sudo('removeVolume', [ RMVOLUME_CMD, app.id, subdir ], callback); + shell.sudo('removeVolume', [ RMVOLUME_CMD, app.id, subdir ], {}, callback); } function removeVolume(app, name, subdir, callback) { @@ -561,6 +561,6 @@ function removeVolume(app, name, subdir, callback) { callback(error); } - shell.sudo('removeVolume', [ RMVOLUME_CMD, app.id, subdir ], callback); + shell.sudo('removeVolume', [ RMVOLUME_CMD, app.id, subdir ], {}, callback); }); } diff --git a/src/domains.js b/src/domains.js index d8db444b6..d98c3186c 100644 --- a/src/domains.js +++ b/src/domains.js @@ -488,7 +488,7 @@ function setAdmin(domain, callback) { callback(); - shell.sudo('restart', [ RESTART_CMD ], NOOP_CALLBACK); + shell.sudo('restart', [ RESTART_CMD ], {}, NOOP_CALLBACK); }); }); } diff --git a/src/reverseproxy.js b/src/reverseproxy.js index 7228da350..ac2ddc45c 100644 --- a/src/reverseproxy.js +++ b/src/reverseproxy.js @@ -191,7 +191,7 @@ function validateCertificate(location, domainObject, certificate) { function reload(callback) { if (process.env.BOX_ENV === 'test') return callback(); - shell.sudo('reload', [ RELOAD_NGINX_CMD ], callback); + shell.sudo('reload', [ RELOAD_NGINX_CMD ], {}, callback); } function generateFallbackCertificateSync(domainObject) { diff --git a/src/setup.js b/src/setup.js index 7937f83e3..b228f21dd 100644 --- a/src/setup.js +++ b/src/setup.js @@ -249,7 +249,7 @@ function restore(backupConfig, backupId, version, autoconf, auditSource, callbac // for this reason, we have to re-setup DNS after a restore so it has DKIm from the backup // Once we have a 100% IP based restore, we can skip this mail.setDnsRecords.bind(null, config.adminDomain()), - shell.sudo.bind(null, 'restart', [ RESTART_CMD ]) + shell.sudo.bind(null, 'restart', [ RESTART_CMD ], {}) ], function (error) { debug('restore:', error); if (error) webadminStatus.restore.error = error.message; diff --git a/src/shell.js b/src/shell.js index 82a27afd6..287aaff74 100644 --- a/src/shell.js +++ b/src/shell.js @@ -75,16 +75,11 @@ function spawn(tag, file, args, options, callback) { function sudo(tag, args, options, callback) { assert.strictEqual(typeof tag, 'string'); assert(util.isArray(args)); - - if (typeof options === 'function') { - callback = options; - options = { }; - } - assert.strictEqual(typeof options, 'object'); + assert.strictEqual(typeof callback, 'function'); // -S makes sudo read stdin for password. -E preserves environment - var cp = spawn(tag, SUDO, [ options.env ? '-SE' : '-S' ].concat(args), options, callback); + var cp = spawn(tag, SUDO, [ options.preserveEnv ? '-SE' : '-S' ].concat(args), options, callback); cp.stdin.end(); return cp; } diff --git a/src/test/shell-test.js b/src/test/shell-test.js index a6fec6ead..8990a165d 100644 --- a/src/test/shell-test.js +++ b/src/test/shell-test.js @@ -32,7 +32,7 @@ describe('shell', function () { }); it('cannot sudo invalid program', function (done) { - shell.sudo('test', [ 'randomprogram' ], function (error) { + shell.sudo('test', [ 'randomprogram' ], {}, function (error) { expect(error).to.be.ok(); done(); }); @@ -40,7 +40,7 @@ describe('shell', function () { it('can sudo valid program', function (done) { var RELOAD_NGINX_CMD = path.join(__dirname, '../src/scripts/reloadnginx.sh'); - shell.sudo('test', [ RELOAD_NGINX_CMD ], function (error) { + shell.sudo('test', [ RELOAD_NGINX_CMD ], {}, function (error) { expect(error).to.be.ok(); done(); }); diff --git a/src/updater.js b/src/updater.js index 99ca78338..5ab8e730c 100644 --- a/src/updater.js +++ b/src/updater.js @@ -74,7 +74,7 @@ function downloadUrl(url, file, callback) { debug(`downloadUrl: curl ${args}`); - shell.spawn('downloadUrl', '/usr/bin/curl', args.split(' '), { }, function (error) { + shell.spawn('downloadUrl', '/usr/bin/curl', args.split(' '), {}, function (error) { if (error) return retryCallback(new UpdaterError(UpdaterError.EXTERNAL_ERROR, `Failed to download ${url}: ${error.message}`)); debug(`downloadUrl: downloadUrl ${url} to ${file}`); @@ -105,7 +105,7 @@ function extractTarball(tarball, dir, callback) { debug(`extractTarball: tar ${args}`); - shell.spawn('extractTarball', '/bin/tar', args.split(' '), { }, function (error) { + shell.spawn('extractTarball', '/bin/tar', args.split(' '), {}, function (error) { if (error) return callback(new UpdaterError(UpdaterError.EXTERNAL_ERROR, `Failed to extract release package: ${error.message}`)); safe.fs.unlinkSync(tarball); @@ -175,7 +175,7 @@ function doUpdate(boxUpdateInfo, callback) { tasks.setProgress(tasks.TASK_UPDATE, { percent: 70, message: 'Installing update' }, NOOP_CALLBACK); - shell.sudo('update', [ UPDATE_CMD, packageInfo.file ], function (error) { + shell.sudo('update', [ UPDATE_CMD, packageInfo.file ], {}, function (error) { if (error) return updateError(error); // Do not add any code here. The installer script will stop the box code any instant