diff --git a/debian.sh b/debian.sh index e4d62c9..69bcfcf 100644 --- a/debian.sh +++ b/debian.sh @@ -1,9 +1,9 @@ #!/bin/bash ######################################################### # Function :Initial Server Setup for Debian Server # -# Platform :Debian 11.x Bullseye and 12.x Bookworm # -# Version :1.6 # -# Date :28-09-2024 # +# Platform :Debian 11, 12 or 13 # +# Version :1.7 # +# Date :31-10-2024 # # Author :Xiufeng Guo # # Contact :i@m.ac # # Company :Show Corporation # @@ -16,36 +16,37 @@ export PATH set -euo pipefail 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 -if [ -f /etc/debian_version ]; then - printf "\E[0;32;40m" - echo "### Debian System Detected. Starting... ###" - printf "\E[0m" -else - printf "\E[0;31;40m" - echo "### This script is only for Debian. Exiting... ###" - printf "\E[0m" +# Check system requirements, if it's not Debian 11, 12 or 13, exit +function check_debian_version() { + if [[ -f /etc/os-release ]]; then + source /etc/os-release + if [[ "$ID" == "debian" && ( "$VERSION_CODENAME" == "bullseye" || "$VERSION_CODENAME" == "bookworm" || "$VERSION_CODENAME" == "trixie" ) ]]; then + echo "Running on supported Debian version: $PRETTY_NAME" + else + echo "Unsupported Debian version: $PRETTY_NAME" + exit 1 + fi + else + echo "/etc/os-release file not found. Cannot determine OS version." exit 1 -fi - -# Check Debian Version, if it's not 11 or 12, exit -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 -fi + fi +} +check_debian_version # 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" echo "### This script must be run as root. Exiting... ###" printf "\E[0m" exit 1 -fi + fi +} + +check_root function change_apt_sources() { 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 https://mirror-cdn.xtom.com/debian/ $codename-backports main contrib non-free non-free-firmware 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 else 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" exit 1 fi @@ -134,7 +148,7 @@ function install_packages() { printf "\E[0m" apt update apt upgrade -y - apt dist-upgrade -y + apt full-upgrade -y apt autoclean apt autoremove -y printf "\E[0;33;40m" @@ -460,7 +474,7 @@ function add_update_sh() { #!/bin/bash apt update apt upgrade -y -apt dist-upgrade -y +apt full-upgrade -y apt autoclean apt autoremove -y EOF @@ -471,9 +485,15 @@ EOF printf "\E[0m" } -# Install Dialog -apt update -apt install dialog -y +# Check if dialog is installed, if not, install it +function check_dialog() { + 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 cmd=(dialog --title "Debian Server Initial Setup" --separate-output --checklist "Select options:" 22 76 16)