7 # TODO: a more complete VPS setup
9 # TODO would $EUID be better?
10 if [ "root" != "$(whoami)" ]; then
11 echo "webi adduser: running user is already a non-root user"
16 #apt-get -y install curl wget rsync git
19 # Picking 'app' because that seems to be what the # Docker/Vagrant
20 # crowd is doing. TODO: Other ideas? me, user, tron
21 adduser --disabled-password --gecos "" app
22 my_password=$(openssl rand -hex 16)
23 printf "$my_password"'\n'"$my_password" | passwd app
25 # make 'app' a sudo-er (admin)
27 echo "app ALL=(ALL:ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/app
29 # allow users who can already login as 'root' to login as 'app'
30 mkdir -p /home/app/.ssh/
31 chmod 0700 /home/app/.ssh/
32 cp -r "$HOME/.ssh/authorized_keys" /home/app/.ssh/
33 chmod 0600 /home/app/.ssh/authorized_keys
34 touch /home/app/.ssh/config
35 chmod 0644 /home/app/.ssh/config
36 chown -R app:app /home/app/.ssh/
38 # ensure that 'app' has an SSH Keypair
39 sudo -i -u app bash -c 'ssh-keygen -b 2048 -t rsa -f /home/app/.ssh/id_rsa -q -N ""'
41 # Install webi for the new 'app' user
42 sudo -i -u app bash -c 'curl -fsSL https://webinstall.dev/webi | bash' \
43 || sudo -i -u app bash -c 'wget -q -O - https://webinstall.dev/webi | bash'
45 # TODO ensure that ssh-password login is off
47 echo "Created user 'app' with password '$my_password'"