ONOS-1328 Converted ONOS features to apps.

ONOS_FEATURES env. var is now deprecated!

Cells are expected to use ONOS_APPS env. var to tailor which builtin apps should be activated by default.  All builtin apps are installed by default, but can be uninstalled if desired.

Cleaned up cell definitions accordingly.

Change-Id: If3bb4691a73543a69197f4bf1855c8368f558450
diff --git a/tools/build/onos-package b/tools/build/onos-package
index afa9848..836ca9d 100755
--- a/tools/build/onos-package
+++ b/tools/build/onos-package
@@ -37,7 +37,17 @@
 cp -r $ONOS_ROOT/tools/package/debian $ONOS_STAGE/debian
 cp -r $ONOS_ROOT/tools/package/etc/* $ONOS_STAGE/$KARAF_DIST/etc
 
-# Patch-in proper Karaf version into the startup script.
+# Stage all builtin ONOS apps for factory install
+mkdir $ONOS_STAGE/apps
+find $ONOS_ROOT -name 'app.xml' | egrep -v '/src/test/|/target/|org\.foo\.' | \
+    xargs grep 'name=' | sed 's/<app name="//g;s/".*//g' | while read line; do
+        appxml=${line%:*}
+        app=${line#*:}
+        mkdir $ONOS_STAGE/apps/$app
+        cp $appxml $ONOS_STAGE/apps/$app/app.xml
+    done
+
+# Patch-in proper Karaf version into the startup script
 sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
     $ONOS_ROOT/tools/package/bin/onos-service > bin/onos-service
 sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
@@ -60,9 +70,9 @@
 perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \
     $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg 
 
-# Patch the Apache Karaf distribution file to load ONOS features
-export ONOS_FEATURES="webconsole,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow"
-perl -pi.old -e "s|^(featuresBoot=.*)|\1,$ONOS_FEATURES|" \
+# Patch the Apache Karaf distribution file to load default ONOS boot features
+export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-cli,onos-rest,onos-gui"
+perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \
     $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
 
 # Patch the Apache Karaf distribution with ONOS branding bundle