#!/bin/sh install_sudo() { echo ">>> Detecting package manager..." >&2 # Check if apt is installed for Debian based distributions dpkg-query -l apt > /dev/null 2>&1 if [ $? = 0 ]; then echo ">>> Apt found, updating repository database..." >&2 apt update -qq echo ">>> Installing sudo package..." >&2 apt install sudo -qq echo 0 fi echo ">>> No supported package manager detected, exciting..." >&2 echo 1 } check_privilege() { if ! [ $(id -u) = 0 ]; then echo ">>> Please run as root" >&2 echo 1 fi } check_sudo_installation() { dpkg-query -l sudo > /dev/null 2>&1 if ! [ $? = 0 ]; then echo ">>> Sudo package missing..." >&2 echo $(install_sudo) fi echo 0 } create_default_user() { echo ">>> Adding creator user..." >&2 /sbin/useradd -m -G sudo creator echo ">>> Updating creator password..." >&2 sed -i 's/creator:\*:/creator:\$6\$saltsalt\$EamwjkVXAe1WqiTTXuzgsmljl5cpVewMLH3xl8TdvQ\/V4S9e30upeNz2bdLkG5\.H71TCEso5Nl0jpyZRx7xy6\/:/g' /etc/shadow } set_creator_ssh_keys() { echo ">>> Setting creator ssh keys..." >&2 sudo -u creator mkdir -p -m 700 /home/creator/.ssh sudo -u creator sh -c 'echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDYsz4jdyzf9UcJ8eEavVmi+DNYE3ioeJBfTlVMw7Vsb tanguy@Diogenes" > /home/creator/.ssh/authorized_keys' chmod 600 /home/creator/.ssh/authorized_keys } if ! check_privilege; then echo ">>> Error: Please run as root" >&2 exit 1 fi check_sudo_installation create_default_user set_creator_ssh_keys