Update 'debian-setup.sh'
This commit is contained in:
parent
1e8984cc96
commit
ef0e45d334
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user