blob: ec496f6867b5ac1562cf1e267896fd15123de32e [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
Jimmy Ou6daae942017-06-13 13:25:47 +080026# ensure .ssh directory and known_hosts file exist
27mkdir -p $HOME/.ssh/
Yuta HIGUCHI04107122017-01-13 18:51:12 -080028(umask 077; touch "$HOME/.ssh/known_hosts")
29
Thomas Vachuska5af2e4f2016-12-16 12:07:33 -080030# Also, remove any previous known keys for the localhost.
31ssh-keygen -f "$HOME/.ssh/known_hosts" -R [localhost]:8101