adduser -> ssh-adduser
[webi-installers/.git] / ssh-adduser / install.sh
1 #!/bin/bash
2
3 set -e
4 set -u
5
6 # TODO: a more complete VPS setup
7
8 # TODO would $EUID be better?
9 if [ "root" != "$(whoami)" ]; then
10   echo "webi adduser: running user is already a non-root user"
11   exit 0
12 fi
13
14 #apt-get -y update
15 #apt-get -y install curl wget rsync git
16
17 # Add User
18 # TODO: might there be a better name?
19 # me, this, user, self, person, i, who, do, tron
20 adduser --disabled-password --gecos "" me
21 my_password=$(openssl rand -hex 16)
22 printf "$my_password"'\n'"$my_password" | passwd me
23 adduser me sudo
24 echo "me ALL=(ALL:ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/me
25 sudo -i -u me bash -c 'ssh-keygen -b 2048 -t rsa -f /home/me/.ssh/id_rsa -q -N ""'
26 mkdir -p /home/me/.ssh/
27 cp -r $HOME/.ssh/authorized_keys /home/me/.ssh/
28 chmod 0600 me:me /home/me/.ssh/authorized_keys
29 chown -R me:me /home/me/.ssh/
30
31 # Install webi for the new user
32 sudo -i -u me bash -c 'curl -fsSL https://webinstall.dev/webi | bash' \
33     || sudo -i -u me bash -c 'wget -q -O - https://webinstall.dev/webi | bash'
34
35 # TODO ensure that ssh-password login is off
36
37 echo "Created user 'me' with password '$my_password'"