-
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(linux): add linux user extension
closes #189 - add linux extension that creates a `ghost` user on the system, used by systemd (and potentially any other process manager)
- Loading branch information
Showing
3 changed files
with
67 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const os = require('os'); | ||
const execa = require('execa'); | ||
const Promise = require('bluebird'); | ||
|
||
const cli = require('../../lib'); | ||
|
||
class LinuxExtension extends cli.Extension { | ||
setup(cmd, argv) { | ||
if (argv.local) { | ||
return; | ||
} | ||
|
||
cmd.addStage('linux-user', this.addGhostUser.bind(this), null, 'a ghost system user'); | ||
} | ||
|
||
addGhostUser(argv, ctx, task) { | ||
if (os.platform() !== 'linux') { | ||
return task.skip('Platform is not linux'); | ||
} | ||
|
||
try { | ||
execa.shellSync('id ghost'); | ||
return task.skip('Ghost user already exists') | ||
} catch (e) { | ||
if (!e.message.match(/no such user/)) { | ||
return Promise.reject(e); | ||
} | ||
} | ||
|
||
return this.ui.listr([{ | ||
title: 'Creating ghost system user', | ||
task: () => this.ui.sudo('useradd --system --user-group ghost') | ||
}, { | ||
title: 'Changing directory permissions', | ||
task: () => this.ui.sudo(`chown -R ghost:ghost ${ctx.instance.dir}`) | ||
}, { | ||
title: 'Adding current user to ghost group', | ||
task: (ctx) => { | ||
return execa.shell('id -un').then((result) => { | ||
ctx.currentuser = result.stdout; | ||
return this.ui.sudo(`gpasswd --add ${ctx.currentuser} ghost`); | ||
}); | ||
} | ||
}], false); | ||
} | ||
} | ||
|
||
module.exports = LinuxExtension; |
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