blob: 56102cbe74c08eb3c39c0ca49d05005632e15734 [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.
5# -----------------------------------------------------------------------------
6
7[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
8. $ONOS_ROOT/tools/build/envDefaults
9
10# TODO: consider putting this under ~/Applications/onos/apache-karaf-...
11export KARAF_ROOT=${KARAF_ROOT:-~/Applications/apache-karaf-$KARAF_VERSION}
12export STAGE=$(dirname $KARAF_ROOT)
13
14# Clean the previous Karaf directory if requested and if it exists.
15if [ "$1" = "clean" ]; then
16 shift
17 [ -d $KARAF_ROOT ] && rm -fr $KARAF_ROOT $STAGE/apps $STAGE/config
18fi
19
20if [ -z $1 ]; then
21 echo "usage: $(basename $0) [clean] <ip-address>"
22 echo "Available IP addresses are:"
23 ifconfig | grep 'inet ' | cut -d\ -f2 | grep -v "127.0.0.1"
24 exit 1
25fi
26
27IP="$1"
28SUBNET="$(echo $IP | cut -d. -f1-3)"
29
30# Bail on any errors
31set -e
32
33# Check if Apache Karaf is already installed.
34if [ ! -d $KARAF_ROOT ]; then
35 # Check if Apache Karaf bits are available and if not, fetch them.
36 if [ ! -f $KARAF_TAR ]; then
37 echo "Downloading $KARAF_TAR..."
38 curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR
39 fi
40 [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \
41 echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1
42
43 echo "Unpacking $KARAF_TAR to $STAGE..."
44 mkdir -p $STAGE
45 cd $STAGE
46 tar zxf $KARAF_TAR
47 rm -rf $KARAF_ROOT/demos
48fi
49
50if ! grep -q "/onos-features/" $KARAF_ROOT/etc/org.apache.karaf.features.cfg; then
51 # Patch the Apache Karaf distribution file to add ONOS features repository
52 echo "Adding ONOS feature repository..."
53 perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \
54 $KARAF_ROOT/etc/org.apache.karaf.features.cfg
55fi
56
57if ! grep -q ",onos-api," $KARAF_ROOT/etc/org.apache.karaf.features.cfg; then
58 # Patch the Apache Karaf distribution file to load default ONOS boot features
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070059 export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-cli,onos-rest,onos-gui"
Thomas Vachuska5630c612015-03-24 12:24:12 -070060 echo "Adding ONOS boot features $BOOT_FEATURES..."
61 perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \
62 $KARAF_ROOT/etc/org.apache.karaf.features.cfg
63fi
64
65if [ ! -f $KARAF_ROOT/lib/onos-branding-$ONOS_POM_VERSION.jar ]; then
66 # Patch the Apache Karaf distribution with ONOS branding bundle
67 echo "Branding as ONOS..."
68 rm -f $KARAF_ROOT/lib/onos-branding-*.jar
69 cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-$ONOS_POM_VERSION.jar \
70 $KARAF_ROOT/lib
71fi
72
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070073if [ ! -d $STAGE/config ]; then
Thomas Vachuska5630c612015-03-24 12:24:12 -070074 echo "Creating local cluster configs for IP $IP..."
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070075 mkdir -p $STAGE/config
Thomas Vachuska5630c612015-03-24 12:24:12 -070076 cat > $STAGE/config/cluster.json <<EOF
77 { "ipPrefix": "$SUBNET.*",
78 "nodes":[ { "id": "$IP", "ip": "$IP", "tcpPort": 9876 }]}
79EOF
80
81 cat > $STAGE/config/tablets.json <<EOF
82 { "nodes": [ { "ip": "$IP", "id": "$IP", "tcpPort": 7238 }],
83 "partitions": { "p1": [ { "ip": "$IP", "id": "$IP", "tcpPort": 7238 }]}}
84EOF
85fi
86
87echo "Setting up hazelcast.xml for subnet $SUBNET..."
88cp $ONOS_ROOT/tools/package/etc/hazelcast.xml $KARAF_ROOT/etc/hazelcast.xml
89perl -pi.old -e "s/192.168.56/$SUBNET/" $KARAF_ROOT/etc/hazelcast.xml
90perl -pi.old -e "s/ <name>onos</ <name>$IP</" $KARAF_ROOT/etc/hazelcast.xml
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070091
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070092echo "Staging builtin apps..."
93rm -fr $STAGE/apps
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070094onos-stage-apps $STAGE/apps $KARAF_ROOT/system
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070095
96echo "Customizing apps to be auto-activated..."
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070097for app in $(echo ${ONOS_APPS:-openflow} | tr ',' ' '); do
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070098 touch $STAGE/apps/org.onosproject.$app/active
99done