blob: 46a99547e060ef2ea716eb774a36e1a0f901d606 [file] [log] [blame]
Sergio Slobodrianb92e5132017-09-13 13:04:05 -04001#!/bin/bash
Zack Williams41513bf2018-07-07 20:08:35 -07002# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
Sergio Slobodrianb92e5132017-09-13 13:04:05 -040015
16key="{{ key }}"
17
18lBlue='\033[1;34m'
19green='\033[0;32m'
20orange='\033[0;33m'
21NC='\033[0m'
22red='\033[0;31m'
23yellow='\033[1;33m'
24dGrey='\033[1;30m'
25lGrey='\033[1;37m'
26lCyan='\033[1;36m'
27
28
29if grep voltha /etc/passwd 2>&1 > /dev/null; then
30 echo -e "${yellow}WARNING:${lBlue}a ${yellow}voltha ${lBlue} user exists on the system!!"
31 echo -e "This account will be re-used by the installer. If you encounter any problems"
32 echo -e "please review the account setup to ensure it is correctly set up to run voltha."
33fi
34
35if [ -d /home/voltha ]; then
36 echo -e "${lBlue}A directory ${yellow}/home/voltha ${green}exists ${red}NOT ${lBlue}creating...${NC}"
37else
38 sudo mkdir /home/voltha
39fi
40
41if [ -f /home/voltha/.ssh/id_rsa ]; then
42 echo -e "${lBlue}A ssh key file ${yellow}/home/voltha/ssh/id_rsa ${green}exists ${red}NOT ${lBlue}creating...${NC}"
43else
44 mkdir voltha_ssh
45 ssh-keygen -f ~/voltha_ssh/id_rsa -t rsa -N ''
46 sudo mv voltha_ssh /home/voltha/.ssh
47fi
48
49if [ -f /etc/sudoers.d/voltha ]; then
50 echo -e "${lBlue}A sudoers file ${yellow}/etc/sudoers.d/voltha ${green}exists ${red}NOT ${lBlue}creating...${NC}"
51else
52 echo "voltha ALL=(ALL) NOPASSWD:ALL" > tmp
53 sudo chown root.root tmp
54 sudo mv tmp /etc/sudoers.d/voltha
55fi
56
57if sudo test -f /home/voltha/.ssh/authorized_keys ; then
58 sudo chmod ugo+w /home/voltha/.ssh/authorized_keys
59 echo $key > key.tmp
60 sudo cat key.tmp >> /home/voltha/.ssh/authorized_keys
61 rm key.tmp
62 sudo chmod 400 /home/voltha/.ssh/authorized_keys
63
64else
65 sudo echo $key > /home/voltha/.ssh/authorized_keys
66 sudo chmod 400 /home/voltha/.ssh/authorized_keys
67fi
68
69if grep voltha /etc/passwd 2>&1 > /dev/null; then
70 echo -e "${lBlue}A ${yellow}voltha ${lBlue} user account ${green}exists ${red}NOT ${lBlue}creating...${NC}"
71 sudo chown voltha.`id -gn voltha` /home/voltha/.ssh/authorized_keys
72else
73 sudo useradd -b /home -d /home/voltha voltha -s /bin/bash
74 echo 'voltha:voltha' | sudo chpasswd
75 sudo chown -R voltha.voltha /home/voltha
76fi
77
78rm .bash_login
79logout
80