blob: c707206e008397977beff5a41f0bf17280c2fa69 [file] [log] [blame]
Brian O'Connor9e1352f2016-04-29 17:13:33 -07001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Packages ONOS distributable into onos.tar.gz, onos.zip or a deb file
4# -----------------------------------------------------------------------------
5
Ray Milkeyd84f89b2018-08-17 14:54:17 -07006set -eu -o pipefail
Brian O'Connor9e1352f2016-04-29 17:13:33 -07007
8OUT=$1
Ray Milkey3f274d92018-09-28 14:23:34 -07009KARAF_TAR=$2
Brian O'Connor9e1352f2016-04-29 17:13:33 -070010ONOS_VERSION=$3
11BRANDING=$4
Thomas Vachuska9e6432c2018-04-20 22:26:19 -070012KARAF_PATCHES=$5
Daniele Morocc41a942020-02-03 23:33:55 -080013LOG4J2_EXTRA=$6
14SANDBOX=${7:-.}
Thomas Vachuska0f956032018-06-12 10:41:12 -070015
Ray Milkeyda746332020-07-06 11:30:36 -070016KARAF_VERSION="4.2.9"
Heedo Kang611a0652017-09-05 12:26:30 +090017ONOS_SECURITY_MODE="false"
Brian O'Connor92ec2132016-05-03 17:30:25 -070018
Brian O'Connor35007342016-09-13 17:41:16 -070019PREFIX="onos-$ONOS_VERSION"
Brian O'Connor9e1352f2016-04-29 17:13:33 -070020
21# Unroll the Apache Karaf bits, prune them and make ONOS top-level directories.
22tar xf $KARAF_TAR
23
Yuta HIGUCHI6771ef62017-12-19 11:37:48 -080024# rename path name to match what was distributed with vicci
Ray Milkeyd84f89b2018-08-17 14:54:17 -070025# mv "$(ls -d apache*)" "apache-karaf-$KARAF_VERSION" || true
Yuta HIGUCHI6771ef62017-12-19 11:37:48 -080026
Ray Milkeyd84f89b2018-08-17 14:54:17 -070027#tar xf $KARAF_PATCHES
Thomas Vachuska9e6432c2018-04-20 22:26:19 -070028
Brian O'Connor9e1352f2016-04-29 17:13:33 -070029# Unroll the Apache Karaf bits, prune them and make ONOS top-level directories.
Charles Chan209edb12020-09-04 19:50:57 -070030export KARAF_DIR=$(ls -d apache*)
Brian O'Connor9e1352f2016-04-29 17:13:33 -070031rm -rf $KARAF_DIR/demos
32
33# Patch the log-file size in place to increase it to 10 MB
34perl -pi.old -e "s/maxFileSize=1MB/maxFileSize=10MB/g" \
35 $KARAF_DIR/etc/org.ops4j.pax.logging.cfg
36
Andrea Campanelladd54d562020-10-07 16:44:21 +020037# Patch the fileinstall to avoid NPE when filter is null
Andrea Campanella8479dd12020-10-19 10:44:15 +020038echo "felix.fileinstall.filter='\\*.jar'" >> \
Andrea Campanelladd54d562020-10-07 16:44:21 +020039 $KARAF_DIR/etc/org.apache.felix.fileinstall-deploy.cfg
40
Brian O'Connor9e1352f2016-04-29 17:13:33 -070041# Patch-in proper Karaf version into the startup script
Charles Chan209edb12020-09-04 19:50:57 -070042perl -pi.bk -e 's/apache-karaf-\$KARAF_VERSION/$ENV{KARAF_DIR}/g' $SANDBOX/bin/onos-service
Ray Milkeyf83e4222018-08-08 07:46:51 -070043
44# hack - need to break the link to the script in the source tree for bazel
Charles Chan209edb12020-09-04 19:50:57 -070045perl -pi.bk -e 's/apache-karaf-\$KARAF_VERSION/$ENV{KARAF_DIR}/g' $SANDBOX/bin/onos
Ray Milkeyf83e4222018-08-08 07:46:51 -070046
Charles Chan209edb12020-09-04 19:50:57 -070047rm -f $SANDBOX/bin/*.bk
Thomas Vachuska0f956032018-06-12 10:41:12 -070048chmod a+x $SANDBOX/bin/onos-service $SANDBOX/bin/onos
Brian O'Connor9e1352f2016-04-29 17:13:33 -070049
Brian O'Connor9e1352f2016-04-29 17:13:33 -070050# Patch the Apache Karaf distribution with ONOS branding bundle
Thomas Vachuska8fcd2042018-06-12 12:00:16 -070051cp $BRANDING $KARAF_DIR/lib/onos-tools-package-branding.jar
Brian O'Connor9e1352f2016-04-29 17:13:33 -070052
Brian O'Connor92ec2132016-05-03 17:30:25 -070053# **** Moving karaf to subdirectory ****
54mkdir $PREFIX
55mv $KARAF_DIR $PREFIX
56
57# Stage the ONOS admin scripts and patch in Karaf service wrapper extras
Thomas Vachuska0f956032018-06-12 10:41:12 -070058cp -r $SANDBOX/bin $PREFIX
59cp -r $SANDBOX/runtime/bin/* $PREFIX/bin/
60cp -r $SANDBOX/init $PREFIX
61cp -r $SANDBOX/etc/* $PREFIX/$KARAF_DIR/etc/
Brian O'Connor92ec2132016-05-03 17:30:25 -070062
Daniele Morocc41a942020-02-03 23:33:55 -080063ONOS_VERSION_POINT=$(echo ${ONOS_VERSION} | sed -E 's/-/./')
64
Ray Milkeyd84f89b2018-08-17 14:54:17 -070065# Fix the onos version string in the features config
66sed -i".VERBACK" -E "s/.ONOS_VERSION/${ONOS_VERSION}/" $PREFIX/$KARAF_DIR/etc/org.apache.karaf.features.cfg
Daniele Morocc41a942020-02-03 23:33:55 -080067# Fix onos version in startup properties
68sed -i".VERBACK" "s/.ONOS_VERSION/${ONOS_VERSION_POINT}/" $PREFIX/$KARAF_DIR/etc/startup.properties
69
70# Add log4j2-extra Bundle
71mkdir -p $PREFIX/$KARAF_DIR/system/org/onosproject/onos-log4j2-extra/$ONOS_VERSION_POINT/
72cp $LOG4J2_EXTRA $PREFIX/$KARAF_DIR/system/org/onosproject/onos-log4j2-extra/$ONOS_VERSION_POINT/onos-log4j2-extra-$ONOS_VERSION_POINT.jar
Ray Milkeyd84f89b2018-08-17 14:54:17 -070073
Heedo Kang611a0652017-09-05 12:26:30 +090074if [ "$ONOS_SECURITY_MODE" = true ]
75then
76 # ONOS Patching ----------------------------------------------------------------
77
78 echo "Enabling security mode ONOS..."
79
80 # SM-ONOS step 1: downgrade felix config admin
81 FELIX_CFG_ADMIN=${FELIX_CFG_ADMIN:-~/Downloads/org.apache.felix.configadmin-1.6.0.jar}
82 if [ ! -f $FELIX_CFG_ADMIN ]; then
83 echo "Downloading $FELIX_CFG_ADMIN..."
84 curl -sL http://archive.apache.org/dist/felix/org.apache.felix.configadmin-1.6.0.jar > $FELIX_CFG_ADMIN
85 fi
86 [ ! -f $FELIX_CFG_ADMIN ] && \
87 echo "Felix config admin not found: $FELIX_CFG_ADMIN" && exit 1
88
89 mkdir -p $PREFIX/$KARAF_DIR/system/org/apache/felix/org.apache.felix.configadmin/1.6.0
90 cp $FELIX_CFG_ADMIN $PREFIX/$KARAF_DIR/system/org/apache/felix/org.apache.felix.configadmin/1.6.0
91 perl -pi.old -e "s|org.apache.felix.configadmin/1.8.4|org.apache.felix.configadmin/1.6.0|g" \
92 $PREFIX/$KARAF_DIR/etc/startup.properties
93
94 # SM-ONOS step 2: stage ONOS Felix framework security (this is already done by karaf assembly); end
95
96 # SM-ONOS step 3.1: configure karaf
97 perl -pi.old -e "s|#java.security.policy|java.security.policy|" \
98 $PREFIX/$KARAF_DIR/etc/system.properties
99 perl -pi.old -e "s|#org.osgi.framework.security|org.osgi.framework.security|" \
100 $PREFIX/$KARAF_DIR/etc/system.properties
101
102 # SM-ONOS step 3.2: update featuresBoot
103 export BOOT_FEATURES="onos-security,$BOOT_FEATURES"
104
105 # Patch the Apache Karaf distribution file to load onos security feature
106 perl -pi.old -e "s|^(featuresBoot=).*|\1$BOOT_FEATURES|" \
107 $PREFIX/$KARAF_DIR/etc/org.apache.karaf.features.cfg
108fi
109
Brian O'Connor65c0bdf2016-05-03 18:40:17 -0700110zip -q -0 -r $OUT $PREFIX