Last active
November 28, 2016 17:57
-
-
Save TheBITLINK/6a35a2cd11cea30833870c2eab88778b to your computer and use it in GitHub Desktop.
Node.js Arch User
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
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); | |
}); |
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
{ | |
"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 <[email protected]>", | |
"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