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