blob: 269f959ae82e2323a9afae2b4bcf250b216e8c16 [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
Luca Pretef2049d12015-08-01 14:48:01 -070093function build_deb() {
Luca Pretee6183752015-07-29 01:55:50 -070094 echo "You need to be root in order to generate a proper DEB package."
95
96 sudo rm -fr $ONOS_DEB_ROOT
97
Luca Pretef2049d12015-08-01 14:48:01 -070098 mkdir -p $ONOS_DEB_ROOT/{DEBIAN,opt,etc/init}
Luca Pretee6183752015-07-29 01:55:50 -070099
100 {
Luca Pretef2049d12015-08-01 14:48:01 -0700101 echo "Package: ONOS"
Luca Pretee6183752015-07-29 01:55:50 -0700102 echo "Architecture: all"
103 echo "Maintainer: ONOS Project"
104 echo "Depends: debconf (>= 0.5.00), default-jre-headless (>= 1.8) | openjdk-8-jre | oracle-java8-installer"
105 echo "Priority: optional"
106 echo "Version: $ONOS_POM_VERSION"
107 echo "Description: Open Network Operating System (ONOS) is an"
108 echo " opensource SDN controller."
109 } > $ONOS_DEB_ROOT/DEBIAN/control
110
111 cp -r $ONOS_STAGE $ONOS_DEB_ROOT/opt/onos
112 cp $ONOS_ROOT/tools/package/debian/onos.conf $ONOS_DEB_ROOT/etc/init/
113
114 mkdir -p $ONOS_DEB_ROOT/opt/onos/var/
115
116 sudo chown -R root:root $ONOS_DEB_ROOT
Luca Pretef2049d12015-08-01 14:48:01 -0700117
Luca Pretee6183752015-07-29 01:55:50 -0700118 sudo dpkg-deb --build $ONOS_DEB_ROOT > /dev/null &&
119 sudo mv $ONOS_STAGE_ROOT/deb.deb $ONOS_DEB && ls -l $ONOS_DEB
120}
121
Luca Pretef2049d12015-08-01 14:48:01 -0700122# Build an RPM package
123function build_rpm() {
124 read -r -p "WARN: rpm-build utility and root priviledges are need to build the package. Do you want to continue? [Y/n] " response
125 case $response in
126 [nN][oO])
127 exit 0
128 ;;
129 *)
130 sudo rm -fr $ONOS_RPM_ROOT
131
132 sudo yum -y install rpm-build
133
134 mkdir -p $ONOS_RPM_ROOT/{BUILD,RPMS,SOURCES/ONOS-$ONOS_RPM_VERSION/{etc/init,opt},SPECS,SRPMS}
135
136 cp -r $ONOS_STAGE $ONOS_RPM_ROOT/SOURCES/ONOS-$ONOS_RPM_VERSION/opt/onos
137 cp $ONOS_ROOT/tools/package/debian/onos.conf $ONOS_RPM_ROOT/SOURCES/ONOS-$ONOS_RPM_VERSION/etc/init/
138
139 cd $ONOS_RPM_ROOT/SOURCES
140 COPYFILE_DISABLE=1 tar zcf ONOS-$ONOS_RPM_VERSION.tar.gz ONOS-$ONOS_RPM_VERSION
141
142 {
143 echo "Name: ONOS"
144 echo "Version: $ONOS_RPM_VERSION"
145 echo "Release: 1"
146 echo "Summary: Open Networking Operating System (ONOS)"
147 echo "Vendor: ONOS Project"
148 echo "Packager: ONOS Project"
149 echo "Group: Applications/Engineering"
150 echo "Requires: jre >= 1:8"
151 echo "License: Apache 2.0"
152 echo "URL: http://www.onosproject.org"
153 echo "Source0: ONOS-$ONOS_RPM_VERSION.tar.gz"
154 echo "BuildArch: noarch"
155 echo "BuildRoot: %{_tmppath}/%{name}-buildroot"
156 echo "%description"
157 echo "Open Network Operating System (ONOS) is an opensource SDN controller."
158 echo -e "\n"
159 echo "%prep"
160 echo "%setup -q"
161 echo -e "\n"
162 echo "%install"
163 echo "mkdir -p %{buildroot}"
164 echo "cp -R * %{buildroot}"
165 echo -e "\n"
166 echo "%clean"
167 echo "rm -rf %{buildroot}"
168 echo -e "\n"
169 echo "%files"
170 echo "%defattr(-,root,root,-)"
171 echo "/etc/init/onos.conf"
172 echo "/opt/onos/"
173 echo -e "\n"
174 echo "%post"
175 echo "echo ONOS successfully installed at /opt/onos"
176 } > $ONOS_RPM_ROOT/SPECS/onos.spec
177
178 rpmbuild --define "_topdir $ONOS_RPM_ROOT" -bb $ONOS_RPM_ROOT/SPECS/onos.spec
179
180 cp $ONOS_RPM_ROOT/RPMS/noarch/ONOS-$ONOS_RPM_VERSION-1.noarch.rpm $ONOS_STAGE_ROOT && ls -l $ONOS_STAGE_ROOT/ONOS-$ONOS_RPM_VERSION-1.noarch.rpm
181 ;;
182 esac
183}
184
Luca Pretee6183752015-07-29 01:55:50 -0700185# Script entry point
tom5c255702014-09-18 06:57:39 -0700186[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
187. $ONOS_ROOT/tools/build/envDefaults
tom4d0c6632014-09-15 23:27:01 -0700188
189# Bail on any errors
190set -e
191
Luca Pretee6183752015-07-29 01:55:50 -0700192# Before starting make sure the environment is clan - delete onos staging folder
193rm -fr $ONOS_STAGE
tom4d0c6632014-09-15 23:27:01 -0700194
Luca Pretef2049d12015-08-01 14:48:01 -0700195# If there are parameters check if we want to build a deb - otherwise build tar.gz
Luca Pretee6183752015-07-29 01:55:50 -0700196case ${1:---tar} in
Luca Pretef2049d12015-08-01 14:48:01 -0700197 "--tar" | "-T") build_stage_dir
198 build_compressed_package
Luca Pretee6183752015-07-29 01:55:50 -0700199 ;;
Luca Pretef2049d12015-08-01 14:48:01 -0700200 "--deb" | "-D") build_stage_dir
201 build_deb
Luca Pretee6183752015-07-29 01:55:50 -0700202 ;;
Luca Pretef2049d12015-08-01 14:48:01 -0700203 "--rpm" | "-R") build_stage_dir
204 build_rpm
205 ;;
206 *) echo "usage: $(basename $0) [--tar|--deb|--rpm]" >&2 && exit 1
Luca Pretee6183752015-07-29 01:55:50 -0700207 ;;
208esac