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
22 adduser --disabled-password --gecos '' "$my_name"
23 my_password=$(openssl rand -hex 16)
24 printf "$my_password"'\n'"$my_password" | passwd "$my_name"
26 # make 'app' a sudo-er (admin)
27 adduser "$my_name" sudo
28 echo "$my_name ALL=(ALL:ALL) NOPASSWD: ALL" | tee "/etc/sudoers.d/$my_name"
30 # allow users who can already login as 'root' to login as 'app'
31 mkdir -p "/home/$my_name/.ssh/"
32 chmod 0700 "/home/$my_name/.ssh/"
33 cp -r "$HOME/.ssh/authorized_keys" "/home/$my_name/.ssh/"
34 chmod 0600 "/home/$my_name/.ssh/authorized_keys"
35 touch "/home/$my_name/.ssh/config"
36 chmod 0644 "/home/$my_name/.ssh/config"
37 chown -R "$my_name":"$my_name" "/home/$my_name/.ssh/"
39 # ensure that 'app' has an SSH Keypair
40 sudo -i -u "$my_name" bash -c "ssh-keygen -b 2048 -t rsa -f '/home/$my_name/.ssh/id_rsa' -q -N ''"
42 # Install webi for the new 'app' user
43 WEBI_HOST=${WEBI_HOST:-"https://webinstall.dev"}
44 sudo -i -u "$my_name" bash -c "curl -fsSL '$WEBI_HOST/webi' | bash" \
45 || sudo -i -u "$my_name" bash -c "wget -q -O - '$WEBI_HOST/webi' | bash"
47 # TODO ensure that ssh-password login is off
49 echo "Created user '$my_name' with password '$my_password'"