Merge "Fixing jenkins file to pull code instead of rebuilding from scratch"
diff --git a/Makefile b/Makefile
index d4b2153..b1f76ee 100644
--- a/Makefile
+++ b/Makefile
@@ -221,11 +221,12 @@
 	ln -sf $(shell ldconfig -p | grep libgrpc++_reflection.so.1 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc++_reflection.so.1
 
 deb:
-	rm *.deb
-	cp build/*.tar.gz mkdebian/debian/release_asfvolt16.tar.gz
-	cp build/openolt mkdebian/debian
-	cp build/libgrpc++_reflection.so.1 mkdebian/debian
-	cp /usr/local/lib/libgrpc.so.6 mkdebian/debian
+	rm -f *.deb
+	cp $(BUILD_DIR)/*.tar.gz mkdebian/debian/release_asfvolt16.tar.gz
+	cp $(BUILD_DIR)/openolt mkdebian/debian
+	cp $(BUILD_DIR)/libgrpc.so.6 mkdebian/debian
+	cp $(BUILD_DIR)/libgrpc++.so.1 mkdebian/debian
+	cp $(BUILD_DIR)/libgrpc++_reflection.so.1 mkdebian/debian
 	cd mkdebian && ./build_asfvolt16_deb.sh
 	mv *.deb $(BUILD_DIR)/openolt.deb
 
diff --git a/README.md b/README.md
index 31e9bb3..bba5d66 100644
--- a/README.md
+++ b/README.md
@@ -54,6 +54,7 @@
 
 mv SW-BCM68620_2_4_3_6.zip sdk-all-6.5.7.tar.gz ACCTON_BAL_2.4.3.6-V201710131639.patch OPENOLT_BAL_2.4.3.6.zip openolt/download
 
+make prereq
 make
 ```
 The **build** directory contains all the build artifacts:
@@ -84,6 +85,7 @@
 - Run openolt:
 ```shell
 cd /broadcom
+export LD_LIBRARY_PATH=/broadcom
 ./openolt  -C 10.6.0.201:40000 -A 10.6.0.201:50000
 ```
 (Note - Substitute 10.6.0.201 with a local IP of the OLT - e.g. mgmt interface IP).
diff --git a/mkdebian/debian/asfvolt16.postinst b/mkdebian/debian/asfvolt16.postinst
index 8c4e661..ab3c7e7 100644
--- a/mkdebian/debian/asfvolt16.postinst
+++ b/mkdebian/debian/asfvolt16.postinst
@@ -1,9 +1,20 @@
 #!/bin/bash
 
-rm -rf /opt/bcm68620
-rm -rf  /broadcom
-rm -rf /run/bcm68620
+# Extract BAL driver
 tar zxf /tmp/release_asfvolt16.tar.gz -C / 2>&1 > /dev/null
+
+# Copy OpenOLT folder
+mv /tmp/openolt /broadcom
+
+# Copy libraries
+mv /tmp/libgrpc++_reflection.so.1 /usr/local/lib
+mv /tmp/libgrpc++.so.1 /usr/local/lib
+mv /tmp/libgrpc.so.6 /usr/local/lib
+
+# Init file
+#mv /tmp/voltha_init.sh /broadcom
+grep -q '\/opt\/bcm68620\/svk_init.sh' /etc/rc.local || sed -i -e '$i \/opt\/bcm68620\/svk_init.sh' /etc/rc.local
+
 source /root/.bashrc
-/sbin/ldconfig
-/opt/bcm68620/svk_init.sh
+cd /broadcom && /sbin/ldconfig
+/opt\/bcm68620\/svk_init.sh
diff --git a/mkdebian/debian/asfvolt16.postrm b/mkdebian/debian/asfvolt16.postrm
new file mode 100644
index 0000000..a666b17
--- /dev/null
+++ b/mkdebian/debian/asfvolt16.postrm
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+rm -rf /opt/bcm68620
+rm -rf /run/bcm68620
+
+rm -rf /broadcom
+
+rm -rf /usr/local/lib/libgrpc++_reflection.so.1
+rm -rf /usr/local/lib/libgrpc++.so.1
+rm -rf /usr/local/lib/libgrpc.so.6
+
+# Remove init scripts
+sed -i '\/opt\/bcm68620\/svk_init.sh/d' /etc/rc.local
+# sed -i '\/broadcom\/voltha_init.sh/d' /etc/rc.local
diff --git a/mkdebian/debian/asfvolt16.preinst b/mkdebian/debian/asfvolt16.preinst
index d2b2335..34bbd3b 100644
--- a/mkdebian/debian/asfvolt16.preinst
+++ b/mkdebian/debian/asfvolt16.preinst
@@ -2,11 +2,8 @@
 
 # kill CLI applications
 echo "kill running time application"
-[ -n "`pidof bcm_user_appl`" ] && killall bcm_user_appl
-[ -n "`pidof bcm.user`" ] && killall bcm.user
-[ -n "`pidof bcm_sdn_agent`" ] && killall bcm_sdn_agent
 [ -n "`pidof bal_core_dist`" ] && killall bal_core_dist 
-[ -n "`pidof voltha_bal_driver`" ] && killall voltha_bal_driver
+[ -n "`pidof openolt`" ] && killall openolt
 
 # unload drivers
 echo "unload kernel drivers"
@@ -24,3 +21,11 @@
 rm -rf /dev/linux-kernel-bde
 rm -rf /dev/coop_dba
 
+rm -rf /opt/bcm68620
+rm -rf /run/bcm68620
+
+rm -rf  /broadcom
+
+rm -rf /usr/local/lib/libgrpc++_reflection.so.1
+rm -rf /usr/local/lib/libgrpc++.so.1
+rm -rf /usr/local/lib/libgrpc.so.5
diff --git a/mkdebian/debian/rules b/mkdebian/debian/rules
index dbb836f..b2906d4 100755
--- a/mkdebian/debian/rules
+++ b/mkdebian/debian/rules
@@ -27,9 +27,13 @@
 override_dh_auto_install: 
 	mkdir -p $(DEB_DH_INSTALL_SOURCEDIR)/tmp
 	cp -a $(CURDIR)/debian/release_asfvolt16.tar.gz $(DEB_DH_INSTALL_SOURCEDIR)/tmp
+	cp -a $(CURDIR)/debian/libgrpc++_reflection.so.1 $(DEB_DH_INSTALL_SOURCEDIR)/tmp
+	cp -a $(CURDIR)/debian/libgrpc++.so.1 $(DEB_DH_INSTALL_SOURCEDIR)/tmp
+	cp -a $(CURDIR)/debian/libgrpc.so.6 $(DEB_DH_INSTALL_SOURCEDIR)/tmp
+	cp -a $(CURDIR)/debian/openolt $(DEB_DH_INSTALL_SOURCEDIR)/tmp
 
-#override_dh_shlibdeps:
-#	dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info -l$(ONLP_LIB_PATH):$(OFDPA_LIB_PATH)
+override_dh_shlibdeps:
+	dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info -l$(ONLP_LIB_PATH):$(OFDPA_LIB_PATH)
 
 # avoid auto strip for debug ofagentapp.dbg
 #
@@ -65,3 +69,4 @@
 	@echo ONLP_LIB_PATH=$(ONLP_LIB_PATH)
 #	@echo OFDPA_LIB_PATH=$(OFDPA_LIB_PATH)
 #	@echo OFDPA_BIN_PATH=$(OFDPA_BIN_PATH)
+