Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Downloads and sets-up Apache Karaf as a basis for running ONOS locally |
| 4 | # as a single-instance. |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 5 | # |
| 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 Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 8 | # ----------------------------------------------------------------------------- |
| 9 | |
| 10 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 11 | . $ONOS_ROOT/tools/build/envDefaults |
| 12 | |
| 13 | # TODO: consider putting this under ~/Applications/onos/apache-karaf-... |
| 14 | export KARAF_ROOT=${KARAF_ROOT:-~/Applications/apache-karaf-$KARAF_VERSION} |
| 15 | export STAGE=$(dirname $KARAF_ROOT) |
| 16 | |
Thomas Vachuska | 60fc842 | 2015-04-23 16:18:34 -0700 | [diff] [blame] | 17 | # Validates the specified IP regular expression against existing adapters. |
| 18 | # Excludes local-loopback. |
| 19 | function validateIp { |
Roan Huang | ddf315d | 2015-04-30 22:54:48 +0800 | [diff] [blame^] | 20 | ifconfig | awk '{ print $2}' | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | grep -v "127\.0\.0\.1" | grep $1 |
Thomas Vachuska | 60fc842 | 2015-04-23 16:18:34 -0700 | [diff] [blame] | 21 | } |
| 22 | |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 23 | # Clean the previous Karaf directory if requested and if it exists. |
| 24 | if [ "$1" = "clean" ]; then |
| 25 | shift |
| 26 | [ -d $KARAF_ROOT ] && rm -fr $KARAF_ROOT $STAGE/apps $STAGE/config |
| 27 | fi |
| 28 | |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 29 | IP="${1:-$ONOS_IP}" |
| 30 | |
| 31 | # If IP was not given, nor configured attempt to use ONOS_NIC env. variable |
| 32 | if [ -z "$IP" -a -n "$ONOS_NIC" ]; then |
Thomas Vachuska | 60fc842 | 2015-04-23 16:18:34 -0700 | [diff] [blame] | 33 | IP=$(validateIp $ONOS_NIC) |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 34 | [ -z "$IP" ] && echo "No adapter with IP matching $ONOS_NIC found!" |
| 35 | else |
| 36 | # Otherwise, verify that the IP address given exists among the adapters. |
| 37 | saveIp=$IP |
Thomas Vachuska | 60fc842 | 2015-04-23 16:18:34 -0700 | [diff] [blame] | 38 | IP=$(validateIp $IP) |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 39 | [ -z "$IP" ] && echo "No adapter with IP $saveIp found!" |
| 40 | fi |
| 41 | |
| 42 | # If IP is still not surmised or if usage was requested, show usage and IPs. |
| 43 | if [ -z "$IP" -o "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]; then |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 44 | echo "usage: $(basename $0) [clean] <ip-address>" |
| 45 | echo "Available IP addresses are:" |
Thomas Vachuska | 60fc842 | 2015-04-23 16:18:34 -0700 | [diff] [blame] | 46 | validateIp . |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 47 | exit 1 |
| 48 | fi |
| 49 | |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 50 | SUBNET="$(echo $IP | cut -d. -f1-3)" |
| 51 | |
| 52 | # Bail on any errors |
| 53 | set -e |
| 54 | |
| 55 | # Check if Apache Karaf is already installed. |
| 56 | if [ ! -d $KARAF_ROOT ]; then |
| 57 | # Check if Apache Karaf bits are available and if not, fetch them. |
| 58 | if [ ! -f $KARAF_TAR ]; then |
| 59 | echo "Downloading $KARAF_TAR..." |
| 60 | curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR |
| 61 | fi |
| 62 | [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \ |
| 63 | echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1 |
| 64 | |
| 65 | echo "Unpacking $KARAF_TAR to $STAGE..." |
| 66 | mkdir -p $STAGE |
| 67 | cd $STAGE |
| 68 | tar zxf $KARAF_TAR |
| 69 | rm -rf $KARAF_ROOT/demos |
| 70 | fi |
| 71 | |
| 72 | if ! grep -q "/onos-features/" $KARAF_ROOT/etc/org.apache.karaf.features.cfg; then |
| 73 | # Patch the Apache Karaf distribution file to add ONOS features repository |
| 74 | echo "Adding ONOS feature repository..." |
| 75 | perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \ |
| 76 | $KARAF_ROOT/etc/org.apache.karaf.features.cfg |
| 77 | fi |
| 78 | |
| 79 | if ! grep -q ",onos-api," $KARAF_ROOT/etc/org.apache.karaf.features.cfg; then |
| 80 | # Patch the Apache Karaf distribution file to load default ONOS boot features |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 81 | export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-cli,onos-rest,onos-gui" |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 82 | echo "Adding ONOS boot features $BOOT_FEATURES..." |
| 83 | perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \ |
| 84 | $KARAF_ROOT/etc/org.apache.karaf.features.cfg |
| 85 | fi |
| 86 | |
| 87 | if [ ! -f $KARAF_ROOT/lib/onos-branding-$ONOS_POM_VERSION.jar ]; then |
| 88 | # Patch the Apache Karaf distribution with ONOS branding bundle |
| 89 | echo "Branding as ONOS..." |
| 90 | rm -f $KARAF_ROOT/lib/onos-branding-*.jar |
| 91 | cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-$ONOS_POM_VERSION.jar \ |
| 92 | $KARAF_ROOT/lib |
| 93 | fi |
| 94 | |
Thomas Vachuska | 9b171c5 | 2015-04-28 12:01:07 -0700 | [diff] [blame] | 95 | echo "Creating local cluster configs for IP $IP..." |
| 96 | [ -d $STAGE/config ] || mkdir -p $STAGE/config |
| 97 | cat > $STAGE/config/cluster.json <<EOF |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 98 | { "ipPrefix": "$SUBNET.*", |
| 99 | "nodes":[ { "id": "$IP", "ip": "$IP", "tcpPort": 9876 }]} |
| 100 | EOF |
| 101 | |
Thomas Vachuska | 9b171c5 | 2015-04-28 12:01:07 -0700 | [diff] [blame] | 102 | cat > $STAGE/config/tablets.json <<EOF |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 103 | { "nodes": [ { "ip": "$IP", "id": "$IP", "tcpPort": 7238 }], |
| 104 | "partitions": { "p1": [ { "ip": "$IP", "id": "$IP", "tcpPort": 7238 }]}} |
| 105 | EOF |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 106 | |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 107 | echo "Setting up hazelcast.xml for subnet $SUBNET.*..." |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 108 | cp $ONOS_ROOT/tools/package/etc/hazelcast.xml $KARAF_ROOT/etc/hazelcast.xml |
| 109 | perl -pi.old -e "s/192.168.56/$SUBNET/" $KARAF_ROOT/etc/hazelcast.xml |
| 110 | perl -pi.old -e "s/ <name>onos</ <name>$IP</" $KARAF_ROOT/etc/hazelcast.xml |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 111 | |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 112 | echo "Staging builtin apps..." |
| 113 | rm -fr $STAGE/apps |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 114 | onos-stage-apps $STAGE/apps $KARAF_ROOT/system |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 115 | |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 116 | ACTIVE_APPS=${ONOS_APPS:-drivers,openflow} |
| 117 | echo "Customizing apps to be auto-activated: $ACTIVE_APPS..." |
| 118 | for app in ${ACTIVE_APPS//,/ }; do |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 119 | touch $STAGE/apps/org.onosproject.$app/active |
| 120 | done |