Skip to content

Instantly share code, notes, and snippets.

@TheBITLINK
Last active November 28, 2016 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheBITLINK/6a35a2cd11cea30833870c2eab88778b to your computer and use it in GitHub Desktop.
Save TheBITLINK/6a35a2cd11cea30833870c2eab88778b to your computer and use it in GitHub Desktop.
Node.js Arch User
const getDistro = require('linus');
const isRoot = require('is-root');
const timeout = require('timeout-as-promise');
const chalk = require('chalk');
const truthy = require('truthy');
const execa = require('execa');
const terminate = require('terminate');
const Log = require('log');
const Promise = require('bluebird');
const pacmanCmd = require('system-install')().split(' ')[1];
const leftPad = require('left-pad');
const log = new Log();
const distro = Promise.promisify(getDistro.name);
function update() {
const pacman = execa(pacmanCmd, ['-Syu', '--noconfirm']);
pacman.stdout.pipe(process.stdout);
return pacman.then(timeout(10000)).then(update);
}
distro().then(d => {
// A true Arch user uses only vanilla Arch.
if (truthy(d.indexOf('Arch') < 0)) {
return Promise.reject('Not running on Arch. Aborting...');
}
// Check if we are root.
if(!truthy(isRoot())) {
return Promise.reject('Not running as root...');
}
}).then(update).catch(err => {
log.error(chalk.bgRed(err));
terminate(process.pid);
});
{
"name": "arch-user",
"version": "1.0.0",
"description": "A simple script to replace an Arch user",
"main": "archuser.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "TheBITLINK aka BIT <me@thebitlink.com>",
"license": "MIT",
"dependencies": {
"bluebird": "^3.4.6",
"chalk": "^1.1.3",
"execa": "^0.5.0",
"is-root": "^1.0.0",
"left-pad": "^1.1.3",
"linus": "0.0.6",
"log": "^1.4.0",
"system-install": "^1.0.0",
"terminate": "^1.0.8",
"timeout-as-promise": "^1.0.0",
"truthy": "0.0.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment