blob: 9a6aff36ed2f197e4daea1d935d09b862f26baab [file] [log] [blame]
Thomas Vachuska12bf4452015-06-26 09:15:38 -07001#!/bin/bash
2# -----------------------------------------------------------------------------
Thomas Vachuska5af2e4f2016-12-16 12:07:33 -08003# Adds or removes a user key for managing passwordless login to ONOS console.
Thomas Vachuska12bf4452015-06-26 09:15:38 -07004# -----------------------------------------------------------------------------
5
Thomas Vachuska5af2e4f2016-12-16 12:07:33 -08006usage="usage: $(basename $0) user {key|key-file|--remove}"
7
8[ $# -lt 2 ] && echo "$usage" >&2 && exit 1
Thomas Vachuska12bf4452015-06-26 09:15:38 -07009
10set -e
11
12user=$1
13[ -f $2 ] && key=$(cut -d\ -f2 $2) || key=$2
14
Thomas Vachuska5af2e4f2016-12-16 12:07:33 -080015[ -z "$user" -o -z "$key" ] && echo "$usage" >&2 && exit 1
16
Thomas Vachuska12bf4452015-06-26 09:15:38 -070017cd $(dirname $0)/../apache-karaf-*/etc
18KEYS=keys.properties
19
20# Remove the user key first, in case one was already present
Thomas Vachuska5af2e4f2016-12-16 12:07:33 -080021egrep -v "^($user|karaf)[ ]*=" $KEYS > $KEYS.new && mv $KEYS.new $KEYS
22if [ $key != "--remove" ]; then
Thomas Vachuska12bf4452015-06-26 09:15:38 -070023 echo "$user=$key,_g_:admingroup" >> $KEYS
24fi
Thomas Vachuska5af2e4f2016-12-16 12:07:33 -080025
26# Also, remove any previous known keys for the localhost.
27ssh-keygen -f "$HOME/.ssh/known_hosts" -R [localhost]:8101
28