nlsr: Adding upstart, postinst, and preinst scripts

NLSR will not be operable until properly configured and proper certificates manually created.
diff --git a/nlsr/Makefile b/nlsr/Makefile
index 9cc8386..f9bfdbb 100644
--- a/nlsr/Makefile
+++ b/nlsr/Makefile
@@ -11,6 +11,6 @@
 VERSION=0.1~rc0.3
 
 # PPA version
-PPA_VERSION=1
+PPA_VERSION=2
 
 include ../packaging.mk
diff --git a/nlsr/debian/changelog b/nlsr/debian/changelog
index 50ee397..ce01aa2 100644
--- a/nlsr/debian/changelog
+++ b/nlsr/debian/changelog
@@ -1,3 +1,10 @@
+nlsr (0.1~rc0.3-ppa2~DISTRO) DISTRO; urgency=low
+
+  * New version based on 48265996f2c8503bf9ba435fbfaade61fea2ffe8
+    (https://github.com/named-data/NLSR)
+
+ -- Alexander Afanasyev <alexander.afanasyev@ucla.edu>  Sun, 10 Aug 2014 18:17:44 -0700
+
 nlsr (0.1~rc0.3-ppa1~DISTRO) DISTRO; urgency=low
 
   * New version based on 48265996f2c8503bf9ba435fbfaade61fea2ffe8
diff --git a/nlsr/debian/nlsr.postinst b/nlsr/debian/nlsr.postinst
new file mode 100644
index 0000000..ab94851
--- /dev/null
+++ b/nlsr/debian/nlsr.postinst
@@ -0,0 +1,20 @@
+#!/bin/sh -e
+
+if [ "$1" != "configure" ]; then
+        exit 0
+fi
+
+if [ ! -d /var/log/ndn/nlsr ]; then
+    mkdir -p /var/log/ndn/nlsr
+    chown -R nlsr:nlsr /var/log/ndn/nlsr
+fi
+
+if [ ! -d /var/lib/ndn/nlsr ]; then
+    # Create HOME and generate self-signed NDN certificate for nrd
+    sudo mkdir -p /var/lib/ndn/nlsr/.ndn
+    sudo chown -R nlsr:nlsr /var/lib/ndn/nlsr
+fi
+
+#DEBHELPER#
+
+exit 0
diff --git a/nlsr/debian/nlsr.preinst b/nlsr/debian/nlsr.preinst
new file mode 100644
index 0000000..1407a0e
--- /dev/null
+++ b/nlsr/debian/nlsr.preinst
@@ -0,0 +1,61 @@
+#!/bin/sh
+# preinst script for nlsr
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <new-preinst> `install'
+#        * <new-preinst> `install' <old-version>
+#        * <new-preinst> `upgrade' <old-version>
+#        * <old-preinst> `abort-upgrade' <new-version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+
+case "$1" in
+    install|upgrade)
+        # Now we have to ensure the following state:
+        # /etc/passwd: nlsr:x:YYY:ZZZ:NLSR User:/nonexistent:/bin/false
+        # /etc/group:  nlsr:x:ZZZ:
+        #
+        # Sadly there could any state be present on the system so we have to
+        # modify everything carefully i.e. not doing a chown before creating
+        # the user etc...
+
+        # creating nlsr group if he isn't already there
+        if ! getent group nlsr >/dev/null; then
+                # Adding system group: nlsr.
+                addgroup --system nlsr >/dev/null
+        fi
+
+        # creating nlsr user if he isn't already there
+        if ! getent passwd nlsr >/dev/null; then
+                # Adding system user: nlsr.
+                adduser \
+                  --system \
+                  --disabled-login \
+                  --ingroup nlsr \
+                  --home /nonexistent \
+                  --gecos "NLSR User" \
+                  --shell /bin/false \
+                  nlsr  >/dev/null
+        fi
+    ;;
+
+    abort-upgrade)
+    ;;
+
+    *)
+        echo "preinst called with unknown argument \`$1'" >&2
+        exit 1
+    ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
diff --git a/nlsr/debian/nlsr.upstart b/nlsr/debian/nlsr.upstart
new file mode 100644
index 0000000..394605f
--- /dev/null
+++ b/nlsr/debian/nlsr.upstart
@@ -0,0 +1,24 @@
+# nlsr.conf
+#
+# NDN NLSR Routing Daemon
+
+description "NDN NLSR Routing Daemon"
+author      "John DeHart <jdd@wustl.edu>"
+
+start on started  nrd
+stop  on stopping nrd
+
+respawn
+respawn limit unlimited
+
+setuid nlsr
+setgid nlsr
+
+pre-start exec sleep 2
+
+script
+  export HOME=/var/lib/ndn/nlsr
+  exec /usr/bin/nlsr -f /etc/ndn/nlsr/nlsr.conf
+end script
+
+post-stop exec sleep 2