Sergio Slobodrian | b92e513 | 2017-09-13 13:04:05 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | key="{{ key }}" |
| 4 | |
| 5 | lBlue='\033[1;34m' |
| 6 | green='\033[0;32m' |
| 7 | orange='\033[0;33m' |
| 8 | NC='\033[0m' |
| 9 | red='\033[0;31m' |
| 10 | yellow='\033[1;33m' |
| 11 | dGrey='\033[1;30m' |
| 12 | lGrey='\033[1;37m' |
| 13 | lCyan='\033[1;36m' |
| 14 | |
| 15 | |
| 16 | if 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." |
| 20 | fi |
| 21 | |
| 22 | if [ -d /home/voltha ]; then |
| 23 | echo -e "${lBlue}A directory ${yellow}/home/voltha ${green}exists ${red}NOT ${lBlue}creating...${NC}" |
| 24 | else |
| 25 | sudo mkdir /home/voltha |
| 26 | fi |
| 27 | |
| 28 | if [ -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}" |
| 30 | else |
| 31 | mkdir voltha_ssh |
| 32 | ssh-keygen -f ~/voltha_ssh/id_rsa -t rsa -N '' |
| 33 | sudo mv voltha_ssh /home/voltha/.ssh |
| 34 | fi |
| 35 | |
| 36 | if [ -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}" |
| 38 | else |
| 39 | echo "voltha ALL=(ALL) NOPASSWD:ALL" > tmp |
| 40 | sudo chown root.root tmp |
| 41 | sudo mv tmp /etc/sudoers.d/voltha |
| 42 | fi |
| 43 | |
| 44 | if 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 | |
| 51 | else |
| 52 | sudo echo $key > /home/voltha/.ssh/authorized_keys |
| 53 | sudo chmod 400 /home/voltha/.ssh/authorized_keys |
| 54 | fi |
| 55 | |
| 56 | if 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 |
| 59 | else |
| 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 |
| 63 | fi |
| 64 | |
| 65 | rm .bash_login |
| 66 | logout |
| 67 | |