From 02d7eb223c9ceb09bef6e65d584159b6eee76991 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sun, 12 Jun 2022 20:53:31 +0200 Subject: [PATCH] Add quick-installer for remote installations --- quick-installer.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 quick-installer.sh diff --git a/quick-installer.sh b/quick-installer.sh new file mode 100755 index 0000000..3a01a1a --- /dev/null +++ b/quick-installer.sh @@ -0,0 +1,59 @@ +#!/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 + return 0 + fi + + echo ">>> No supported package manager detected, exciting..." >&2 + return 1 +} + +check_privilege() { + if ! [ $(id -u) = 0 ]; then + echo ">>> Please run as root" >&2 + return 1 + fi +} + +check_sudo_installation() { + dpkg-query -l sudo > /dev/null 2>&1 + + if ! [ $? = 0 ]; then + echo ">>> Sudo package missing..." >&2 + return $(install_sudo) + fi + + return 0 +} + +create_default_user() { + echo ">>> Adding creator user..." >&2 + 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 +} + +check_privilege + +check_sudo_installation + +create_default_user + +set_creator_ssh_keys