Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
setup nodejs (git, nvm, npm, forever) on remote machine
// working NodeSSH can be used by installing via npm this http://github.com/outbounder/NodeSSH/tarball/master
var SSHClient = require("NodeSSH");
var Expect = require('node-expect');
var password = "password";
var ssh=new SSHClient("host","root", "rootPassword");
parser = new Expect();
parser.debug = 5;
parser
.conversation("logged")
.sync() // synchronous conversation.
.expect(null,true) // the conversation trigger starts the expect. no need to expect anything more.
.send("apt-get update; apt-get -y install rsync build-essential g++ curl libssl-dev apache2-utils git-core\n")
.expect("# ")
.send("useradd -g admin -s /bin/bash -m nodejs\n")
.expect("# ")
.send("passwd nodejs\n")
.expect(/assword*/)
.send(password+"\n")
.expect(/assword*/)
.send(password+"\n")
.expect("# ")
.send("su - nodejs\n")
.end()
.conversation(/\$ /)
.sync()
.expect(null,true)
.send("git clone git://github.com/creationix/nvm.git ~/.nvm\n")
.expect(/\$ /)
.send(". ~/.nvm/nvm.sh; nvm install v0.4.11\n")
.expect(/\$ /)
.send(". ~/.nvm/nvm.sh; nvm use v0.4.11; npm install forever -g\n")
.expect(/\$ /)
.send("exit\n")
.emit("close")
.end()
.monitor(ssh);
ssh.on('close',function(addr) {
console.log('Disconnected from '+addr);
});
ssh.connect(function(addr) {
console.log('Connected to '+addr);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment