Update debian.sh

This commit is contained in:
Xiufeng Guo 2024-10-31 02:24:31 +09:00
parent 94719774ae
commit 9aa71ea724
Signed by: showfom
GPG Key ID: 29A7777777777777

View File

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
######################################################### #########################################################
# Function :Initial Server Setup for Debian Server # # Function :Initial Server Setup for Debian Server #
# Platform :Debian 11.x Bullseye and 12.x Bookworm # # Platform :Debian 11, 12 or 13 #
# Version :1.6 # # Version :1.7 #
# Date :28-09-2024 # # Date :31-10-2024 #
# Author :Xiufeng Guo # # Author :Xiufeng Guo #
# Contact :i@m.ac # # Contact :i@m.ac #
# Company :Show Corporation # # Company :Show Corporation #
@ -16,36 +16,37 @@ export PATH
set -euo pipefail set -euo pipefail
IFS=$'\n\t' IFS=$'\n\t'
current_dir=$(cd -P -- "$(dirname -- "$0")" && pwd -P) #current_dir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
# Check system requirements, if it's not Debian, exit # Check system requirements, if it's not Debian 11, 12 or 13, exit
if [ -f /etc/debian_version ]; then function check_debian_version() {
printf "\E[0;32;40m" if [[ -f /etc/os-release ]]; then
echo "### Debian System Detected. Starting... ###" source /etc/os-release
printf "\E[0m" if [[ "$ID" == "debian" && ( "$VERSION_CODENAME" == "bullseye" || "$VERSION_CODENAME" == "bookworm" || "$VERSION_CODENAME" == "trixie" ) ]]; then
else echo "Running on supported Debian version: $PRETTY_NAME"
printf "\E[0;31;40m" else
echo "### This script is only for Debian. Exiting... ###" echo "Unsupported Debian version: $PRETTY_NAME"
printf "\E[0m"
exit 1 exit 1
fi fi
else
# Check Debian Version, if it's not 11 or 12, exit echo "/etc/os-release file not found. Cannot determine OS version."
if [ "$(cat /etc/debian_version | cut -d'.' -f1)" != "12" ] && [ "$(cat /etc/debian_version | cut -d'.' -f1)" != "11" ]; then
printf "\E[0;31;40m"
echo "### This script is only for Debian 11 or 12. Exiting... ###"
printf "\E[0m"
exit 1 exit 1
fi fi
}
check_debian_version
# Check if user is root, if not, exit # Check if user is root, if not, exit
if [ "$(id -u)" != "0" ]; then function check_root() {
if [ "$(id -u)" != "0" ]; then
printf "\E[0;31;40m" printf "\E[0;31;40m"
echo "### This script must be run as root. Exiting... ###" echo "### This script must be run as root. Exiting... ###"
printf "\E[0m" printf "\E[0m"
exit 1 exit 1
fi fi
}
check_root
function change_apt_sources() { function change_apt_sources() {
printf "\E[0;35;40m" printf "\E[0;35;40m"
@ -95,10 +96,23 @@ deb https://mirror-cdn.xtom.com/debian/ $codename-updates main contrib non-free
#deb-src https://mirror-cdn.xtom.com/debian/ $codename-updates main contrib non-free non-free-firmware #deb-src https://mirror-cdn.xtom.com/debian/ $codename-updates main contrib non-free non-free-firmware
deb https://mirror-cdn.xtom.com/debian/ $codename-backports main contrib non-free non-free-firmware deb https://mirror-cdn.xtom.com/debian/ $codename-backports main contrib non-free non-free-firmware
EOF EOF
# If codename = trixie, use the new sources.list
elif [ "$codename" == "trixie" ]; then
cat > /etc/apt/sources.list << EOF
deb https://mirror-cdn.xtom.com/debian/ $codename main contrib non-free non-free-firmware
#deb-src https://mirror-cdn.xtom.com/debian/ $codename main contrib non-free non-free-firmware
deb https://mirror-cdn.xtom.com/debian-security/ $codename-security main contrib non-free non-free-firmware
#deb-src https://mirror-cdn.xtom.com/debian-security/ $codename-security main contrib non-free non-free-firmware
deb https://mirror-cdn.xtom.com/debian/ $codename-updates main contrib non-free non-free-firmware
#deb-src https://mirror-cdn.xtom.com/debian/ $codename-updates main contrib non-free non-free-firmware
deb https://mirror-cdn.xtom.com/debian/ $codename-backports main contrib non-free non-free-firmware
EOF
# If codename = others, then exit # If codename = others, then exit
else else
printf "\E[0;31;40m" printf "\E[0;31;40m"
echo "### This script is only for Debian 11 or 12. Exiting... ###" echo "### This script is only for Debian 11, 12 or 13. Exiting... ###"
printf "\E[0m" printf "\E[0m"
exit 1 exit 1
fi fi
@ -134,7 +148,7 @@ function install_packages() {
printf "\E[0m" printf "\E[0m"
apt update apt update
apt upgrade -y apt upgrade -y
apt dist-upgrade -y apt full-upgrade -y
apt autoclean apt autoclean
apt autoremove -y apt autoremove -y
printf "\E[0;33;40m" printf "\E[0;33;40m"
@ -460,7 +474,7 @@ function add_update_sh() {
#!/bin/bash #!/bin/bash
apt update apt update
apt upgrade -y apt upgrade -y
apt dist-upgrade -y apt full-upgrade -y
apt autoclean apt autoclean
apt autoremove -y apt autoremove -y
EOF EOF
@ -471,9 +485,15 @@ EOF
printf "\E[0m" printf "\E[0m"
} }
# Install Dialog # Check if dialog is installed, if not, install it
apt update function check_dialog() {
apt install dialog -y if ! command -v dialog &> /dev/null; then
echo "dialog is not installed. Installing it now..."
apt update && apt install dialog -y
fi
}
check_dialog
# Dialog box begins here # Dialog box begins here
cmd=(dialog --title "Debian Server Initial Setup" --separate-output --checklist "Select options:" 22 76 16) cmd=(dialog --title "Debian Server Initial Setup" --separate-output --checklist "Select options:" 22 76 16)