blob: 51207c524063c2df8f6c4d6de7628de97549287d [file] [log] [blame]
tom4d0c6632014-09-15 23:27:01 -07001#!/bin/bash
Pavlin Radoslavov91413792014-10-15 11:00:32 -07002# -----------------------------------------------------------------------------
Luca Pretee6183752015-07-29 01:55:50 -07003# Packages ONOS distributable into onos.tar.gz, onos.zip or a deb file
Pavlin Radoslavov91413792014-10-15 11:00:32 -07004# -----------------------------------------------------------------------------
tom4d0c6632014-09-15 23:27:01 -07005
Luca Pretee6183752015-07-29 01:55:50 -07006# Build the staging directory used to produce the packages
7function build_stage_dir() {
8 # Make sure we have the original apache karaf bits first
9 [ ! -d $M2_REPO ] && echo "M2 repository $M2_REPO not found" && exit 1
10 [ -d $ONOS_STAGE ] && echo "ONOS stage $ONOS_STAGE already exists" && exit 1
11
12 # Create the stage directory and warp into it
13 mkdir -p $ONOS_STAGE
14 cd $ONOS_STAGE
15
16 # Check if Apache Karaf bits are available and if not, fetch them.
17 if [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ]; then
18 echo "Downloading $KARAF_TAR..."
19 curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR
20 fi
21 [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \
22 echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1
23
24 # Unroll the Apache Karaf bits, prune them and make ONOS top-level directories.
25 [ -f $KARAF_ZIP ] && unzip -q $KARAF_ZIP && rm -rf $ONOS_STAGE/$KARAF_DIST/demos
26 [ -f $KARAF_TAR ] && tar zxf $KARAF_TAR && rm -rf $ONOS_STAGE/$KARAF_DIST/demos
27 mkdir bin
28
29 # Stage the ONOS admin scripts and patch in Karaf service wrapper extras
30 cp -r $ONOS_ROOT/tools/package/bin .
31 cp -r $ONOS_ROOT/tools/package/debian $ONOS_STAGE/debian
32 cp -r $ONOS_ROOT/tools/package/etc/* $ONOS_STAGE/$KARAF_DIST/etc
33
34 # Stage all builtin ONOS apps for factory install
35 onos-stage-apps $ONOS_STAGE/apps $ONOS_STAGE/$KARAF_DIST/system
36
37 # Mark the org.onosproject.drivers app active by default
38 touch $ONOS_STAGE/apps/org.onosproject.drivers/active
39
40 # Patch-in proper Karaf version into the startup script
41 sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
42 $ONOS_ROOT/tools/package/bin/onos-service > bin/onos-service
43 sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
44 $ONOS_ROOT/tools/package/bin/onos-client > bin/onos
45 chmod a+x bin/onos-service bin/onos
46
47 # Stage the ONOS bundles, but only those that match the version
48 mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject
49 find $M2_REPO/org/onosproject -type f -path "*/$ONOS_POM_VERSION/*" \
50 -name '*.jar' -o -name '*.pom' -o -name '*-features.xml' \
51 | grep -v -Ee '-tests.jar|-[0-9]{8}.[0-9]{6}-' \
52 | while read src; do
53 dst=$ONOS_STAGE/$KARAF_DIST/system/${src#$M2_REPO/*}
54 mkdir -p $(dirname $dst)
55 cp $src $dst
56 done
57
58 # ONOS Patching ----------------------------------------------------------------
59
60 # Patch the Apache Karaf distribution file to add ONOS features repository
61 perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \
62 $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
63
64 # Patch the Apache Karaf distribution file to load default ONOS boot features
65 export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui"
66 perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \
67 $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
68
69 # Patch the Apache Karaf distribution with ONOS branding bundle
70 cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-*.jar \
71 $ONOS_STAGE/$KARAF_DIST/lib
72
73 # Patch in the ONOS version file
74 echo $ONOS_VERSION > $ONOS_STAGE/VERSION
75}
76
77function build_compressed_package() {
78 # Package up the ONOS tar file
79 cd $ONOS_STAGE_ROOT
80 rm -f $ONOS_TAR $ONOS_ZIP
81 COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS
82
83 # Figure out whether we should build ONOS zip file and if so, build it.
84 which zip >/dev/null && [ -z "$ONOS_TAR_ONLY" ] && buildZip=true || unset buildZip
85 [ -n "$buildZip" ] && zip -rq $ONOS_ZIP $ONOS_BITS
86
87 # Report on the archives that were built and clean-up
88 [ -n "$buildZip" ] && ls -lh $ONOS_TAR $ONOS_ZIP || ls -lh $ONOS_TAR
89 rm -r $ONOS_STAGE
90}
91
92# Build a DEB package
93function build_deb() {
94 echo "You need to be root in order to generate a proper DEB package."
95
96 sudo rm -fr $ONOS_DEB_ROOT
97
98 mkdir -p $ONOS_DEB_ROOT/DEBIAN
99 mkdir -p $ONOS_DEB_ROOT/opt/
100 mkdir -p $ONOS_DEB_ROOT/etc/init
101
102 {
103 echo "Package: onos"
104 echo "Architecture: all"
105 echo "Maintainer: ONOS Project"
106 echo "Depends: debconf (>= 0.5.00), default-jre-headless (>= 1.8) | openjdk-8-jre | oracle-java8-installer"
107 echo "Priority: optional"
108 echo "Version: $ONOS_POM_VERSION"
109 echo "Description: Open Network Operating System (ONOS) is an"
110 echo " opensource SDN controller."
111 } > $ONOS_DEB_ROOT/DEBIAN/control
112
113 cp -r $ONOS_STAGE $ONOS_DEB_ROOT/opt/onos
114 cp $ONOS_ROOT/tools/package/debian/onos.conf $ONOS_DEB_ROOT/etc/init/
115
116 mkdir -p $ONOS_DEB_ROOT/opt/onos/var/
117
118 sudo chown -R root:root $ONOS_DEB_ROOT
119
120 sudo dpkg-deb --build $ONOS_DEB_ROOT > /dev/null &&
121 sudo mv $ONOS_STAGE_ROOT/deb.deb $ONOS_DEB && ls -l $ONOS_DEB
122}
123
124# Script entry point
tom5c255702014-09-18 06:57:39 -0700125[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
126. $ONOS_ROOT/tools/build/envDefaults
tom4d0c6632014-09-15 23:27:01 -0700127
128# Bail on any errors
129set -e
130
Luca Pretee6183752015-07-29 01:55:50 -0700131# Before starting make sure the environment is clan - delete onos staging folder
132rm -fr $ONOS_STAGE
tom4d0c6632014-09-15 23:27:01 -0700133
Luca Pretee6183752015-07-29 01:55:50 -0700134# If there are parameters check if we want to build a deb - otherwise build tar.gz
135case ${1:---tar} in
136 "--tar") build_stage_dir
137 build_compressed_package
138 ;;
139 "--deb") build_stage_dir
140 build_deb
141 ;;
142 *) echo "usage: $(basename $0) [--tar|--deb]" >&2 && exit 1
143 ;;
144esac