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