blob: 972b2f5f4232e9320d2daf75c0caab9f5fd7f711 [file] [log] [blame]
Sergio Slobodrianb92e5132017-09-13 13:04:05 -04001#!/bin/bash
2
3key="{{ key }}"
4
5lBlue='\033[1;34m'
6green='\033[0;32m'
7orange='\033[0;33m'
8NC='\033[0m'
9red='\033[0;31m'
10yellow='\033[1;33m'
11dGrey='\033[1;30m'
12lGrey='\033[1;37m'
13lCyan='\033[1;36m'
14
15
16if grep voltha /etc/passwd 2>&1 > /dev/null; then
17 echo -e "${yellow}WARNING:${lBlue}a ${yellow}voltha ${lBlue} user exists on the system!!"
18 echo -e "This account will be re-used by the installer. If you encounter any problems"
19 echo -e "please review the account setup to ensure it is correctly set up to run voltha."
20fi
21
22if [ -d /home/voltha ]; then
23 echo -e "${lBlue}A directory ${yellow}/home/voltha ${green}exists ${red}NOT ${lBlue}creating...${NC}"
24else
25 sudo mkdir /home/voltha
26fi
27
28if [ -f /home/voltha/.ssh/id_rsa ]; then
29 echo -e "${lBlue}A ssh key file ${yellow}/home/voltha/ssh/id_rsa ${green}exists ${red}NOT ${lBlue}creating...${NC}"
30else
31 mkdir voltha_ssh
32 ssh-keygen -f ~/voltha_ssh/id_rsa -t rsa -N ''
33 sudo mv voltha_ssh /home/voltha/.ssh
34fi
35
36if [ -f /etc/sudoers.d/voltha ]; then
37 echo -e "${lBlue}A sudoers file ${yellow}/etc/sudoers.d/voltha ${green}exists ${red}NOT ${lBlue}creating...${NC}"
38else
39 echo "voltha ALL=(ALL) NOPASSWD:ALL" > tmp
40 sudo chown root.root tmp
41 sudo mv tmp /etc/sudoers.d/voltha
42fi
43
44if sudo test -f /home/voltha/.ssh/authorized_keys ; then
45 sudo chmod ugo+w /home/voltha/.ssh/authorized_keys
46 echo $key > key.tmp
47 sudo cat key.tmp >> /home/voltha/.ssh/authorized_keys
48 rm key.tmp
49 sudo chmod 400 /home/voltha/.ssh/authorized_keys
50
51else
52 sudo echo $key > /home/voltha/.ssh/authorized_keys
53 sudo chmod 400 /home/voltha/.ssh/authorized_keys
54fi
55
56if grep voltha /etc/passwd 2>&1 > /dev/null; then
57 echo -e "${lBlue}A ${yellow}voltha ${lBlue} user account ${green}exists ${red}NOT ${lBlue}creating...${NC}"
58 sudo chown voltha.`id -gn voltha` /home/voltha/.ssh/authorized_keys
59else
60 sudo useradd -b /home -d /home/voltha voltha -s /bin/bash
61 echo 'voltha:voltha' | sudo chpasswd
62 sudo chown -R voltha.voltha /home/voltha
63fi
64
65rm .bash_login
66logout
67