linux_watermarksetup/setup.sh
2024-07-31 13:23:07 -04:00

112 lines
8.2 KiB
Bash

#!/bin/bash
set -e
echo -e "\e[32m
# # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Josh's Watermark Setup Script #
# This Script only works on Ubuntu & Debian #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # #\e[0m"
# Check if user is sudo
if [[ $EUID -ne 0 ]]; then
echo -e "\e[32m* This script must be executed via sudo user. \e[0m" 1>&2
exit 1
fi
# Proceed?
while true; do
RESET="\e[0m"
GREEN="\e[32m"
read -p "$(echo -e $GREEN"\n* Do you want to proceed? (Y/N)"$RESET)" yn
case $yn in
[yY] ) echo -e "\e[32m* Confirmed. Continuing..\e[0m"; break;;
[nN] ) echo -e "\e[32m* Confirmed. Exiting Installation..\e[0m"; exit;;
* ) echo -e "\e[32m* Invalid Response.\e[0m";;
esac
done
echo -e "\e[32m* Setting up watermark..\e[0m"
awk '/^#?Banner/{gsub(/#?Banner .*/, "Banner /etc/welcome"); found=1}1;END{if(!found) print "Banner /etc/welcome"}' /etc/ssh/sshd_config > /tmp/sshd_config_temp && sudo mv /tmp/sshd_config_temp /etc/ssh/sshd_config
echo -e "\n* Enter your domain (e.g., example.com):"
read -r host
# Setup MOTD
if [[ -f /etc/motd ]]; then
echo -e "\e[32m* /etc/motd file found. Removing file..\e[0m"
rm /etc/motd
else
echo -e "\e[32m* /etc/motd file not found. Skipping removal.\e[0m"
fi
cat <<EOL | sudo tee -a /etc/motd > /dev/null
============================================================================================================================================================
██╗ ██████╗ ███████╗██╗ ██╗███████╗███████╗██╗ ██╗███████╗██████╗ ██████╗ ███████╗ ███╗ ██╗███████╗████████╗██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗
██║██╔═══██╗██╔════╝██║ ██║██╔════╝██╔════╝██║ ██║██╔════╝██╔══██╗██╔═══██╗██╔════╝ ████╗ ██║██╔════╝╚══██╔══╝██║ ██║██╔═══██╗██╔══██╗██║ ██╔╝
██║██║ ██║███████╗███████║███████╗█████╗ ██║ ██║█████╗ ██████╔╝██║ ██║███████╗ ██╔██╗ ██║█████╗ ██║ ██║ █╗ ██║██║ ██║██████╔╝█████╔╝
██ ██║██║ ██║╚════██║██╔══██║╚════██║██╔══╝ ╚██╗ ██╔╝██╔══╝ ██╔══██╗██║ ██║╚════██║ ██║╚██╗██║██╔══╝ ██║ ██║███╗██║██║ ██║██╔══██╗██╔═██╗
╚█████╔╝╚██████╔╝███████║██║ ██║███████║███████╗ ╚████╔╝ ███████╗██║ ██║╚██████╔╝███████║██╗██║ ╚████║███████╗ ██║ ╚███╔███╔╝╚██████╔╝██║ ██║██║ ██╗
╚════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚══╝╚══╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
==========================================
Server Management
==========================================
Managed By:
Josh Severo
https://joshsevero.dev
Node ID:
$host
Contact Information:
me@joshsevero.dev
============================================================================================================================================================
EOL
if [[ -f /etc/welcome ]]; then
echo -e "\e[32m* /etc/welcome file found. Removing file..\e[0m"
rm /etc/welcome
else
echo -e "\e[32m* /etc/welcome file not found. Skipping removal.\e[0m"
fi
cat <<EOL | sudo tee -a /etc/welcome > /dev/null
============================================================================================================================================================
██╗ ██████╗ ███████╗██╗ ██╗███████╗███████╗██╗ ██╗███████╗██████╗ ██████╗ ███████╗ ███╗ ██╗███████╗████████╗██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗
██║██╔═══██╗██╔════╝██║ ██║██╔════╝██╔════╝██║ ██║██╔════╝██╔══██╗██╔═══██╗██╔════╝ ████╗ ██║██╔════╝╚══██╔══╝██║ ██║██╔═══██╗██╔══██╗██║ ██╔╝
██║██║ ██║███████╗███████║███████╗█████╗ ██║ ██║█████╗ ██████╔╝██║ ██║███████╗ ██╔██╗ ██║█████╗ ██║ ██║ █╗ ██║██║ ██║██████╔╝█████╔╝
██ ██║██║ ██║╚════██║██╔══██║╚════██║██╔══╝ ╚██╗ ██╔╝██╔══╝ ██╔══██╗██║ ██║╚════██║ ██║╚██╗██║██╔══╝ ██║ ██║███╗██║██║ ██║██╔══██╗██╔═██╗
╚█████╔╝╚██████╔╝███████║██║ ██║███████║███████╗ ╚████╔╝ ███████╗██║ ██║╚██████╔╝███████║██╗██║ ╚████║███████╗ ██║ ╚███╔███╔╝╚██████╔╝██║ ██║██║ ██╗
╚════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚══╝╚══╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
========================================================================================
WARNING: Unauthorized access will be logged and reported to the appropriate authorities.
========================================================================================
Server Management Information:
Managed By:
Josh Severo
https://joshsevero.dev
Node ID:
$host
Contact Information:
me@joshsevero.dev
============================================================================================================================================================
EOL
# Restart SSH
sudo systemctl restart ssh
rm /etc/hostname
cat <<EOL | sudo tee -a /etc/hostname > /dev/null
$host
EOL
echo -e "\e[32m* Domain setup completed\e[0m"