utils/init-server.sh

53 lines
1.0 KiB
Bash
Raw Normal View History

2024-07-30 06:31:58 +05:00
#!/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
2024-08-05 06:05:44 +05:00
echo "Upgrade packages..."
2024-08-05 07:01:48 +05:00
apt-get update
2024-08-05 05:18:37 +05:00
apt-get upgrade -y
2024-08-05 06:05:44 +05:00
echo "Install apps..."
2024-08-05 05:18:37 +05:00
apt-get install -y mc vim pwgen
2024-07-30 06:31:58 +05:00
2024-08-05 06:05:44 +05:00
echo "Set timezone..."
2024-07-30 06:31:58 +05:00
timedatectl set-timezone Asia/Yekaterinburg
echo "Timezone changed:"
timedatectl
2024-08-05 06:05:44 +05:00
echo "Add new sudo user..."
2024-07-30 06:31:58 +05:00
if id "$USERNAME" &>/dev/null; then
echo "User $USERNAME already exists"
else
useradd -m -s /bin/bash "$USERNAME"
usermod -aG sudo "$USERNAME"
fi
2024-08-05 06:05:44 +05:00
echo "Configure /data privilegies..."
2024-07-30 06:31:58 +05:00
chown "$USERNAME":"$USERNAME" /data
chmod 770 /data
2024-08-05 06:05:44 +05:00
echo "Create /backups directory..."
2024-07-30 06:31:58 +05:00
mkdir -p /backups
chown "$USERNAME":"$USERNAME" /backups
chmod 770 /backups
2024-08-05 06:05:44 +05:00
echo "Change SSH port to $SSH_PORT..."
2024-07-30 06:31:58 +05:00
cd /data/utils
bash ssh-port.sh $SSH_PORT
2024-08-05 06:05:44 +05:00
echo "Disable SSH password auth..."
bash ssh-pw.sh n
2024-07-30 06:31:58 +05:00
trap - ERR
2024-07-27 04:15:43 +05:00
echo "Init complete"