blob: 2360946919b7f325a7e79b37e505713fdbb6220e [file] [log] [blame]
#!/bin/bash
# -----------------------------------------------------------------------------
# Packages ONOS distributable into onos.tar.gz and onos.zip
# -----------------------------------------------------------------------------
[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
. $ONOS_ROOT/tools/build/envDefaults
# 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
[ -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
# Check if Apache Karaf bits are available and if not, fetch them.
if [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ]; then
echo "Downloading $KARAF_TAR..."
curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR
fi
[ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \
echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1
# Unroll the Apache Karaf bits, prune them and make ONOS top-level directories.
[ -f $KARAF_ZIP ] && unzip -q $KARAF_ZIP && rm -rf $ONOS_STAGE/$KARAF_DIST/demos
[ -f $KARAF_TAR ] && tar zxf $KARAF_TAR && rm -rf $ONOS_STAGE/$KARAF_DIST/demos
mkdir bin
# Stage the ONOS admin scripts and patch in Karaf service wrapper extras
cp -r $ONOS_ROOT/tools/package/bin .
cp -r $ONOS_ROOT/tools/package/debian $ONOS_STAGE/debian
cp -r $ONOS_ROOT/tools/package/etc/* $ONOS_STAGE/$KARAF_DIST/etc
# Stage all builtin ONOS apps for factory install
onos-stage-apps $ONOS_STAGE/apps $ONOS_STAGE/$KARAF_DIST/system
# Mark the org.onosproject.drivers app active by default
touch $ONOS_STAGE/apps/org.onosproject.drivers/active
# 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" \
$ONOS_ROOT/tools/package/bin/onos > bin/onos
# Stage the ONOS bundles, but only those that match the version
mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject
find $M2_REPO/org/onosproject -type f -path "*/$ONOS_POM_VERSION/*" \
-name '*.jar' -o -name '*.pom' -o -name 'features.xml' \
| grep -v -e '-tests.jar' | while read src; do
dst=$ONOS_STAGE/$KARAF_DIST/system/${src#$M2_REPO/*}
mkdir -p $(dirname $dst)
cp $src $dst
done
# ONOS Patching ----------------------------------------------------------------
# Patch the Apache Karaf distribution file to add ONOS features repository
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 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
cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-*.jar \
$ONOS_STAGE/$KARAF_DIST/lib
# Patch in the ONOS version file
echo $ONOS_VERSION > $ONOS_STAGE/VERSION
# Now package up the ONOS tar file
cd $ONOS_STAGE_ROOT
rm -f $ONOS_TAR $ONOS_ZIP
COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS
which zip >/dev/null && zip -rq $ONOS_ZIP $ONOS_BITS
which zip >/dev/null && ls -l $ONOS_TAR $ONOS_ZIP || ls -l $ONOS_TAR
rm -r $ONOS_STAGE