Updating onos-package for debian packaging

Change-Id: Icc3899b3a35ba0a02a97f5eddebfbe51ff6c1638
diff --git a/tools/package/deb/prerm b/tools/package/deb/prerm
new file mode 100755
index 0000000..5e8ace3
--- /dev/null
+++ b/tools/package/deb/prerm
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# Check if onos is running; if it is, stop onos
+[ -z "$(status onos 2>/dev/null | grep start)" ] && echo "onos is not running." || (
+    stop onos
+
+    # Wait for onos to stop up to 5 seconds
+    for i in $(seq 1 5); do
+      [ -z "$(ps -ef | grep karaf.jar | grep -v grep)" ] && break
+      sleep 1
+    done
+    [ -z "$(ps -ef | grep karaf.jar | grep -v grep)" ] && echo 'Stopped onos service' || echo 'Failed to stop onos'
+    ps -ef | grep karaf.jar | grep -v grep
+)
+
+# Clean up onos runtime directories
+#      TODO don't hardcode karaf version
+rm -rf /opt/onos/apache-karaf-3.0.3/
+rm -rf /opt/onos/var/*
+rm -rf /opt/onos/config
+rm -rf /opt/onos/options
+rm -rf /opt/onos/log
+
+#TODO consider removing the sdn user if we created it