Update 'debian-setup.sh'
This commit is contained in:
parent
1e8984cc96
commit
ef0e45d334
@ -3,19 +3,31 @@
|
|||||||
### configuration ###
|
### configuration ###
|
||||||
admin_user="newnius"
|
admin_user="newnius"
|
||||||
|
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
|
|
||||||
# check environment
|
# check permission
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
echo "[ERROR] Please run as root"
|
echo "[ERROR] Please run with user root"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! hash apt 2>/dev/null; then
|
# check OS
|
||||||
echo "[ERROR] Only debian is supported"
|
file=/etc/apt/sources.list
|
||||||
|
if ! test -f "${file}"; then
|
||||||
|
echo "[ERROR] Only Debian is supported"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
# install security updates
|
||||||
@ -24,9 +36,10 @@ apt update
|
|||||||
#uncomment as it may prompt update grub window
|
#uncomment as it may prompt update grub window
|
||||||
#apt upgrade -y
|
#apt upgrade -y
|
||||||
|
|
||||||
|
|
||||||
# install necessary tools
|
# install necessary tools
|
||||||
echo "[INFO] Installing 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
|
# install ssh service
|
||||||
if ! hash sshd 2>/dev/null; then
|
if ! hash sshd 2>/dev/null; then
|
||||||
@ -37,16 +50,13 @@ fi
|
|||||||
# Add admin user
|
# Add admin user
|
||||||
echo "[INFO] Creating admin user"
|
echo "[INFO] Creating admin user"
|
||||||
ssh_pass=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)
|
ssh_pass=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)
|
||||||
|
|
||||||
useradd $admin_user -m -s /bin/bash
|
useradd $admin_user -m -s /bin/bash
|
||||||
echo $admin_user:$ssh_pass | chpasswd
|
echo $admin_user:$ssh_pass | chpasswd
|
||||||
|
|
||||||
|
|
||||||
# Add to sudoers
|
# Add to sudoers
|
||||||
sed -i "/$admin_user/d" /etc/sudoers
|
sed -i "/$admin_user/d" /etc/sudoers
|
||||||
sed -i "/User privilege specification/a $admin_user\tALL=(ALL:ALL) ALL" /etc/sudoers
|
sed -i "/User privilege specification/a $admin_user\tALL=(ALL:ALL) ALL" /etc/sudoers
|
||||||
|
|
||||||
|
|
||||||
# update root password to random and forget it
|
# update root password to random and forget it
|
||||||
echo "[INFO] Updating root password to random"
|
echo "[INFO] Updating root password to random"
|
||||||
pass=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)
|
pass=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)
|
||||||
|
Loading…
Reference in New Issue
Block a user