blob: ac94de5dac003c9baa345fdce1e09d4b48bff5a6 [file] [log] [blame]
Thomas Vachuska12bf4452015-06-26 09:15:38 -07001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Enables secure access to ONOS console by removing default users & keys.
4# -----------------------------------------------------------------------------
5
6rm -f $(dirname $0)/onos
7
8set -e
9
Thomas Vachuskaeff0e4e2015-08-11 00:26:24 -070010# Scan argument for user/password or other options...
11while getopts u:p: o; do
12 case "$o" in
13 u) user=$OPTARG;;
14 p) password=$OPTARG;;
15 esac
16done
17password=${password:-user} # password defaults to the user name if not specified
18let OPC=$OPTIND-1
19shift $OPC
20
Thomas Vachuska12bf4452015-06-26 09:15:38 -070021cd $(dirname $0)/../apache-karaf-*/etc
22USERS=users.properties
23KEYS=keys.properties
24
25# Remove the built-in users and keys to secure the access implicitly.
26egrep -v "^(karaf|onos)[ ]*=" $USERS > $USERS.new && mv $USERS.new $USERS
27egrep -v "^(#karaf|onos)[ ]*=" $KEYS > $KEYS.new && mv $KEYS.new $KEYS
28
29# Remove any previous known keys for the local host.
30ssh-keygen -f "$HOME/.ssh/known_hosts" -R [localhost]:8101
31
Thomas Vachuskaeff0e4e2015-08-11 00:26:24 -070032# Swap the onos client to use the SSH variant.
Thomas Vachuska12bf4452015-06-26 09:15:38 -070033ln -s $(dirname $0)/onos-ssh $(dirname $0)/onos
Thomas Vachuskaeff0e4e2015-08-11 00:26:24 -070034
35# If user and password options were given, setup the user/password.
36if [ -n "$user" -a -n "$password" ]; then
37 echo "$user = $password,_g_:admingroup" >> $USERS
38fi