add some vps setup utils
[webi-installers/.git] / 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 adduser --disabled-password --gecos "" bob
19 my_password=$(openssl rand -hex 16)
20 printf "$my_password"'\n'"$my_password" | passwd bob
21 adduser bob sudo
22 echo "bob ALL=(ALL:ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/bob
23 sudo -i -u bob bash -c 'ssh-keygen -b 2048 -t rsa -f /home/bob/.ssh/id_rsa -q -N ""'
24 mkdir -p /home/bob/.ssh/
25 cp -r $HOME/.ssh/authorized_keys /home/bob/.ssh/
26 chmod 0600 bob:bob /home/bob/.ssh/authorized_keys
27 chown -R bob:bob /home/bob/.ssh/
28
29 # Install webi for the new user
30 sudo -i -u bob bash -c 'curl -fsSL https://webinstall.dev/webi | bash' \
31     || sudo -i -u bob bash -c 'wget -q -O - https://webinstall.dev/webi | bash'
32
33 # TODO ensure that ssh-password login is off
34
35 echo "Created user 'bob' with password '$my_password'"