utils/init-server.sh
2024-08-14 10:49:55 +05:00

53 lines
1.0 KiB
Bash

#!/bin/bash
USERNAME=usradmin
SSH_PORT=2525
if [ "$(id -u)" != "0" ]; then
echo -e "\033[31mThis script requires superuser rights.\033[0m"
exit 0
fi
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' ERR
set -e
export DEBIAN_FRONTEND=noninteractive
echo "Upgrade packages..."
apt-get update
apt-get upgrade -y
echo "Install apps..."
apt-get install -y mc vim pwgen cron
echo "Set timezone..."
timedatectl set-timezone Asia/Yekaterinburg
echo "Timezone changed:"
timedatectl
echo "Add new sudo user..."
if id "$USERNAME" &>/dev/null; then
echo "User $USERNAME already exists"
else
useradd -m -s /bin/bash "$USERNAME"
usermod -aG sudo "$USERNAME"
fi
echo "Configure /data privilegies..."
chown "$USERNAME":"$USERNAME" /data
chmod 770 /data
echo "Create /backups directory..."
mkdir -p /backups
chown "$USERNAME":"$USERNAME" /backups
chmod 770 /backups
echo "Change SSH port to $SSH_PORT..."
cd /data/utils
bash ssh-port.sh $SSH_PORT
echo "Disable SSH password auth..."
bash ssh-pw.sh n
trap - ERR
echo "Init complete"