3 # This file is part of openvim
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
18 # For those usages not covered by the Apache License, Version 2.0 please
19 # contact with: nfvlabs@tid.es
21 # Authors: Leonardo Mirabal
27 echo -e "Usage: sudo $0 <user-name> "
28 echo -e " Configure dhcp server for VIM usage. (version 1.0). Params:"
29 echo -e " <user-name> Create if not exist and configure this user for openvim to connect"
30 echo -e " -h --help this help"
34 function _install_packages_dependencies
()
36 # Required packages by openvim
38 apt-get
-y install ethtool build-essential dnsmasq openvswitch-switch
39 echo "Remove unneeded packages....."
43 function _add_user_to_visudo
()
45 # Allow admin users to access without password
46 if ! grep -q "#openmano" /etc
/sudoers
48 cat >> /home
/${option_user}/script_visudo.sh
<< EOL
50 echo "#openmano allow to group admin to grant root privileges without password" >> \$1
51 echo "${option_user} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
53 chmod +x
/home
/${option_user}/script_visudo.sh
54 echo "allowing admin user to get root privileges withut password"
55 export EDITOR
=/home
/${option_user}/script_visudo.sh
&& sudo
-E visudo
56 rm -f /home
/${option_user}/script_visudo.sh
61 function _create_ovs_controller_config_path
() {
62 mkdir
-p '/var/lib/openvim'
65 function _install_user
() {
66 # create user given by the user and add to groups need it.
70 # Adds user, default password same as name
71 if grep -q "^${option_user}:" /etc
/passwd
73 #user exist, add to group
74 echo "adding user ${option_user} to group admin"
75 usermod
-a -G admin
-g admin
${option_user}
77 #create user if it does not exist
78 [ -z "$FORCE" ] && read -p "user '${option_user}' does not exist, create (Y/n)" kk
79 if ! [ -z "$kk" -o "$kk"="y" -o "$kk"="Y" ]
83 echo "creating and configuring user ${option_user}"
84 useradd
-m -G admin
-g admin
${option_user}
88 echo "Provide a password for ${option_user}"
91 echo -e "$option_user\n$option_user" | passwd
--stdin ${option_user}
100 #1.2 input parameters
102 while getopts "h" o
; do
120 [ -z "$1" ] && echo -e "ERROR: User argument is mandatory, --user=<user>\n" && _usage
124 #check root privileges
125 [ "${USER}" != "root" ] && echo "Needed root privileges" >&2 && exit 2
129 #################################################################
130 ##### INSTALL USER #####
131 #################################################################'
137 #################################################################
138 ##### INSTALL NEEDED PACKETS #####
139 #################################################################'
140 _install_packages_dependencies
142 _create_ovs_controller_config_path
145 echo "Do not forget to copy the public ssh key into /home/${option_user}/.ssh/authorized_keys for authomatic login from openvim controller"
148 echo "Reboot the system to make the changes effective"