docs: add -- global flag
[webi-installers/.git] / ssh-adduser / install.sh
index 6400a0c4f75efba196ca48b5fd878af73b1cb1e2..0673917193245832a453f909279d980c4adf79fb 100644 (file)
@@ -1,37 +1,20 @@
 #!/bin/bash
-
 set -e
 set -u
 
-# TODO: a more complete VPS setup
-
-# TODO would $EUID be better?
-if [ "root" != "$(whoami)" ]; then
-  echo "webi adduser: running user is already a non-root user"
-  exit 0
-fi
+function __install_ssh_adduser() {
+    my_cmd="ssh-adduser"
 
-#apt-get -y update
-#apt-get -y install curl wget rsync git
+    rm -f "$HOME/.local/bin/${my_cmd}"
 
-# Add User
-# TODO: might there be a better name?
-# me, this, user, self, person, i, who, do, tron
-adduser --disabled-password --gecos "" me
-my_password=$(openssl rand -hex 16)
-printf "$my_password"'\n'"$my_password" | passwd me
-adduser me sudo
-echo "me ALL=(ALL:ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/me
-sudo -i -u me bash -c 'ssh-keygen -b 2048 -t rsa -f /home/me/.ssh/id_rsa -q -N ""'
-mkdir -p /home/me/.ssh/
-cp -r $HOME/.ssh/authorized_keys /home/me/.ssh/
-chmod 0600 me:me /home/me/.ssh/authorized_keys
-chown -R me:me /home/me/.ssh/
+    webi_download \
+        "$WEBI_HOST/packages/${my_cmd}/${my_cmd}.sh" \
+        "$HOME/.local/bin/${my_cmd}"
 
-# Install webi for the new user
-sudo -i -u me bash -c 'curl -fsSL https://webinstall.dev/webi | bash' \
-    || sudo -i -u me bash -c 'wget -q -O - https://webinstall.dev/webi | bash'
+    chmod a+x "$HOME/.local/bin/${my_cmd}"
 
-# TODO ensure that ssh-password login is off
+    # run the command
+    "$HOME/.local/bin/${my_cmd}"
+}
 
-echo "Created user 'me' with password '$my_password'"
+__install_ssh_adduser