blob: 05b51e646ae3198987e2efc0cb4e6f46bc1ed617 [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..."
25 karafURL=$(curl -s http://www.apache.org/dyn/closer.cgi/karaf/$KARAF_VERSION/apache-karaf-$KARAF_VERSION.tar.gz |
26 grep "<a href=\".*apache-karaf-$KARAF_VERSION.tar.gz\"" |
27 head -n 1 | sed 's/.*<a href="//g;s/".*//g')
28 curl -s $karafURL > $KARAF_TAR
29fi
30[ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \
31 echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1
32
tom5c255702014-09-18 06:57:39 -070033# Unroll the Apache Karaf bits, prune them and make ONOS top-level directories.
tom2d7acb72014-09-22 22:13:00 -070034[ -f $KARAF_ZIP ] && unzip -q $KARAF_ZIP && rm -rf $KARAF_DIST/demos
35[ -f $KARAF_TAR ] && tar zxf $KARAF_TAR && rm -rf $KARAF_DIST/demos
tom4d0c6632014-09-15 23:27:01 -070036mkdir bin
tom4d0c6632014-09-15 23:27:01 -070037
tom5c255702014-09-18 06:57:39 -070038# Stage the ONOS admin scripts and patch in Karaf service wrapper extras
tom4d0c6632014-09-15 23:27:01 -070039cp -r $ONOS_ROOT/tools/package/bin .
tom0eaa97f2014-09-22 16:13:06 -070040cp -r $ONOS_ROOT/tools/package/debian $ONOS_STAGE/debian
Thomas Vachuskab105fd42014-10-20 09:02:27 -070041cp -r $ONOS_ROOT/tools/package/etc/* $ONOS_STAGE/$KARAF_DIST/etc
42
43# Patch-in proper Karaf version into the startup script.
44sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
45 $ONOS_ROOT/tools/package/bin/onos-service > bin/onos-service
46sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
47 $ONOS_ROOT/tools/package/bin/onos > bin/onos
tom4d0c6632014-09-15 23:27:01 -070048
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080049# Stage the ONOS bundles, but only those that match the version
Brian O'Connorabafb502014-12-02 22:26:20 -080050mkdir -p $KARAF_DIST/system/org/onosproject
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080051# cp -r $M2_REPO/org/onosproject/ $KARAF_DIST/system/org/
52find $M2_REPO/org/onosproject/ -type d -name $ONOS_POM_VERSION | while read line; do
53 path=${line#*/onosproject/}
54 artifact=${path%/$ONOS_POM_VERSION}
55 mkdir -p $KARAF_DIST/system/org/onosproject/$artifact
56 cp -r $M2_REPO/org/onosproject/$artifact/$ONOS_POM_VERSION \
57 $KARAF_DIST/system/org/onosproject/$artifact/$ONOS_POM_VERSION
58done
tom4d0c6632014-09-15 23:27:01 -070059
tom7e02cda2014-09-18 12:05:46 -070060# ONOS Patching ----------------------------------------------------------------
61
tom4d0c6632014-09-15 23:27:01 -070062# Patch the Apache Karaf distribution file to add ONOS features repository
Brian O'Connorabafb502014-12-02 22:26:20 -080063perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \
tom4d0c6632014-09-15 23:27:01 -070064 $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
65
tome4729872014-09-23 00:37:37 -070066# Patch the Apache Karaf distribution file to load ONOS features
Thomas Vachuska734b7492015-03-11 20:42:07 -070067export ONOS_FEATURES="webconsole,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow"
tome797a5d2014-09-30 11:57:50 -070068perl -pi.old -e "s|^(featuresBoot=.*)|\1,$ONOS_FEATURES|" \
tome4729872014-09-23 00:37:37 -070069 $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
70
tom4d0c6632014-09-15 23:27:01 -070071# Patch the Apache Karaf distribution with ONOS branding bundle
Brian O'Connorabafb502014-12-02 22:26:20 -080072cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-*.jar \
tom73d6d1e2014-09-17 20:08:01 -070073 $ONOS_STAGE/$KARAF_DIST/lib
tom4d0c6632014-09-15 23:27:01 -070074
tom61e317d2014-10-08 11:18:02 -070075# Patch in the ONOS version file
76echo $ONOS_VERSION > $ONOS_STAGE/VERSION
tom53efab52014-10-07 17:43:48 -070077
tom4d0c6632014-09-15 23:27:01 -070078# Now package up the ONOS tar file
79cd $ONOS_STAGE_ROOT
tom5c255702014-09-18 06:57:39 -070080COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS
Thomas Vachuskafc7f22d2014-12-04 11:07:01 -080081which zip >/dev/null && zip -rq $ONOS_ZIP $ONOS_BITS
Thomas Vachuska045c01d2014-12-04 00:18:06 -080082ls -l $ONOS_TAR $ONOS_ZIP >&2
tom61e317d2014-10-08 11:18:02 -070083rm -r $ONOS_STAGE