diff options
author | Georg | 2021-08-14 10:02:44 +0200 |
---|---|---|
committer | Georg | 2021-08-14 10:10:42 +0200 |
commit | c27753da863b3c44ceb81b2fe6ac689550704f89 (patch) | |
tree | 40e31d653640e43188ce5b45e08136297210a63f /lcpubsh/bin/generate.sh | |
download | public-shell-c27753da863b3c44ceb81b2fe6ac689550704f89.tar.gz public-shell-c27753da863b3c44ceb81b2fe6ac689550704f89.tar.bz2 public-shell-c27753da863b3c44ceb81b2fe6ac689550704f89.zip |
Init
Signed-off-by: Georg <georg@lysergic.dev>
Diffstat (limited to 'lcpubsh/bin/generate.sh')
-rw-r--r-- | lcpubsh/bin/generate.sh | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lcpubsh/bin/generate.sh b/lcpubsh/bin/generate.sh new file mode 100644 index 0000000..299cab6 --- /dev/null +++ b/lcpubsh/bin/generate.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# georg@lysergic.dev +set -e +echo "Shell generation invoked." | nc -N 127.0.0.2 2424 +if [ ! "$#" -eq 0 ]; then +user="$(echo "$1" |tr '[:upper:]' '[:lower:]')" +case "$2" in + "archlinux") + os="archlinux" + image="lc-archlinux-userbase-v2:sh0" + ;; + "ubuntu") + os="ubuntu" + image="lcbase_ubuntu_14082021_2:sh0" + ;; + *) + echo "Choose between archlinux or ubuntu" + exit 1 + ;; +esac +fingerprint_ecdsa="$(ssh-keygen -lf /etc/ssh/ssh_host_ecdsa_key.pub)" +if id "$1" &>/dev/null; then + echo "Aborted. Username is already taken." + echo "Aborted: $user is already taken." | nc -N 127.0.0.2 2424 +else + echo "Hang on ..." + echo "Creating $user locally." | nc -N 127.0.0.2 2424 + sudo useradd -mUs /opt/lcpubsh/bin/pubsh -G docker $user + pass=$(shuf -n2 /usr/share/dict/words | tr -d '\n') + echo "Appending to config." | nc -N 127.0.0.2 2424 + echo "" >> /etc/dockersh.ini + echo "[$user]" >> /etc/dockersh.ini + echo "image = $user" >> /etc/dockersh.ini + echo "Forking Docker base image ($image)." | nc -N 127.0.0.2 2424 + /opt/lcpubsh/bin/make_lc_user_image.sh $user $image | nc -N 127.0.0.2 2424 + echo "Setting password." | nc -N 127.0.0.2 2424 + sudo /opt/adduser.sh $user $pass + echo "@$user ssh -p 2222 $user@sh.lib.casa" | nc -N 127.0.0.2 2424 + echo "@$user $fingerprint_ecdsa" | nc -N 127.0.0.2 2424 + echo "@$user $pass" | nc -N 127.0.0.2 2424 + echo "#universe $pass" | nc -N 127.0.0.2 2424 + echo "Done." | nc -N 127.0.0.2 2424 + echo "OK. Details sent to user and/or admins." +fi +else + echo "No argument supplied." +fi + |