| # ----------------------------------------------------------------------------- |
| # Adds or removes a user key for managing passwordless login to ONOS console. |
| # ----------------------------------------------------------------------------- |
| usage="usage: $(basename $0) user {key|key-file|--remove}" |
| [ $# -lt 2 ] && echo "$usage" >&2 && exit 1 |
| [ -f $2 ] && key=$(cut -d\ -f2 $2) || key=$2 |
| [ -z "$user" -o -z "$key" ] && echo "$usage" >&2 && exit 1 |
| cd $(dirname $0)/../apache-karaf-*/etc |
| # Remove the user key first, in case one was already present |
| egrep -v "^($user|karaf)[ ]*=" $KEYS > $KEYS.new && mv $KEYS.new $KEYS |
| if [ $key != "--remove" ]; then |
| echo "$user=$key,_g_:admingroup" >> $KEYS |
| # ensure .ssh directory and known_hosts file exist |
| (umask 077; touch "$HOME/.ssh/known_hosts") |
| # Also, remove any previous known keys for the localhost. |
| which ssh-keygen >/dev/null && ssh-keygen -f "$HOME/.ssh/known_hosts" -R [localhost]:8101 |