From ef0e45d334ba09d26cb1b99a78b82e4762a960be Mon Sep 17 00:00:00 2001 From: Newnius Date: Sat, 14 May 2022 13:33:08 +0000 Subject: [PATCH] Update 'debian-setup.sh' --- debian-setup.sh | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/debian-setup.sh b/debian-setup.sh index 5ae0c0d..b135725 100644 --- a/debian-setup.sh +++ b/debian-setup.sh @@ -3,19 +3,31 @@ ### configuration ### admin_user="newnius" - ##################### -# check environment +# check permission if [ "$EUID" -ne 0 ]; then - echo "[ERROR] Please run as root" + echo "[ERROR] Please run with user root" exit 1 fi -if ! hash apt 2>/dev/null; then - echo "[ERROR] Only debian is supported" +# check OS +file=/etc/apt/sources.list +if ! test -f "${file}"; then + echo "[ERROR] Only Debian is supported" exit 1 fi +if ! grep -q debian "${file}"; then + echo "[ERROR] Only Debian is supported" + exit 1 +fi + +# check do once +file=/etc/passwd +if grep -q ${admin_user} "${file}"; then + echo "[ERROR] OS is already setup" + exit 0 +fi # install security updates @@ -24,9 +36,10 @@ apt update #uncomment as it may prompt update grub window #apt upgrade -y + # install necessary tools echo "[INFO] Installing necessary tools" -apt install -y curl vim git sudo ca-certificates apt-transport-https haveged +apt install -y curl vim git sudo ca-certificates apt-transport-https haveged tree # install ssh service if ! hash sshd 2>/dev/null; then @@ -37,16 +50,13 @@ fi # Add admin user echo "[INFO] Creating admin user" ssh_pass=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32) - useradd $admin_user -m -s /bin/bash echo $admin_user:$ssh_pass | chpasswd - # Add to sudoers sed -i "/$admin_user/d" /etc/sudoers sed -i "/User privilege specification/a $admin_user\tALL=(ALL:ALL) ALL" /etc/sudoers - # update root password to random and forget it echo "[INFO] Updating root password to random" pass=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)