Carmelo Cascone | ada7b5b | 2019-04-23 13:50:03 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | ONOS_TAR=~/onos.tar.gz |
| 4 | |
| 5 | [ -f $ONOS_TAR ] || (echo "$ONOS_TAR not found" && exit 1) |
| 6 | |
| 7 | ONOS_DIR=/tmp/$(tar tf $ONOS_TAR | head -n 1 | cut -d/ -f1) |
| 8 | |
| 9 | # Kill any running instances |
| 10 | ps -ef | grep apache.karaf.main.Main | grep -v grep | awk '{print $2}' | xargs kill -9 &>/dev/null |
| 11 | |
| 12 | # Do not tolerate any errors from this point onward |
| 13 | set -e |
| 14 | |
| 15 | echo "Running clean installation..." |
| 16 | # Blitz previously unrolled onos- directory |
| 17 | rm -fr $ONOS_DIR |
| 18 | # Unroll new image from the specified tar file |
| 19 | [ -f $ONOS_TAR ] && tar zxf $ONOS_TAR -C /tmp |
| 20 | |
| 21 | echo "Configuring password-less CLI access..." |
| 22 | # Run using the secure SSH client |
| 23 | [ ! -f ~/.ssh/id_rsa.pub ] && (echo "Missing SSH public key (~/.ssh/id_rsa.pub), please generate one using ssh-keygen"; exit 1) |
| 24 | $ONOS_DIR/bin/onos-user-key $(id -un) "$(cut -d\ -f2 ~/.ssh/id_rsa.pub)" |
| 25 | $ONOS_DIR/bin/onos-user-password onos rocks |
| 26 | |
| 27 | # Create config/cluster.json (cluster metadata) |
| 28 | IP=${ONOS_IP:-127.0.0.1} |
| 29 | echo "Creating local cluster configs for IP $IP..." |
| 30 | [ -d $ONOS_DIR/config ] || mkdir -p $ONOS_DIR/config |
| 31 | cat > $ONOS_DIR/config/cluster.json <<-EOF |
| 32 | { |
| 33 | "name": "default-$RANDOM", |
| 34 | "node": { |
| 35 | "id": "$IP", |
| 36 | "ip": "$IP", |
| 37 | "port": 9876 |
| 38 | }, |
| 39 | "clusterSecret": "$RANDOM" |
| 40 | } |
| 41 | EOF |
| 42 | |
| 43 | # Change into the ONOS home directory |
| 44 | cd $ONOS_DIR |
| 45 | export ONOS_HOME=$PWD |
| 46 | |
| 47 | # Start ONOS as a server, but include any specified options |
| 48 | ./bin/onos-service server "$@" |