blob: 4576aa04fd4b890cb92f63a3f9e33d9c4bb70577 [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
Thomas Vachuska6066dff2016-10-26 13:57:36 -07006[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
7cd $ONOS_ROOT && onos-buck build onos --show-output && onos-check-bits
8exit $?
9
10#=============================================================================
11
12# FIXME: This needs to be refactored using Buck; for now it is disabled
13# FIXME: .deb, .rpm, .zip need to be re-implemented
14# FIXME: SM-ONOS packaging flavour needs to be re-implemented
15
Brian O'Connorf5d93632015-09-04 20:18:31 -070016set -e
17
Luca Pretee6183752015-07-29 01:55:50 -070018# Build the staging directory used to produce the packages
19function build_stage_dir() {
20 # Make sure we have the original apache karaf bits first
21 [ ! -d $M2_REPO ] && echo "M2 repository $M2_REPO not found" && exit 1
22 [ -d $ONOS_STAGE ] && echo "ONOS stage $ONOS_STAGE already exists" && exit 1
23
24 # Create the stage directory and warp into it
25 mkdir -p $ONOS_STAGE
26 cd $ONOS_STAGE
27
28 # Check if Apache Karaf bits are available and if not, fetch them.
29 if [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ]; then
30 echo "Downloading $KARAF_TAR..."
31 curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR
32 fi
33 [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \
34 echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1
35
36 # Unroll the Apache Karaf bits, prune them and make ONOS top-level directories.
37 [ -f $KARAF_ZIP ] && unzip -q $KARAF_ZIP && rm -rf $ONOS_STAGE/$KARAF_DIST/demos
38 [ -f $KARAF_TAR ] && tar zxf $KARAF_TAR && rm -rf $ONOS_STAGE/$KARAF_DIST/demos
39 mkdir bin
40
Thomas Vachuska08ab6a62015-09-23 16:55:45 -070041 # Patch the log-file size in place to increase it to 10 MB
42 perl -pi.old -e "s/maxFileSize=1MB/maxFileSize=10MB/g" \
43 $ONOS_STAGE/$KARAF_DIST/etc/org.ops4j.pax.logging.cfg
44
Luca Pretee6183752015-07-29 01:55:50 -070045 # Stage the ONOS admin scripts and patch in Karaf service wrapper extras
46 cp -r $ONOS_ROOT/tools/package/bin .
Brian O'Connor0eed29e2015-09-16 11:38:33 -070047 cp -r $ONOS_ROOT/tools/package/init $ONOS_STAGE/init
Luca Pretee6183752015-07-29 01:55:50 -070048 cp -r $ONOS_ROOT/tools/package/etc/* $ONOS_STAGE/$KARAF_DIST/etc
49
50 # Stage all builtin ONOS apps for factory install
51 onos-stage-apps $ONOS_STAGE/apps $ONOS_STAGE/$KARAF_DIST/system
52
53 # Mark the org.onosproject.drivers app active by default
54 touch $ONOS_STAGE/apps/org.onosproject.drivers/active
55
56 # Patch-in proper Karaf version into the startup script
57 sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
58 $ONOS_ROOT/tools/package/bin/onos-service > bin/onos-service
59 sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
60 $ONOS_ROOT/tools/package/bin/onos-client > bin/onos
61 chmod a+x bin/onos-service bin/onos
62
Thomas Vachuska8c9ee812015-11-24 17:29:37 -080063 if [ -d $ONOS_ROOT/tools/package/karaf-assembly/target/repo ]; then
64 cp -r $ONOS_ROOT/tools/package/karaf-assembly/target/repo/* $ONOS_STAGE/$KARAF_DIST/system
Brian O'Connoreca5bbc2015-12-05 00:55:58 -080065 #FIXME we need to add onos-features manually
66 mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject/onos-features/$ONOS_POM_VERSION
67 cp $M2_REPO/org/onosproject/onos-features/$ONOS_POM_VERSION/onos-features* \
68 $ONOS_STAGE/$KARAF_DIST/system/org/onosproject/onos-features/$ONOS_POM_VERSION
Thomas Vachuska8c9ee812015-11-24 17:29:37 -080069 else
70 # TODO: Deprecated so remove when confident staging works.
71 # Stage the ONOS bundles, but only those that match the version
72 mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject
73 find $M2_REPO/org/onosproject -type f -path "*/$ONOS_POM_VERSION/*" \
74 \( -name '*.jar' -o -name '*.pom' -o -name '*-features.xml' \) \
75 | grep -v -Ee '-tests.jar|-[0-9]{8}.[0-9]{6}-' \
76 | while read src; do
77 dst=$ONOS_STAGE/$KARAF_DIST/system/${src#$M2_REPO/*}
78 mkdir -p $(dirname $dst)
79 cp $src $dst
80 done
81 fi
Luca Pretee6183752015-07-29 01:55:50 -070082
83 # ONOS Patching ----------------------------------------------------------------
84
Brian O'Connordfe13c82015-09-01 22:02:52 -070085 export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui"
86
87 [ "$ONOS_SECURITY_MODE" = true ] && enable_security_mode
88
Luca Pretee6183752015-07-29 01:55:50 -070089 # Patch the Apache Karaf distribution file to add ONOS features repository
90 perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \
91 $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
92
93 # Patch the Apache Karaf distribution file to load default ONOS boot features
Luca Pretee6183752015-07-29 01:55:50 -070094 perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \
95 $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
96
97 # Patch the Apache Karaf distribution with ONOS branding bundle
98 cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-*.jar \
99 $ONOS_STAGE/$KARAF_DIST/lib
100
101 # Patch in the ONOS version file
102 echo $ONOS_VERSION > $ONOS_STAGE/VERSION
103}
104
Brian O'Connordfe13c82015-09-01 22:02:52 -0700105function clean_stage_dir() {
106 [ -d "$ONOS_STAGE" ] && rm -r $ONOS_STAGE || :
107}
108
109function enable_security_mode() {
110 echo "Enabling security mode ONOS..."
111
112 # SM-ONOS step 1: downgrade felix config admin
113 FELIX_CFG_ADMIN=${FELIX_CFG_ADMIN:-~/Downloads/org.apache.felix.configadmin-1.6.0.jar}
114 if [ ! -f $FELIX_CFG_ADMIN ]; then
115 echo "Downloading $FELIX_CFG_ADMIN..."
116 curl -sL http://archive.apache.org/dist/felix/org.apache.felix.configadmin-1.6.0.jar > $FELIX_CFG_ADMIN
117 fi
118 [ ! -f $FELIX_CFG_ADMIN ] && \
119 echo "Felix config admin not found: $FELIX_CFG_ADMIN" && exit 1
120
121 mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/apache/felix/org.apache.felix.configadmin/1.6.0
122 cp $FELIX_CFG_ADMIN $ONOS_STAGE/$KARAF_DIST/system/org/apache/felix/org.apache.felix.configadmin/1.6.0
Changhoon Yoona68e6f92016-05-02 15:36:43 +0900123 perl -pi.old -e "s|^(.*org.apache.felix.configadmin.*)|mvn\\\\:org.apache.felix/org.apache.felix.configadmin/1.6.0 = 10|" \
Brian O'Connordfe13c82015-09-01 22:02:52 -0700124 $ONOS_STAGE/$KARAF_DIST/etc/startup.properties
125
126 # SM-ONOS step 2: stage ONOS Felix framework security (this is already done by karaf assembly); end
127
128 # SM-ONOS step 3.1: configure karaf
129 perl -pi.old -e "s|#java.security.policy|java.security.policy|" \
130 $ONOS_STAGE/$KARAF_DIST/etc/system.properties
131 perl -pi.old -e "s|#org.osgi.framework.security|org.osgi.framework.security|" \
132 $ONOS_STAGE/$KARAF_DIST/etc/system.properties
133
134 # SM-ONOS step 3.2: update featuresBoot
135 export BOOT_FEATURES="onos-security,$BOOT_FEATURES"
136}
137
138function build_compressed_zip() {
Luca Pretee6183752015-07-29 01:55:50 -0700139 cd $ONOS_STAGE_ROOT
Brian O'Connordfe13c82015-09-01 22:02:52 -0700140 rm -f $ONOS_ZIP
141 which zip >/dev/null && zip -rq $ONOS_ZIP $ONOS_BITS && ls -lh $ONOS_ZIP
142}
Luca Pretee6183752015-07-29 01:55:50 -0700143
Brian O'Connordfe13c82015-09-01 22:02:52 -0700144function build_compressed_tar() {
145 cd $ONOS_STAGE_ROOT
146 rm -f $ONOS_TAR
147 COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS && ls -lh $ONOS_TAR
Luca Pretee6183752015-07-29 01:55:50 -0700148}
149
150# Build a DEB package
Luca Pretef2049d12015-08-01 14:48:01 -0700151function build_deb() {
Brian O'Connor8a0c20e2015-09-16 22:54:24 -0700152 echo "This command may ask for your password to run commands as sudo,"
153 echo " because you need to be root in order to generate a proper DEB package."
Luca Pretee6183752015-07-29 01:55:50 -0700154
155 sudo rm -fr $ONOS_DEB_ROOT
156
Luca Pretef2049d12015-08-01 14:48:01 -0700157 mkdir -p $ONOS_DEB_ROOT/{DEBIAN,opt,etc/init}
Luca Pretee6183752015-07-29 01:55:50 -0700158
Brian O'Connor8a0c20e2015-09-16 22:54:24 -0700159 # Copy the debian directory and fill in version
160 cp -r $ONOS_ROOT/tools/package/deb/* $ONOS_DEB_ROOT/DEBIAN/
161 sed -i'' -E "s/@ONOS_POM_VERSION/$ONOS_POM_VERSION/" $ONOS_DEB_ROOT/DEBIAN/control
Luca Pretee6183752015-07-29 01:55:50 -0700162
163 cp -r $ONOS_STAGE $ONOS_DEB_ROOT/opt/onos
Brian O'Connor0eed29e2015-09-16 11:38:33 -0700164 cp $ONOS_ROOT/tools/package/init/onos.conf $ONOS_DEB_ROOT/etc/init/
Luca Pretee6183752015-07-29 01:55:50 -0700165
166 mkdir -p $ONOS_DEB_ROOT/opt/onos/var/
167
168 sudo chown -R root:root $ONOS_DEB_ROOT
Luca Pretef2049d12015-08-01 14:48:01 -0700169
Luca Pretee6183752015-07-29 01:55:50 -0700170 sudo dpkg-deb --build $ONOS_DEB_ROOT > /dev/null &&
171 sudo mv $ONOS_STAGE_ROOT/deb.deb $ONOS_DEB && ls -l $ONOS_DEB
Brian O'Connor8a0c20e2015-09-16 22:54:24 -0700172
173 #TODO run lintian on .deb
Luca Pretee6183752015-07-29 01:55:50 -0700174}
175
Luca Pretef2049d12015-08-01 14:48:01 -0700176# Build an RPM package
177function build_rpm() {
178 read -r -p "WARN: rpm-build utility and root priviledges are need to build the package. Do you want to continue? [Y/n] " response
Brian O'Connorac322442015-09-17 23:49:17 -0700179 [[ "$response" =~ ^[Nn] ]] && exit 0
Luca Pretef2049d12015-08-01 14:48:01 -0700180
Brian O'Connorac322442015-09-17 23:49:17 -0700181 sudo rm -fr $ONOS_RPM_ROOT
Luca Pretef2049d12015-08-01 14:48:01 -0700182
Brian O'Connorac322442015-09-17 23:49:17 -0700183 sudo yum -y install rpm-build
Luca Pretef2049d12015-08-01 14:48:01 -0700184
Brian O'Connorac322442015-09-17 23:49:17 -0700185 mkdir -p $ONOS_RPM_ROOT/{BUILD,RPMS,SOURCES/onos-$ONOS_RPM_VERSION/{etc/init,opt},SPECS,SRPMS}
Luca Pretef2049d12015-08-01 14:48:01 -0700186
Brian O'Connorac322442015-09-17 23:49:17 -0700187 cp -r $ONOS_STAGE $ONOS_RPM_ROOT/SOURCES/onos-$ONOS_RPM_VERSION/opt/onos
188 cp $ONOS_ROOT/tools/package/init/onos.conf $ONOS_RPM_ROOT/SOURCES/onos-$ONOS_RPM_VERSION/etc/init/
Luca Pretef2049d12015-08-01 14:48:01 -0700189
Brian O'Connorac322442015-09-17 23:49:17 -0700190 cd $ONOS_RPM_ROOT/SOURCES
191 COPYFILE_DISABLE=1 tar zcf onos-$ONOS_RPM_VERSION.tar.gz onos-$ONOS_RPM_VERSION
Luca Pretef2049d12015-08-01 14:48:01 -0700192
Brian O'Connorac322442015-09-17 23:49:17 -0700193 cp $ONOS_ROOT/tools/package/rpm/onos.spec $ONOS_RPM_ROOT/SPECS/
194 sed -i'' -E "s/@ONOS_RPM_VERSION/$ONOS_RPM_VERSION/g" $ONOS_RPM_ROOT/SPECS/onos.spec
Luca Pretef2049d12015-08-01 14:48:01 -0700195
Brian O'Connorac322442015-09-17 23:49:17 -0700196 rpmbuild --define "_topdir $ONOS_RPM_ROOT" -bb $ONOS_RPM_ROOT/SPECS/onos.spec
197
198 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
Luca Pretef2049d12015-08-01 14:48:01 -0700199}
200
Luca Pretee6183752015-07-29 01:55:50 -0700201# Script entry point
tom5c255702014-09-18 06:57:39 -0700202[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
203. $ONOS_ROOT/tools/build/envDefaults
tom4d0c6632014-09-15 23:27:01 -0700204
205# Bail on any errors
206set -e
207
Brian O'Connordfe13c82015-09-01 22:02:52 -0700208[[ $# == 0 ]] && ONOS_PACKAGE_TAR_arg=true
209while [[ $# > 0 ]]; do
210case $1 in
211 -t|--tar)
212 ONOS_PACKAGE_TAR_arg=true
213 ;;
214 -z|--zip)
215 ONOS_PACKAGE_ZIP_arg=true
216 ;;
217 -d|--deb)
218 ONOS_PACKAGE_DEB_arg=true
219 ;;
220 -r|--rpm)
221 ONOS_PACKAGE_RPM_arg=true
222 ;;
223 -s|--secure)
224 ONOS_SECURITY_MODE=true
225 ;;
226 *)
227 # unknown option
228 echo "Unknown options: $1"
229 echo "usage: $(basename $0) [--tar] [--zip] [--deb] [--rpm] [--secure]" >&2 && exit 1
230 ;;
231esac
232shift
233done
234
Brian O'Connor37c486f2015-12-14 20:28:48 -0800235#TODO consider moving this block to build_stage_dir
Thomas Vachuska82082052015-12-04 16:12:45 -0800236# Run karaf assembly to collect artifacts for off-line installations.
237aux=/tmp/assembly-$$.log
238trap "rm -f $aux 2>/dev/null" EXIT
Brian O'Connor37c486f2015-12-14 20:28:48 -0800239#TODO possibly merge with MAVEN_OPTS, also M2_REPO must be set for the reasons
240[ -n "$M2_REPO" ] && args="-Dmaven.repo.local=$M2_REPO" || args=""
241cd $ONOS_ROOT/tools/package/karaf-assembly &&
242 mvn $args clean install > $aux 2>&1 ||
Brian O'Connor68498e22016-01-04 14:02:03 -0800243 ( cat $aux &&
244 printf "\nFailed to run karaf-assembly, which stages artifacts for offline deployments.\n" &&
245 exit 1 )
Thomas Vachuska82082052015-12-04 16:12:45 -0800246
Luca Pretee6183752015-07-29 01:55:50 -0700247# Before starting make sure the environment is clan - delete onos staging folder
Brian O'Connordfe13c82015-09-01 22:02:52 -0700248clean_stage_dir
tom4d0c6632014-09-15 23:27:01 -0700249
Brian O'Connordfe13c82015-09-01 22:02:52 -0700250build_stage_dir
251[ "$ONOS_PACKAGE_TAR_arg" = true ] && build_compressed_tar
252[ "$ONOS_PACKAGE_ZIP_arg" = true ] && build_compressed_zip
253[ "$ONOS_PACKAGE_DEB_arg" = true ] && build_deb
254[ "$ONOS_PACKAGE_RPM_arg" = true ] && build_rpm
255clean_stage_dir