From 81202600bf28baa3602620c5a04c01a880ce416c Mon Sep 17 00:00:00 2001
From: Sean McArthur <sean.monstar@gmail.com>
Date: Thu, 9 Aug 2012 20:42:11 -0700
Subject: [PATCH] remove symlinks, added postinstall script

- unix symlinks are incompatible with Windows
- postinstall now generates keys, and sets up files

fixes #2263
---
 .gitignore                                  |  4 +-
 package.json                                |  2 +-
 resources/static/common/js/lib/bidbundle.js |  1 -
 resources/static/dialog/views/site          |  1 -
 scripts/awsbox/post_deploy.sh               |  2 +-
 scripts/postinstall.js                      | 42 +++++++++++++++++++++
 6 files changed, 47 insertions(+), 5 deletions(-)
 delete mode 120000 resources/static/common/js/lib/bidbundle.js
 delete mode 120000 resources/static/dialog/views/site
 create mode 100644 scripts/postinstall.js

diff --git a/.gitignore b/.gitignore
index 24d578800..a556e4109 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,8 @@
 /resources/static/build
 /resources/static/production
 /resources/static/i18n
+/resources/static/common/js/lib/bidbundle.js
+/resources/static/dialog/views/site
 .DS_Store
 Thumbs.db
 /locale
@@ -18,4 +20,4 @@ Thumbs.db
 /automation-tests/credentials.yaml
 /automation-tests/sauce.yaml
 automation-tests/persona_server/results/*
-/automation-tests/chromedriver.log
\ No newline at end of file
+/automation-tests/chromedriver.log
diff --git a/package.json b/package.json
index f4be9a5a9..4cede4338 100644
--- a/package.json
+++ b/package.json
@@ -47,7 +47,7 @@
     },
     "scripts": {
         "preinstall": "./scripts/lockdown",
-        "postinstall": "node ./scripts/generate_ephemeral_keys.js",
+        "postinstall": "node ./scripts/postinstall.js",
         "test": "./scripts/test",
         "start": "node ./scripts/run_locally.js"
     },
diff --git a/resources/static/common/js/lib/bidbundle.js b/resources/static/common/js/lib/bidbundle.js
deleted file mode 120000
index 00c7194bc..000000000
--- a/resources/static/common/js/lib/bidbundle.js
+++ /dev/null
@@ -1 +0,0 @@
-../../../../../node_modules/jwcrypto/bidbundle.js
\ No newline at end of file
diff --git a/resources/static/dialog/views/site b/resources/static/dialog/views/site
deleted file mode 120000
index f5a3723db..000000000
--- a/resources/static/dialog/views/site
+++ /dev/null
@@ -1 +0,0 @@
-../../../views/
\ No newline at end of file
diff --git a/scripts/awsbox/post_deploy.sh b/scripts/awsbox/post_deploy.sh
index 766cc41a0..ef4220340 100755
--- a/scripts/awsbox/post_deploy.sh
+++ b/scripts/awsbox/post_deploy.sh
@@ -2,7 +2,7 @@
 
 if [ ! -f $HOME/var/root.cert ] ; then
     echo ">> generating keypair"
-    scripts/generate_ephemeral_keys.js
+    scripts/postinstall.js
     mv var/root.{cert,secretkey} $HOME/var
 else
     echo ">> no keypair needed.  you gots one"
diff --git a/scripts/postinstall.js b/scripts/postinstall.js
new file mode 100644
index 000000000..9af5bec42
--- /dev/null
+++ b/scripts/postinstall.js
@@ -0,0 +1,42 @@
+// make symlinks
+var fs = require('fs');
+var path = require('path');
+var existsSync = fs.existsSync || path.existsSync;
+
+// symlink'ed directories work fine in both *nix and Windows
+function relativeLink(src, dest) {
+  src = path.join(__dirname, src);
+  dest = path.join(__dirname, dest);
+  var destParent = path.dirname(dest);
+  var cwd = process.cwd();
+  process.chdir(destParent);
+
+  if (existsSync(dest)) {
+    fs.unlinkSync(dest);
+  }
+  var relSrc = path.relative(destParent, src);
+  fs.symlinkSync(relSrc, dest, 'junction');
+  process.chdir(cwd);
+}
+
+// Windows requires Administrator cmd prompt to make file links,
+// so just make a copy instead.
+function copy(src, dest) {
+  src = path.join(__dirname, src);
+  dest = path.join(__dirname, dest);
+  fs.writeFileSync(dest, fs.readFileSync(src));
+}
+
+copy('../node_modules/jwcrypto/bidbundle.js', '../resources/static/common/js/lib/bidbundle.js');
+relativeLink('../resources/views', '../resources/static/dialog/views/site');
+
+
+// generate ephemeral keys
+var child_process = require('child_process');
+function node(script) {
+  var cp = child_process.spawn('node', [path.join(__dirname, script)]);
+  cp.stdout.pipe(process.stdout);
+  cp.stderr.pipe(process.stderr);
+}
+
+node('./generate_ephemeral_keys.js');
-- 
GitLab