blob: 8b363042e3826419b0f9e14cac0c65f1930a79ce [file] [log] [blame]
tom4d0c6632014-09-15 23:27:01 -07001#!/bin/bash
Pavlin Radoslavov91413792014-10-15 11:00:32 -07002# -----------------------------------------------------------------------------
Thomas Vachuska734b7492015-03-11 20:42:07 -07003# Packages ONOS distributable into onos.tar.gz and onos.zip
Pavlin Radoslavov91413792014-10-15 11:00:32 -07004# -----------------------------------------------------------------------------
tom4d0c6632014-09-15 23:27:01 -07005
tom5c255702014-09-18 06:57:39 -07006[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
7. $ONOS_ROOT/tools/build/envDefaults
tom4d0c6632014-09-15 23:27:01 -07008
9# Bail on any errors
10set -e
11
12rm -fr $ONOS_STAGE # Remove this when package script is completed
13
14# Make sure we have the original apache karaf bits first
15[ ! -d $M2_REPO ] && echo "M2 repository $M2_REPO not found" && exit 1
tom4d0c6632014-09-15 23:27:01 -070016[ -d $ONOS_STAGE ] && echo "ONOS stage $ONOS_STAGE already exists" && exit 1
17
18# Create the stage directory and warp into it
19mkdir -p $ONOS_STAGE
20cd $ONOS_STAGE
21
Thomas Vachuskab105fd42014-10-20 09:02:27 -070022# Check if Apache Karaf bits are available and if not, fetch them.
23if [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ]; then
24 echo "Downloading $KARAF_TAR..."
Thomas Vachuska84ca6e72015-03-18 14:31:29 -070025 curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR
Thomas Vachuskab105fd42014-10-20 09:02:27 -070026fi
27[ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \
28 echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1
29
tom5c255702014-09-18 06:57:39 -070030# Unroll the Apache Karaf bits, prune them and make ONOS top-level directories.
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070031[ -f $KARAF_ZIP ] && unzip -q $KARAF_ZIP && rm -rf $ONOS_STAGE/$KARAF_DIST/demos
32[ -f $KARAF_TAR ] && tar zxf $KARAF_TAR && rm -rf $ONOS_STAGE/$KARAF_DIST/demos
tom4d0c6632014-09-15 23:27:01 -070033mkdir bin
tom4d0c6632014-09-15 23:27:01 -070034
tom5c255702014-09-18 06:57:39 -070035# Stage the ONOS admin scripts and patch in Karaf service wrapper extras
tom4d0c6632014-09-15 23:27:01 -070036cp -r $ONOS_ROOT/tools/package/bin .
tom0eaa97f2014-09-22 16:13:06 -070037cp -r $ONOS_ROOT/tools/package/debian $ONOS_STAGE/debian
Thomas Vachuskab105fd42014-10-20 09:02:27 -070038cp -r $ONOS_ROOT/tools/package/etc/* $ONOS_STAGE/$KARAF_DIST/etc
39
Thomas Vachuska785f5812015-03-19 01:11:00 -070040# Stage all builtin ONOS apps for factory install
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070041onos-stage-apps $ONOS_STAGE/apps $ONOS_STAGE/$KARAF_DIST/system
Thomas Vachuska785f5812015-03-19 01:11:00 -070042
Thomas Vachuska82e60a92015-04-30 01:15:58 -070043# Mark the org.onosproject.drivers app active by default
44touch $ONOS_STAGE/apps/org.onosproject.drivers/active
45
Thomas Vachuska785f5812015-03-19 01:11:00 -070046# Patch-in proper Karaf version into the startup script
Thomas Vachuskab105fd42014-10-20 09:02:27 -070047sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
48 $ONOS_ROOT/tools/package/bin/onos-service > bin/onos-service
49sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
Thomas Vachuska12bf4452015-06-26 09:15:38 -070050 $ONOS_ROOT/tools/package/bin/onos-client > bin/onos
51chmod a+x bin/onos-service bin/onos
tom4d0c6632014-09-15 23:27:01 -070052
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080053# Stage the ONOS bundles, but only those that match the version
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070054mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject
Thomas Vachuskab23fad22015-05-05 15:20:58 -070055find $M2_REPO/org/onosproject -type f -path "*/$ONOS_POM_VERSION/*" \
Thomas Vachuska97a70332015-05-20 09:29:55 -070056 -name '*.jar' -o -name '*.pom' -o -name '*-features.xml' \
Thomas Vachuska8eb12a22015-05-05 16:20:19 -070057 | grep -v -Ee '-tests.jar|-[0-9]{8}.[0-9]{6}-' \
58 | while read src; do
Thomas Vachuskab23fad22015-05-05 15:20:58 -070059 dst=$ONOS_STAGE/$KARAF_DIST/system/${src#$M2_REPO/*}
60 mkdir -p $(dirname $dst)
61 cp $src $dst
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080062done
tom4d0c6632014-09-15 23:27:01 -070063
tom7e02cda2014-09-18 12:05:46 -070064# ONOS Patching ----------------------------------------------------------------
65
tom4d0c6632014-09-15 23:27:01 -070066# Patch the Apache Karaf distribution file to add ONOS features repository
Brian O'Connorabafb502014-12-02 22:26:20 -080067perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \
Brian O'Connor014e2212015-05-05 22:46:36 +000068 $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
tom4d0c6632014-09-15 23:27:01 -070069
Thomas Vachuska785f5812015-03-19 01:11:00 -070070# Patch the Apache Karaf distribution file to load default ONOS boot features
Thomas Vachuskabf916ea2015-05-20 18:24:34 -070071export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui"
Thomas Vachuska785f5812015-03-19 01:11:00 -070072perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \
tome4729872014-09-23 00:37:37 -070073 $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
74
tom4d0c6632014-09-15 23:27:01 -070075# Patch the Apache Karaf distribution with ONOS branding bundle
Brian O'Connorabafb502014-12-02 22:26:20 -080076cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-*.jar \
tom73d6d1e2014-09-17 20:08:01 -070077 $ONOS_STAGE/$KARAF_DIST/lib
tom4d0c6632014-09-15 23:27:01 -070078
tom61e317d2014-10-08 11:18:02 -070079# Patch in the ONOS version file
80echo $ONOS_VERSION > $ONOS_STAGE/VERSION
tom53efab52014-10-07 17:43:48 -070081
tom4d0c6632014-09-15 23:27:01 -070082# Now package up the ONOS tar file
83cd $ONOS_STAGE_ROOT
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070084rm -f $ONOS_TAR $ONOS_ZIP
tom5c255702014-09-18 06:57:39 -070085COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS
Thomas Vachuskaaab35592015-05-18 14:12:53 -070086
87# Figure out whether we should build ONOS zip file and if so, build it.
88which zip >/dev/null && [ -z "$ONOS_TAR_ONLY" ] && buildZip=true || unset buildZip
89[ -n "$buildZip" ] && zip -rq $ONOS_ZIP $ONOS_BITS
90
91# Report on the archives that were built and clean-up
92[ -n "$buildZip" ] && ls -lh $ONOS_TAR $ONOS_ZIP || ls -lh $ONOS_TAR
tom61e317d2014-10-08 11:18:02 -070093rm -r $ONOS_STAGE