blob: 59b8fa9bc0aa245c337fa5e11beb83d133491a4f [file] [log] [blame]
Thomas Vachuska5630c612015-03-24 12:24:12 -07001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Downloads and sets-up Apache Karaf as a basis for running ONOS locally
4# as a single-instance.
Thomas Vachuskafcd61142015-04-23 13:59:08 -07005#
6# Note that this in no way impacts the method for running ONOS remotely.
7# For that, one should use onos-package and onos-install tools.
Thomas Vachuska5630c612015-03-24 12:24:12 -07008# -----------------------------------------------------------------------------
9
10[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
11. $ONOS_ROOT/tools/build/envDefaults
12
Thomas Vachuska5905f2c2016-10-21 09:46:35 -070013echo "This command is deprecated and will be removed imminently!!!"
14echo "Please use 'buck run onos-local' instead."
15echo "e.g.: buck run onos-local -- clean debug"
16echo " or: buck run onos-local -- debug"
17
Thomas Vachuska5630c612015-03-24 12:24:12 -070018# TODO: consider putting this under ~/Applications/onos/apache-karaf-...
19export KARAF_ROOT=${KARAF_ROOT:-~/Applications/apache-karaf-$KARAF_VERSION}
20export STAGE=$(dirname $KARAF_ROOT)
21
Thomas Vachuska60fc8422015-04-23 16:18:34 -070022# Validates the specified IP regular expression against existing adapters.
23# Excludes local-loopback.
24function validateIp {
Charles Chan4ba6b552016-06-02 19:04:31 +080025 ifconfig | sed -ne 's:[[:space:]]*inet[^6][ adr:]*\([0-9.]*\).*:\1: p' | grep $1
Thomas Vachuska60fc8422015-04-23 16:18:34 -070026}
27
Brian O'Connorbcfc0542015-12-09 22:26:45 -080028# Parse optional arguments
29while [[ $# > 0 ]]; do
Thomas Vachuskabc833672016-01-04 15:12:50 -080030 case $1 in
Brian O'Connorbcfc0542015-12-09 22:26:45 -080031 clean)
Thomas Vachuskabc833672016-01-04 15:12:50 -080032 CLEAN="true";;
Brian O'Connorbcfc0542015-12-09 22:26:45 -080033 secure)
Thomas Vachuskabc833672016-01-04 15:12:50 -080034 SECURE="true";;
Brian O'Connorbcfc0542015-12-09 22:26:45 -080035 *)
Thomas Vachuskabc833672016-01-04 15:12:50 -080036 break;;
37 esac
38 shift
Brian O'Connorbcfc0542015-12-09 22:26:45 -080039done
Thomas Vachuska5630c612015-03-24 12:24:12 -070040
Thomas Vachuskaba082b82015-05-20 13:47:38 -070041ONOS_IP=${ONOS_IP:-127.0.0.1}
Thomas Vachuskafcd61142015-04-23 13:59:08 -070042IP="${1:-$ONOS_IP}"
43
Thomas Vachuskabc833672016-01-04 15:12:50 -080044# If the installed version does not line-up with ONOS_POM_VERSION force clean install
45if [ ! -f $KARAF_ROOT/etc/org.apache.karaf.features.cfg ] || \
46 ! grep -q "mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features" \
47 $KARAF_ROOT/etc/org.apache.karaf.features.cfg; then
48 echo "Existing ONOS Karaf uses version different from $ONOS_POM_VERSION; forcing clean install..."
49 CLEAN="true"
50fi
51
52# If clean option was specified, wipe-out existing installation
53if [ "$CLEAN" = "true" ]; then
Jian Licc752fa2016-03-25 18:15:22 -070054 echo "Removing existing ONOS Karaf, apps, data and config directories..."
Yuta HIGUCHI7f2c6f92016-07-04 19:52:52 -070055 [ -d $KARAF_ROOT ] && rm -fr $KARAF_ROOT $KARAF_ROOT/data $STAGE/apps $STAGE/data $STAGE/config
Thomas Vachuskabc833672016-01-04 15:12:50 -080056fi
57
Thomas Vachuskafcd61142015-04-23 13:59:08 -070058# If IP was not given, nor configured attempt to use ONOS_NIC env. variable
59if [ -z "$IP" -a -n "$ONOS_NIC" ]; then
Thomas Vachuska60fc8422015-04-23 16:18:34 -070060 IP=$(validateIp $ONOS_NIC)
Thomas Vachuskafcd61142015-04-23 13:59:08 -070061 [ -z "$IP" ] && echo "No adapter with IP matching $ONOS_NIC found!"
62else
63 # Otherwise, verify that the IP address given exists among the adapters.
64 saveIp=$IP
Thomas Vachuska60fc8422015-04-23 16:18:34 -070065 IP=$(validateIp $IP)
Thomas Vachuskafcd61142015-04-23 13:59:08 -070066 [ -z "$IP" ] && echo "No adapter with IP $saveIp found!"
67fi
68
69# If IP is still not surmised or if usage was requested, show usage and IPs.
70if [ -z "$IP" -o "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]; then
Brian O'Connorbcfc0542015-12-09 22:26:45 -080071 echo "usage: $(basename $0) [clean] [secure] <ip-address>"
Thomas Vachuska5630c612015-03-24 12:24:12 -070072 echo "Available IP addresses are:"
Thomas Vachuska60fc8422015-04-23 16:18:34 -070073 validateIp .
Thomas Vachuska5630c612015-03-24 12:24:12 -070074 exit 1
75fi
76
Thomas Vachuska5630c612015-03-24 12:24:12 -070077SUBNET="$(echo $IP | cut -d. -f1-3)"
78
79# Bail on any errors
80set -e
81
82# Check if Apache Karaf is already installed.
83if [ ! -d $KARAF_ROOT ]; then
84 # Check if Apache Karaf bits are available and if not, fetch them.
85 if [ ! -f $KARAF_TAR ]; then
86 echo "Downloading $KARAF_TAR..."
HIGUCHI Yuta9fe56ce2015-11-20 10:24:01 -080087 curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz --create-dirs -o $KARAF_TAR
Thomas Vachuska5630c612015-03-24 12:24:12 -070088 fi
89 [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \
90 echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1
91
92 echo "Unpacking $KARAF_TAR to $STAGE..."
93 mkdir -p $STAGE
94 cd $STAGE
95 tar zxf $KARAF_TAR
96 rm -rf $KARAF_ROOT/demos
97fi
98
Brian O'Connorbcfc0542015-12-09 22:26:45 -080099if [ "$SECURE" = "true" ]; then
100 echo "Enabling security mode ONOS..."
101
102 # SM-ONOS step 1: downgrade felix config admin
103 FELIX_CFG_ADMIN=${FELIX_CFG_ADMIN:-~/Downloads/org.apache.felix.configadmin-1.6.0.jar}
104 if [ ! -f $FELIX_CFG_ADMIN ]; then
105 echo "Downloading $FELIX_CFG_ADMIN..."
106 curl -sL http://archive.apache.org/dist/felix/org.apache.felix.configadmin-1.6.0.jar > $FELIX_CFG_ADMIN
107 fi
108 [ ! -f $FELIX_CFG_ADMIN ] && \
109 echo "Felix config admin not found: $FELIX_CFG_ADMIN" && exit 1
110
111 mkdir -p $KARAF_ROOT/system/org/apache/felix/org.apache.felix.configadmin/1.6.0
112 cp $FELIX_CFG_ADMIN $KARAF_ROOT/system/org/apache/felix/org.apache.felix.configadmin/1.6.0
Changhoon Yoona68e6f92016-05-02 15:36:43 +0900113 perl -pi.old -e "s|^(.*org.apache.felix.configadmin.*)|mvn\\\\:org.apache.felix/org.apache.felix.configadmin/1.6.0 = 10|" \
Brian O'Connorbcfc0542015-12-09 22:26:45 -0800114 $KARAF_ROOT/etc/startup.properties
115
116 # SM-ONOS step 2: stage ONOS Felix framework security (will get downloaded on demand); end
117
118 # SM-ONOS step 3.1: configure karaf
119 perl -pi.old -e "s|#java.security.policy|java.security.policy|" \
120 $KARAF_ROOT/etc/system.properties
121 perl -pi.old -e "s|#org.osgi.framework.security|org.osgi.framework.security|" \
122 $KARAF_ROOT/etc/system.properties
123fi
124
Thomas Vachuska5630c612015-03-24 12:24:12 -0700125if ! grep -q "/onos-features/" $KARAF_ROOT/etc/org.apache.karaf.features.cfg; then
126 # Patch the Apache Karaf distribution file to add ONOS features repository
127 echo "Adding ONOS feature repository..."
Brian O'Connorfa5e0762016-04-08 15:51:34 -0700128 perl -pi.old -e "s|^(featuresRepositories=.*)|featuresRepositories=mvn:org.apache.karaf.features/standard/$KARAF_VERSION/xml/features,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \
Thomas Vachuska5630c612015-03-24 12:24:12 -0700129 $KARAF_ROOT/etc/org.apache.karaf.features.cfg
130fi
131
132if ! grep -q ",onos-api," $KARAF_ROOT/etc/org.apache.karaf.features.cfg; then
133 # Patch the Apache Karaf distribution file to load default ONOS boot features
Brian O'Connorfa5e0762016-04-08 15:51:34 -0700134 BOOT_FEATURES="standard,ssh,webconsole"
Brian O'Connorbcfc0542015-12-09 22:26:45 -0800135 if [ "$SECURE" = "true" ]; then
136 # SM-ONOS Step 3.2: add onos-security to featuresBoot
Brian O'Connorfa5e0762016-04-08 15:51:34 -0700137 BOOT_FEATURES="$BOOT_FEATURES,onos-security"
Brian O'Connorbcfc0542015-12-09 22:26:45 -0800138 fi
Brian O'Connorfa5e0762016-04-08 15:51:34 -0700139 BOOT_FEATURES="$BOOT_FEATURES,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui"
Thomas Vachuska5630c612015-03-24 12:24:12 -0700140 echo "Adding ONOS boot features $BOOT_FEATURES..."
Brian O'Connorfa5e0762016-04-08 15:51:34 -0700141 perl -pi.old -e "s|^(featuresBoot=.*)|featuresBoot=$BOOT_FEATURES|" \
Thomas Vachuska5630c612015-03-24 12:24:12 -0700142 $KARAF_ROOT/etc/org.apache.karaf.features.cfg
143fi
144
145if [ ! -f $KARAF_ROOT/lib/onos-branding-$ONOS_POM_VERSION.jar ]; then
146 # Patch the Apache Karaf distribution with ONOS branding bundle
147 echo "Branding as ONOS..."
148 rm -f $KARAF_ROOT/lib/onos-branding-*.jar
149 cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-$ONOS_POM_VERSION.jar \
150 $KARAF_ROOT/lib
151fi
152
Thomas Vachuska9b171c52015-04-28 12:01:07 -0700153echo "Creating local cluster configs for IP $IP..."
154[ -d $STAGE/config ] || mkdir -p $STAGE/config
155cat > $STAGE/config/cluster.json <<EOF
Madan Jampani596f2662015-10-23 14:35:23 -0700156{
157 "name": "default",
158 "nodes": [ {"id": "$IP", "ip": "$IP", "port": 9876 } ],
Madan Jampani597282a2016-06-04 09:23:17 -0700159 "partitions": [ { "id": 1, "members": [ "$IP" ] } ]
Madan Jampani596f2662015-10-23 14:35:23 -0700160}
Thomas Vachuska5630c612015-03-24 12:24:12 -0700161EOF
Thomas Vachuska5630c612015-03-24 12:24:12 -0700162
Jonathan Hart2aa40682015-08-03 10:53:51 -0700163if [ "$CLEAN" = "true" ]; then
164 echo "Copying package configs..."
165 cp -r $ONOS_ROOT/tools/package/etc/* $KARAF_ROOT/etc/
166 cp -r $ONOS_ROOT/tools/package/config/* $STAGE/config/
167fi
168
Thomas Vachuskac4cb1002015-03-29 10:28:26 -0700169echo "Staging builtin apps..."
170rm -fr $STAGE/apps
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -0700171onos-stage-apps $STAGE/apps $KARAF_ROOT/system
Thomas Vachuskac4cb1002015-03-29 10:28:26 -0700172
Thomas Vachuskafcd61142015-04-23 13:59:08 -0700173ACTIVE_APPS=${ONOS_APPS:-drivers,openflow}
174echo "Customizing apps to be auto-activated: $ACTIVE_APPS..."
175for app in ${ACTIVE_APPS//,/ }; do
Thomas Vachuskac4cb1002015-03-29 10:28:26 -0700176 touch $STAGE/apps/org.onosproject.$app/active
177done