Thomas Vachuska | 12bf445 | 2015-06-26 09:15:38 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Secures the ONOS console for all instances in the cell ONOS cluster. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
| 6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 7 | . $ONOS_ROOT/tools/build/envDefaults |
| 8 | |
Thomas Vachuska | 3534933 | 2016-04-04 14:06:46 -0700 | [diff] [blame] | 9 | # Scan arguments for user/password or other options... |
| 10 | while getopts u:p: o; do |
| 11 | case "$o" in |
| 12 | u) user=$OPTARG;; |
| 13 | p) password=$OPTARG;; |
| 14 | esac |
| 15 | done |
| 16 | password=${password:-$user} # password defaults to the user if not specified |
| 17 | let OPC=$OPTIND-1 |
| 18 | shift $OPC |
| 19 | |
Thomas Vachuska | cf7ce3b | 2018-08-20 09:34:08 -0700 | [diff] [blame] | 20 | user=${user:-$ONOS_WEB_USER} |
| 21 | password=${password:-$ONOS_WEB_PASS} |
Claudine Chiu | 45312d0 | 2016-06-15 13:17:12 +0000 | [diff] [blame] | 22 | nodes=${1:-$(env | sort | egrep "^OC[0-9]+" | cut -d= -f2)} |
Thomas Vachuska | 12bf445 | 2015-06-26 09:15:38 -0700 | [diff] [blame] | 23 | |
Yuta HIGUCHI | 0410712 | 2017-01-13 18:51:12 -0800 | [diff] [blame] | 24 | # ensure known_hosts file exist |
| 25 | (umask 077; touch "$HOME/.ssh/known_hosts") |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 26 | set -x |
Thomas Vachuska | 12bf445 | 2015-06-26 09:15:38 -0700 | [diff] [blame] | 27 | for node in $nodes; do |
Thomas Vachuska | 12bf445 | 2015-06-26 09:15:38 -0700 | [diff] [blame] | 28 | # Setup passwordless login for the local user on the remote node |
| 29 | ssh $ONOS_USER@$node " |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 30 | set -x |
Thomas Vachuska | 12bf445 | 2015-06-26 09:15:38 -0700 | [diff] [blame] | 31 | [ ! -f ~/.ssh/id_rsa.pub ] && ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' -q |
| 32 | $ONOS_INSTALL_DIR/bin/onos-user-key \$(id -un) \$(cut -d\\ -f2 ~/.ssh/id_rsa.pub) |
Thomas Vachuska | 5af2e4f | 2016-12-16 12:07:33 -0800 | [diff] [blame] | 33 | $ONOS_INSTALL_DIR/bin/onos-user-password $user $password |
Thomas Vachuska | 12bf445 | 2015-06-26 09:15:38 -0700 | [diff] [blame] | 34 | |
| 35 | # Implicitly accept the new server key in dev/test environments |
| 36 | while ! ssh -p 8101 -o StrictHostKeyChecking=no localhost list 2>/dev/null; do |
| 37 | echo Waiting for connection... |
| 38 | sleep 1 |
| 39 | done |
| 40 | " |
Charles Chan | 2497dbe | 2015-10-14 17:08:56 -0700 | [diff] [blame] | 41 | |
| 42 | # Setup passwordless login for the remote user on the local bench host |
| 43 | # For now, we let the local public key override the remote one |
| 44 | # TODO: fix username collision between workbench and the remote hosts |
| 45 | onos-user-key $node |
Thomas Vachuska | 12bf445 | 2015-06-26 09:15:38 -0700 | [diff] [blame] | 46 | done |