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. |
| 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-... |
| 11 | export KARAF_ROOT=${KARAF_ROOT:-~/Applications/apache-karaf-$KARAF_VERSION} |
| 12 | export STAGE=$(dirname $KARAF_ROOT) |
| 13 | |
| 14 | # Clean the previous Karaf directory if requested and if it exists. |
| 15 | if [ "$1" = "clean" ]; then |
| 16 | shift |
| 17 | [ -d $KARAF_ROOT ] && rm -fr $KARAF_ROOT $STAGE/apps $STAGE/config |
| 18 | fi |
| 19 | |
| 20 | if [ -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 |
| 25 | fi |
| 26 | |
| 27 | IP="$1" |
| 28 | SUBNET="$(echo $IP | cut -d. -f1-3)" |
| 29 | |
| 30 | # Bail on any errors |
| 31 | set -e |
| 32 | |
| 33 | # Check if Apache Karaf is already installed. |
| 34 | if [ ! -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 |
| 48 | fi |
| 49 | |
| 50 | if ! 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 |
| 55 | fi |
| 56 | |
| 57 | if ! 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 Vachuska | 5167aad | 2015-03-25 11:29:07 -0700 | [diff] [blame] | 59 | export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow" |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 60 | 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 |
| 63 | fi |
| 64 | |
| 65 | if [ ! -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 |
| 71 | fi |
| 72 | |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame^] | 73 | if [ ! -d $STAGE/config ]; then |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 74 | echo "Creating local cluster configs for IP $IP..." |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame^] | 75 | mkdir -p $STAGE/config |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 76 | cat > $STAGE/config/cluster.json <<EOF |
| 77 | { "ipPrefix": "$SUBNET.*", |
| 78 | "nodes":[ { "id": "$IP", "ip": "$IP", "tcpPort": 9876 }]} |
| 79 | EOF |
| 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 }]}} |
| 84 | EOF |
| 85 | fi |
| 86 | |
| 87 | echo "Setting up hazelcast.xml for subnet $SUBNET..." |
| 88 | cp $ONOS_ROOT/tools/package/etc/hazelcast.xml $KARAF_ROOT/etc/hazelcast.xml |
| 89 | perl -pi.old -e "s/192.168.56/$SUBNET/" $KARAF_ROOT/etc/hazelcast.xml |
| 90 | 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^] | 91 | |
| 92 | |
| 93 | echo "Staging builtin apps..." |
| 94 | rm -fr $STAGE/apps |
| 95 | mkdir -p $STAGE/apps |
| 96 | find $ONOS_ROOT -name 'app.xml' | egrep -v '/src/test/|/target/|org\.foo\.' | \ |
| 97 | xargs grep 'name=' | sed 's/<app name="//g;s/".*//g' | while read line; do |
| 98 | appxml=${line%:*} |
| 99 | app=${line#*:} |
| 100 | mkdir $STAGE/apps/$app |
| 101 | cp $appxml $STAGE/apps/$app/app.xml |
| 102 | done |
| 103 | |
| 104 | echo "Customizing apps to be auto-activated..." |
| 105 | for app in $(echo $ONOS_APPS | tr ',' ' '); do |
| 106 | touch $STAGE/apps/org.onosproject.$app/active |
| 107 | done |