Skip to content

Instantly share code, notes, and snippets.

@outbounder
Created August 26, 2011 22:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save outbounder/1174534 to your computer and use it in GitHub Desktop.
Save outbounder/1174534 to your computer and use it in GitHub Desktop.
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