Build script adjustments

Based on Apple's documentation (https://developer.apple.com/library/content/
documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html)
custom paths must not be used for binaries, as they are left unsigned by
codesign app.

Change-Id: I628a3a9da15dfdbbf515b4c16a3d38590ae433f5
diff --git a/make-osx-bundle.py b/make-osx-bundle.py
index 4a78a58..dfbbbe4 100755
--- a/make-osx-bundle.py
+++ b/make-osx-bundle.py
@@ -261,10 +261,20 @@
     print ' * Copying NDN dependencies'
 
     src = os.path.join(path, 'bin')
-    dst = os.path.join(self.bundle, 'Contents', 'Platform')
-    shutil.copytree(src, dst, symlinks=False)
+    dstBinary = os.path.join(self.bundle, 'Contents', 'Helpers')
+    dstResource = os.path.join(self.bundle, 'Contents', 'Resources', 'bin')
+    os.makedirs(dstBinary)
+    os.makedirs(dstResource)
 
-    for subdir, dirs, files in os.walk(dst):
+    for file in os.listdir(src):
+      ftype = Popen(['/usr/bin/file', '-b', "%s/%s" % (src, file)], stdout=PIPE).communicate()[0]
+      if "Mach-O" in ftype:
+        shutil.copy("%s/%s" % (src, file), "%s/%s" % (dstBinary, file))
+      else:
+        shutil.copy("%s/%s" % (src, file), "%s/%s" % (dstResource, file))
+        Popen(['/usr/bin/sed', '-i', '', '-e', 's|`dirname "$0"`/|`dirname "$0"`/../../Helpers/|', "%s/%s" % (dstResource, file)]).communicate()[0]
+
+    for subdir, dirs, files in os.walk(dstBinary):
       for file in files:
         abs = subdir + "/" + file
         self.handle_binary_libs(abs)
diff --git a/res/bin/ndn b/res/bin/ndn
new file mode 100755
index 0000000..1ced1b6
--- /dev/null
+++ b/res/bin/ndn
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+function usage() {
+    echo
+    echo Available commands:
+    for command in $(ls /Applications/NDN.app/Contents/Helpers/ 2>/dev/null); do
+        echo "  $command"
+    done
+    for command in $(ls /Applications/NDN.app/Contents/Resources/bin/ 2>/dev/null); do
+        echo "  $command"
+    done
+}
+
+if [[ $# -eq 0 ]]; then
+    echo ERROR: No command is specified
+    usage
+    exit 1
+fi
+
+if [[ -f /Applications/NDN.app/Contents/Helpers/"$1" ]]; then
+    /Applications/NDN.app/Contents/Helpers/"$@"
+elif [[ -f /Applications/NDN.app/Contents/Resources/bin/"$1" ]]; then
+    /Applications/NDN.app/Contents/Resources/bin/"$@"
+else
+    echo ERROR: Unknown is specified
+    usage
+    exit 1
+fi
diff --git a/res/ndn b/res/ndn
deleted file mode 100755
index 50f4921..0000000
--- a/res/ndn
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-
-if [[ $# -eq 0 ]] || [[ ! -f /Applications/NDN.app/Contents/Platform/"$1" ]] ; then
-    echo ERROR: No command or invalid command is specified
-    echo
-    echo Available commands:
-    for command in $(ls /Applications/NDN.app/Contents/Platform/ 2>/dev/null); do
-        echo "  $command"
-    done
-    exit 1
-fi
-
-/Applications/NDN.app/Contents/Platform/"$@"
diff --git a/src/main.cpp b/src/main.cpp
index 9cfff3a..1dcee21 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -166,6 +166,10 @@
 int
 main(int argc, char *argv[])
 {
+  ndn::KeyChain keyChain;
+  ndn::Data data("/to/request/or/check/keychain/permissions");
+  keyChain.sign(data);
+
   qRegisterMetaType<ndn::shared_ptr<const ndn::Data>>();
   qRegisterMetaType<ndn::nfd::ForwarderStatus>();
   qRegisterMetaType<std::vector<ndn::nfd::FibEntry>>();
diff --git a/src/tray-menu.cpp b/src/tray-menu.cpp
index 3a6d76c..de90134 100644
--- a/src/tray-menu.cpp
+++ b/src/tray-menu.cpp
@@ -199,7 +199,7 @@
 #ifdef OSX_BUILD
   QProcess* proc = new QProcess();
   connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater()));
-  proc->startDetached((QCoreApplication::applicationDirPath() + "/../Platform/nfd"),
+  proc->startDetached((QCoreApplication::applicationDirPath() + "/../Helpers/nfd"),
                       QStringList()
                         << "--config"
                         << (QCoreApplication::applicationDirPath() + "/../etc/ndn/nfd.conf"));
@@ -255,7 +255,7 @@
 
   scheduleDelayedTask(std::chrono::seconds(2), [this] {
       appendNdnAutoConfigStatus("NDN auto configuration starting...\n");
-      m_acProc->start(QCoreApplication::applicationDirPath() + "/../Platform/ndn-autoconfig",
+      m_acProc->start(QCoreApplication::applicationDirPath() + "/../Helpers/ndn-autoconfig",
                       QStringList() << "--daemon");
       connect(m_acProc, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput()));
       connect(m_acProc, SIGNAL(readyReadStandardError()), this, SLOT(processOutput()));
@@ -394,7 +394,7 @@
               << "do shell script \""
                    "/bin/mkdir -vp /usr/local/bin; "
                    "/bin/ln -s -f '" +  QCoreApplication::applicationDirPath() +
-                     "/../Resources/ndn" + "' /usr/local/bin/ndn;"
+                     "/../Resources/bin/ndn" + "' /usr/local/bin/ndn;"
                    "\" with administrator privileges");
 #endif
 }