blob: 35508365a733fca56c7fadc248523aa35cd1b0ab [file] [log] [blame]
Carmelo Casconeada7b5b2019-04-23 13:50:03 -07001#!/usr/bin/env bash
2
3ONOS_TAR=~/onos.tar.gz
4
5[ -f $ONOS_TAR ] || (echo "$ONOS_TAR not found" && exit 1)
6
7ONOS_DIR=/tmp/$(tar tf $ONOS_TAR | head -n 1 | cut -d/ -f1)
8
9# Kill any running instances
10ps -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
13set -e
14
15echo "Running clean installation..."
16# Blitz previously unrolled onos- directory
17rm -fr $ONOS_DIR
18# Unroll new image from the specified tar file
19[ -f $ONOS_TAR ] && tar zxf $ONOS_TAR -C /tmp
20
21echo "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)
28IP=${ONOS_IP:-127.0.0.1}
29echo "Creating local cluster configs for IP $IP..."
30[ -d $ONOS_DIR/config ] || mkdir -p $ONOS_DIR/config
31cat > $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}
41EOF
42
43# Change into the ONOS home directory
44cd $ONOS_DIR
45export ONOS_HOME=$PWD
46
47# Start ONOS as a server, but include any specified options
48./bin/onos-service server "$@"