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 | |
Brian O'Connor | bcfc054 | 2015-12-09 22:26:45 -0800 | [diff] [blame] | 23 | # Parse optional arguments |
| 24 | while [[ $# > 0 ]]; do |
Thomas Vachuska | bc83367 | 2016-01-04 15:12:50 -0800 | [diff] [blame] | 25 | case $1 in |
Brian O'Connor | bcfc054 | 2015-12-09 22:26:45 -0800 | [diff] [blame] | 26 | clean) |
Thomas Vachuska | bc83367 | 2016-01-04 15:12:50 -0800 | [diff] [blame] | 27 | CLEAN="true";; |
Brian O'Connor | bcfc054 | 2015-12-09 22:26:45 -0800 | [diff] [blame] | 28 | secure) |
Thomas Vachuska | bc83367 | 2016-01-04 15:12:50 -0800 | [diff] [blame] | 29 | SECURE="true";; |
Brian O'Connor | bcfc054 | 2015-12-09 22:26:45 -0800 | [diff] [blame] | 30 | *) |
Thomas Vachuska | bc83367 | 2016-01-04 15:12:50 -0800 | [diff] [blame] | 31 | break;; |
| 32 | esac |
| 33 | shift |
Brian O'Connor | bcfc054 | 2015-12-09 22:26:45 -0800 | [diff] [blame] | 34 | done |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 35 | |
Thomas Vachuska | ba082b8 | 2015-05-20 13:47:38 -0700 | [diff] [blame] | 36 | ONOS_IP=${ONOS_IP:-127.0.0.1} |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 37 | IP="${1:-$ONOS_IP}" |
| 38 | |
Thomas Vachuska | bc83367 | 2016-01-04 15:12:50 -0800 | [diff] [blame] | 39 | # If the installed version does not line-up with ONOS_POM_VERSION force clean install |
| 40 | if [ ! -f $KARAF_ROOT/etc/org.apache.karaf.features.cfg ] || \ |
| 41 | ! grep -q "mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features" \ |
| 42 | $KARAF_ROOT/etc/org.apache.karaf.features.cfg; then |
| 43 | echo "Existing ONOS Karaf uses version different from $ONOS_POM_VERSION; forcing clean install..." |
| 44 | CLEAN="true" |
| 45 | fi |
| 46 | |
| 47 | # If clean option was specified, wipe-out existing installation |
| 48 | if [ "$CLEAN" = "true" ]; then |
Jian Li | cc752fa | 2016-03-25 18:15:22 -0700 | [diff] [blame] | 49 | echo "Removing existing ONOS Karaf, apps, data and config directories..." |
| 50 | [ -d $KARAF_ROOT ] && rm -fr $KARAF_ROOT $STAGE/apps $STAGE/data $STAGE/config |
Thomas Vachuska | bc83367 | 2016-01-04 15:12:50 -0800 | [diff] [blame] | 51 | fi |
| 52 | |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 53 | # If IP was not given, nor configured attempt to use ONOS_NIC env. variable |
| 54 | if [ -z "$IP" -a -n "$ONOS_NIC" ]; then |
Thomas Vachuska | 60fc842 | 2015-04-23 16:18:34 -0700 | [diff] [blame] | 55 | IP=$(validateIp $ONOS_NIC) |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 56 | [ -z "$IP" ] && echo "No adapter with IP matching $ONOS_NIC found!" |
| 57 | else |
| 58 | # Otherwise, verify that the IP address given exists among the adapters. |
| 59 | saveIp=$IP |
Thomas Vachuska | 60fc842 | 2015-04-23 16:18:34 -0700 | [diff] [blame] | 60 | IP=$(validateIp $IP) |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 61 | [ -z "$IP" ] && echo "No adapter with IP $saveIp found!" |
| 62 | fi |
| 63 | |
| 64 | # If IP is still not surmised or if usage was requested, show usage and IPs. |
| 65 | if [ -z "$IP" -o "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]; then |
Brian O'Connor | bcfc054 | 2015-12-09 22:26:45 -0800 | [diff] [blame] | 66 | echo "usage: $(basename $0) [clean] [secure] <ip-address>" |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 67 | echo "Available IP addresses are:" |
Thomas Vachuska | 60fc842 | 2015-04-23 16:18:34 -0700 | [diff] [blame] | 68 | validateIp . |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 69 | exit 1 |
| 70 | fi |
| 71 | |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 72 | SUBNET="$(echo $IP | cut -d. -f1-3)" |
| 73 | |
| 74 | # Bail on any errors |
| 75 | set -e |
| 76 | |
| 77 | # Check if Apache Karaf is already installed. |
| 78 | if [ ! -d $KARAF_ROOT ]; then |
| 79 | # Check if Apache Karaf bits are available and if not, fetch them. |
| 80 | if [ ! -f $KARAF_TAR ]; then |
| 81 | echo "Downloading $KARAF_TAR..." |
HIGUCHI Yuta | 9fe56ce | 2015-11-20 10:24:01 -0800 | [diff] [blame] | 82 | 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] | 83 | fi |
| 84 | [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \ |
| 85 | echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1 |
| 86 | |
| 87 | echo "Unpacking $KARAF_TAR to $STAGE..." |
| 88 | mkdir -p $STAGE |
| 89 | cd $STAGE |
| 90 | tar zxf $KARAF_TAR |
| 91 | rm -rf $KARAF_ROOT/demos |
| 92 | fi |
| 93 | |
Brian O'Connor | bcfc054 | 2015-12-09 22:26:45 -0800 | [diff] [blame] | 94 | if [ "$SECURE" = "true" ]; then |
| 95 | echo "Enabling security mode ONOS..." |
| 96 | |
| 97 | # SM-ONOS step 1: downgrade felix config admin |
| 98 | FELIX_CFG_ADMIN=${FELIX_CFG_ADMIN:-~/Downloads/org.apache.felix.configadmin-1.6.0.jar} |
| 99 | if [ ! -f $FELIX_CFG_ADMIN ]; then |
| 100 | echo "Downloading $FELIX_CFG_ADMIN..." |
| 101 | curl -sL http://archive.apache.org/dist/felix/org.apache.felix.configadmin-1.6.0.jar > $FELIX_CFG_ADMIN |
| 102 | fi |
| 103 | [ ! -f $FELIX_CFG_ADMIN ] && \ |
| 104 | echo "Felix config admin not found: $FELIX_CFG_ADMIN" && exit 1 |
| 105 | |
| 106 | mkdir -p $KARAF_ROOT/system/org/apache/felix/org.apache.felix.configadmin/1.6.0 |
| 107 | cp $FELIX_CFG_ADMIN $KARAF_ROOT/system/org/apache/felix/org.apache.felix.configadmin/1.6.0 |
Changhoon Yoon | a68e6f9 | 2016-05-02 15:36:43 +0900 | [diff] [blame] | 108 | perl -pi.old -e "s|^(.*org.apache.felix.configadmin.*)|mvn\\\\:org.apache.felix/org.apache.felix.configadmin/1.6.0 = 10|" \ |
Brian O'Connor | bcfc054 | 2015-12-09 22:26:45 -0800 | [diff] [blame] | 109 | $KARAF_ROOT/etc/startup.properties |
| 110 | |
| 111 | # SM-ONOS step 2: stage ONOS Felix framework security (will get downloaded on demand); end |
| 112 | |
| 113 | # SM-ONOS step 3.1: configure karaf |
| 114 | perl -pi.old -e "s|#java.security.policy|java.security.policy|" \ |
| 115 | $KARAF_ROOT/etc/system.properties |
| 116 | perl -pi.old -e "s|#org.osgi.framework.security|org.osgi.framework.security|" \ |
| 117 | $KARAF_ROOT/etc/system.properties |
| 118 | fi |
| 119 | |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 120 | if ! grep -q "/onos-features/" $KARAF_ROOT/etc/org.apache.karaf.features.cfg; then |
| 121 | # Patch the Apache Karaf distribution file to add ONOS features repository |
| 122 | echo "Adding ONOS feature repository..." |
Brian O'Connor | fa5e076 | 2016-04-08 15:51:34 -0700 | [diff] [blame] | 123 | 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 Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 124 | $KARAF_ROOT/etc/org.apache.karaf.features.cfg |
| 125 | fi |
| 126 | |
| 127 | if ! grep -q ",onos-api," $KARAF_ROOT/etc/org.apache.karaf.features.cfg; then |
| 128 | # Patch the Apache Karaf distribution file to load default ONOS boot features |
Brian O'Connor | fa5e076 | 2016-04-08 15:51:34 -0700 | [diff] [blame] | 129 | BOOT_FEATURES="standard,ssh,webconsole" |
Brian O'Connor | bcfc054 | 2015-12-09 22:26:45 -0800 | [diff] [blame] | 130 | if [ "$SECURE" = "true" ]; then |
| 131 | # SM-ONOS Step 3.2: add onos-security to featuresBoot |
Brian O'Connor | fa5e076 | 2016-04-08 15:51:34 -0700 | [diff] [blame] | 132 | BOOT_FEATURES="$BOOT_FEATURES,onos-security" |
Brian O'Connor | bcfc054 | 2015-12-09 22:26:45 -0800 | [diff] [blame] | 133 | fi |
Brian O'Connor | fa5e076 | 2016-04-08 15:51:34 -0700 | [diff] [blame] | 134 | BOOT_FEATURES="$BOOT_FEATURES,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui" |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 135 | echo "Adding ONOS boot features $BOOT_FEATURES..." |
Brian O'Connor | fa5e076 | 2016-04-08 15:51:34 -0700 | [diff] [blame] | 136 | perl -pi.old -e "s|^(featuresBoot=.*)|featuresBoot=$BOOT_FEATURES|" \ |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 137 | $KARAF_ROOT/etc/org.apache.karaf.features.cfg |
| 138 | fi |
| 139 | |
| 140 | if [ ! -f $KARAF_ROOT/lib/onos-branding-$ONOS_POM_VERSION.jar ]; then |
| 141 | # Patch the Apache Karaf distribution with ONOS branding bundle |
| 142 | echo "Branding as ONOS..." |
| 143 | rm -f $KARAF_ROOT/lib/onos-branding-*.jar |
| 144 | cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-$ONOS_POM_VERSION.jar \ |
| 145 | $KARAF_ROOT/lib |
| 146 | fi |
| 147 | |
Thomas Vachuska | 9b171c5 | 2015-04-28 12:01:07 -0700 | [diff] [blame] | 148 | echo "Creating local cluster configs for IP $IP..." |
| 149 | [ -d $STAGE/config ] || mkdir -p $STAGE/config |
| 150 | cat > $STAGE/config/cluster.json <<EOF |
Madan Jampani | 596f266 | 2015-10-23 14:35:23 -0700 | [diff] [blame] | 151 | { |
| 152 | "name": "default", |
| 153 | "nodes": [ {"id": "$IP", "ip": "$IP", "port": 9876 } ], |
Madan Jampani | ab7e7cd | 2016-01-14 14:02:32 -0800 | [diff] [blame] | 154 | "partitions": [ { "id": 0, "members": [ "$IP" ] }, { "id": 1, "members": [ "$IP" ] } ] |
Madan Jampani | 596f266 | 2015-10-23 14:35:23 -0700 | [diff] [blame] | 155 | } |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 156 | EOF |
Thomas Vachuska | 5630c61 | 2015-03-24 12:24:12 -0700 | [diff] [blame] | 157 | |
Jonathan Hart | 2aa4068 | 2015-08-03 10:53:51 -0700 | [diff] [blame] | 158 | if [ "$CLEAN" = "true" ]; then |
| 159 | echo "Copying package configs..." |
| 160 | cp -r $ONOS_ROOT/tools/package/etc/* $KARAF_ROOT/etc/ |
| 161 | cp -r $ONOS_ROOT/tools/package/config/* $STAGE/config/ |
| 162 | fi |
| 163 | |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 164 | echo "Staging builtin apps..." |
| 165 | rm -fr $STAGE/apps |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 166 | onos-stage-apps $STAGE/apps $KARAF_ROOT/system |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 167 | |
Thomas Vachuska | fcd6114 | 2015-04-23 13:59:08 -0700 | [diff] [blame] | 168 | ACTIVE_APPS=${ONOS_APPS:-drivers,openflow} |
| 169 | echo "Customizing apps to be auto-activated: $ACTIVE_APPS..." |
| 170 | for app in ${ACTIVE_APPS//,/ }; do |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 171 | touch $STAGE/apps/org.onosproject.$app/active |
| 172 | done |