package 2.28 KB
#!/bin/bash
#-------------------------------------------------------------------------------
# Packages ONOS distributable into onos.tar.gz
#-------------------------------------------------------------------------------

export M2_REPO=${M2_REPO:-~/.m2/repository}
export KARAF_ZIP=${KARAF_ZIP:-~/Downloads/apache-karaf-3.0.1.zip}
export KARAF_DIST=$(basename $KARAF_ZIP .zip)

export ONOS_VERSION=${ONOS_VERSION:-1.0.0-SNAPSHOT}
export ONOS_STAGE_ROOT=${ONOS_STAGE_ROOT:-/tmp}
export ONOS_BITS=onos-$ONOS_VERSION
export ONOS_STAGE=$ONOS_STAGE_ROOT/$ONOS_BITS

# Bail on any errors
set -e

rm -fr $ONOS_STAGE # Remove this when package script is completed

# Make sure we have the original apache karaf bits first
[ ! -d $M2_REPO ] && echo "M2 repository $M2_REPO not found" && exit 1
[ ! -f $KARAF_ZIP ] && echo "Apache Karaf bits $KARAF_ZIP not found" && exit 1
[ -d $ONOS_STAGE ] && echo "ONOS stage $ONOS_STAGE already exists" && exit 1

# Create the stage directory and warp into it
mkdir -p $ONOS_STAGE
cd $ONOS_STAGE

# Unroll the Apache Karaf bits and make the ONOS top-level directories.
unzip $KARAF_ZIP
mkdir bin
mkdir lib

# Stage the ONOS admin scripts
cp -r $ONOS_ROOT/tools/package/bin .

# Stage the ONOS bundles
mkdir -p lib/org/onlab 
cp -r $M2_REPO/org/onlab lib/org


# Patch the Apache Karaf distribution file to point to the lib as maven repo
#perl -pi.old -e "s|^org.ops4j.pax.url.mvn.repositories= |org.ops4j.pax.url.mvn.repositories= \\\n    file:../../lib, |" $ONOS_STAGE/$KARAF_DIST/etc/org.ops4j.pax.url.mvn.cfg

# Patch the Apache Karaf distribution file to add ONOS features repository
perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onlab.onos/onos-features/$ONOS_VERSION/xml/features|" \
    $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg 

# Patch the Apache Karaf distribution file to load ONOS features
perl -pi.old -e 's|^(featuresBoot=.*)|\1,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow,onos-app-tvue|' \
    /tmp/onos-1.0.0-SNAPSHOT/apache-karaf-3.0.1/etc/org.apache.karaf.features.cfg 

# Patch the Apache Karaf distribution with ONOS branding bundle
cp $M2_REPO/org/onlab/onos/onos-branding/$ONOS_VERSION/onos-branding-*.jar \
    $ONOS_STAGE/apache-karaf-*/lib

# Now package up the ONOS tar file
cd $ONOS_STAGE_ROOT
tar zcf $ONOS_BITS.tar.gz $ONOS_BITS