From 386c79e02060928404ed3b6e693b625c2e1e2e7b Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Wed, 14 Sep 2011 17:15:40 -0600
Subject: [PATCH] rename and move prepare_deps into scripts/ now that all it
 does is generate keys which are only used for local development (all other
 environments will manually create keys).  Also add generate_ephemeral_keys as
 a post-install step so that npm install is all you need, like love

---
 package.json                       |  5 ++++-
 prepare_deps.sh                    | 10 ----------
 scripts/generate_ephemeral_keys.sh | 23 +++++++++++++++++++++++
 3 files changed, 27 insertions(+), 11 deletions(-)
 delete mode 100755 prepare_deps.sh
 create mode 100755 scripts/generate_ephemeral_keys.sh

diff --git a/package.json b/package.json
index dafffb6ea..eb3760192 100644
--- a/package.json
+++ b/package.json
@@ -25,6 +25,9 @@
     , "colors" : "0.5.0"
     , "sax" : "0.2.3"
     , "mimelib-noiconv" : "0.1.3"
-    , "jwcrypto": "https://github.com/lloyd/jwcrypto/tarball/8edb08b"
+    , "jwcrypto": "https://github.com/lloyd/jwcrypto/tarball/ace101"
+  }
+  , "scripts": {
+    "postinstall": "./scripts/generate_ephemeral_keys.sh"
   }
 }
diff --git a/prepare_deps.sh b/prepare_deps.sh
deleted file mode 100755
index e8b6c4c81..000000000
--- a/prepare_deps.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/bash
-
-echo ''
-echo '*** Generating keys and placing them into correct location ***'
-cd node_modules/jwcrypto
-node generate-keypair.js
-
-mv key.publickey ../../var/root.publickey
-mv key.secretkey ../../var/root.secretkey
-cd ../..
diff --git a/scripts/generate_ephemeral_keys.sh b/scripts/generate_ephemeral_keys.sh
new file mode 100755
index 000000000..a5da91812
--- /dev/null
+++ b/scripts/generate_ephemeral_keys.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
+VAR=SCRIPT_DIR/../var
+export PATH=$PATH:$SCRIPT_DIR/../node_modules/.bin
+
+# if keys already exist, do nothing
+if [ -f $VAR/root.publickey ] ; then
+    exit 0
+fi
+
+GENERATE_KEYPAIR=`which generate-keypair 2> /dev/null`
+
+if [ ! -x "$GENERATE_KEYPAIR" ] ; then
+    echo "can't find generate-keypair from the jwcrypto package.  try: npm install"
+    exit 1
+fi
+
+echo '*** Generating ephemeral keys used for testing ***'
+$GENERATE_KEYPAIR
+mkdir -p $VAR
+mv key.publickey $VAR/root.publickey
+mv key.secretkey $VAR/root.secretkey
-- 
GitLab