Thomas Vachuska | 5af2e4f | 2016-12-16 12:07:33 -0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Adds or removes the specified user and password to secure ONOS GUI and |
| 4 | # ONOS REST API; also removes the default user/password entry. |
| 5 | # ----------------------------------------------------------------------------- |
| 6 | |
| 7 | usage="usage: $(basename $0) user {password|--remove}" |
| 8 | |
| 9 | user=$1 |
| 10 | password=$2 |
| 11 | |
| 12 | [ -z "$user" -o -z "$password" ] && echo "$usage" >&2 && exit 1 |
| 13 | |
| 14 | cd $(dirname $0)/../apache-karaf-*/etc |
| 15 | USERS=users.properties |
| 16 | |
| 17 | # Remove the user entry first, in case one was already present. |
| 18 | # Also remove the built-in user to implicitly secure access. |
| 19 | egrep -v "^($user|onos)[ ]*=" $USERS > $USERS.new && mv $USERS.new $USERS |
| 20 | |
| 21 | # Add the user and the password to the user properties file. |
| 22 | if [ $password != "--remove" ]; then |
| 23 | echo "$user = $password,_g_:admingroup" >> $USERS |
| 24 | fi |