From 25919b7644bdef0ea59680ce10467680de5a2234 Mon Sep 17 00:00:00 2001
From: Clark Boylan <clark.boylan@gmail.com>
Date: Thu, 21 Jun 2012 17:52:43 +0000
Subject: [PATCH] Go back to using self compiled node.js.

The version of node.js packaged by ubuntu does not seem to play nice
with require-kernel and etherpad-lite. Go back to compiling version
0.6.16 of node.js which is tested and appears to be working.

Change-Id: Ib9bda5d7acbda06561398a0c715b28e46edb531d
---
 modules/etherpad_lite/manifests/init.pp     | 73 +++++++++++++++++----
 modules/etherpad_lite/templates/upstart.erb |  2 +-
 2 files changed, 61 insertions(+), 14 deletions(-)

diff --git a/modules/etherpad_lite/manifests/init.pp b/modules/etherpad_lite/manifests/init.pp
index 0ebe145faf..6cdde769ef 100644
--- a/modules/etherpad_lite/manifests/init.pp
+++ b/modules/etherpad_lite/manifests/init.pp
@@ -44,6 +44,39 @@ define git_repo (
 
 }
 
+# define to build from source using ./configure && make && make install.
+define buildsource(
+  $dir     = $title,
+  $user    = 'root',
+  $creates = '/nonexistant/file'
+) {
+
+  exec { "./configure in ${dir}":
+    command => './configure',
+    path    => "/usr/bin:/bin:/usr/local/bin:${dir}",
+    user    => $user,
+    cwd     => $dir,
+    creates => $creates
+  } ->
+
+  exec { "make in ${dir}":
+    command => 'make',
+    path    => '/usr/bin:/bin',
+    user    => $user,
+    cwd     => $dir,
+    creates => $creates
+  } ->
+
+  exec { "make install in ${dir}":
+    command => 'make install',
+    path    => '/usr/bin:/bin',
+    user    => $user,
+    cwd     => $dir,
+    creates => $creates
+  }
+
+}
+
 # Class to install etherpad lite. Puppet acts a lot like a package manager
 # through this class.
 #
@@ -86,18 +119,39 @@ class etherpad_lite (
     mode   => 0664,
   }
 
+  git_repo { 'nodejs_repo':
+    repo       => 'https://github.com/joyent/node.git',
+    dest       => "${base_install_dir}/nodejs",
+    branch     => 'v0.6.16-release',
+    clone_only => 'true',
+    require    => Package['git']
+  }
+
   package { ['gzip',
              'curl',
              'python',
              'libssl-dev',
              'pkg-config',
              'abiword',
-             'build-essential',
-             'nodejs',
-             'npm',]:
+             'build-essential']:
     ensure => present
   }
 
+  package { ['nodejs', 'npm']:
+    ensure => purged
+  }
+
+  buildsource { "${base_install_dir}/nodejs":
+    creates => '/usr/local/bin/node',
+    require => [Package['gzip'],
+                Package['curl'],
+                Package['python'],
+                Package['libssl-dev'],
+                Package['pkg-config'],
+                Package['build-essential'],
+                Git_repo['nodejs_repo']]
+  }
+
   git_repo { 'etherpad_repo':
     repo       => 'https://github.com/Pita/etherpad-lite.git',
     dest       => "${base_install_dir}/etherpad-lite",
@@ -113,16 +167,9 @@ class etherpad_lite (
     cwd         => "${base_install_dir}/etherpad-lite",
     environment => "HOME=${base_log_dir}/${ep_user}",
     require     => [Git_repo['etherpad_repo'],
-                    Package['gzip'],
-                    Package['curl'],
-                    Package['python'],
-                    Package['libssl-dev'],
-                    Package['pkg-config'],
-                    Package['build-essential'],
-                    Package['nodejs'],
-                    Package['npm']
-                   ],
-    before      => File["${base_install_dir}/etherpad-lite/settings.json"]
+                    Buildsource["${base_install_dir}/nodejs"]],
+    before      => File["${base_install_dir}/etherpad-lite/settings.json"],
+    creates     => "${base_install_dir}/etherpad-lite/node_modules"
   }
 
   file { '/etc/init/etherpad-lite.conf':
diff --git a/modules/etherpad_lite/templates/upstart.erb b/modules/etherpad_lite/templates/upstart.erb
index 246a7765bd..9610779659 100644
--- a/modules/etherpad_lite/templates/upstart.erb
+++ b/modules/etherpad_lite/templates/upstart.erb
@@ -20,7 +20,7 @@ end script
 
 script
   cd $EPHOME
-  exec su -s /bin/sh -c 'exec "$0" "$@"' $EPUSER -- node node_modules/ep_etherpad-lite/node/server.js \
+  exec su -s /bin/sh -c 'exec "$0" "$@"' $EPUSER -- /usr/local/bin/node node_modules/ep_etherpad-lite/node/server.js \
                         >> $EPLOGS/access.log \
                         2>> $EPLOGS/error.log
 end script