Sergio Slobodrian | b92e513 | 2017-09-13 13:04:05 -0400 | [diff] [blame] | 1 | #!/bin/bash |
Zack Williams | 41513bf | 2018-07-07 20:08:35 -0700 | [diff] [blame] | 2 | # 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 Slobodrian | b92e513 | 2017-09-13 13:04:05 -0400 | [diff] [blame] | 15 | |
| 16 | key="{{ key }}" |
| 17 | |
| 18 | lBlue='\033[1;34m' |
| 19 | green='\033[0;32m' |
| 20 | orange='\033[0;33m' |
| 21 | NC='\033[0m' |
| 22 | red='\033[0;31m' |
| 23 | yellow='\033[1;33m' |
| 24 | dGrey='\033[1;30m' |
| 25 | lGrey='\033[1;37m' |
| 26 | lCyan='\033[1;36m' |
| 27 | |
| 28 | |
| 29 | if 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." |
| 33 | fi |
| 34 | |
| 35 | if [ -d /home/voltha ]; then |
| 36 | echo -e "${lBlue}A directory ${yellow}/home/voltha ${green}exists ${red}NOT ${lBlue}creating...${NC}" |
| 37 | else |
| 38 | sudo mkdir /home/voltha |
| 39 | fi |
| 40 | |
| 41 | if [ -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}" |
| 43 | else |
| 44 | mkdir voltha_ssh |
| 45 | ssh-keygen -f ~/voltha_ssh/id_rsa -t rsa -N '' |
| 46 | sudo mv voltha_ssh /home/voltha/.ssh |
| 47 | fi |
| 48 | |
| 49 | if [ -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}" |
| 51 | else |
| 52 | echo "voltha ALL=(ALL) NOPASSWD:ALL" > tmp |
| 53 | sudo chown root.root tmp |
| 54 | sudo mv tmp /etc/sudoers.d/voltha |
| 55 | fi |
| 56 | |
| 57 | if 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 | |
| 64 | else |
| 65 | sudo echo $key > /home/voltha/.ssh/authorized_keys |
| 66 | sudo chmod 400 /home/voltha/.ssh/authorized_keys |
| 67 | fi |
| 68 | |
| 69 | if 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 |
| 72 | else |
| 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 |
| 76 | fi |
| 77 | |
| 78 | rm .bash_login |
| 79 | logout |
| 80 | |