#!/bin/bash

# Define colors
GREEN='\033[32m'
RED='\033[31m'
NC='\033[0m' # No Color

# Print success message
success_print() {
  printf "${GREEN}%s${NC}\n" "$1"
}

# Print error message
error_print() {
  printf "${RED}%s${NC}\n" "$1"
}

# Get system information
get_sys_info() {
  # Check the Linux distribution
  if [[ -f /etc/os-release ]]; then
    source /etc/os-release
    SYS_VERSION=$ID
  else
    SYS_VERSION="other"
  fi

  # Gather system information
  SYS_JG=$(uname -m)
  SYS_INFO=$(uname -a)
  SYS_BIT=$(getconf LONG_BIT)
  MEM_TOTAL=$(free -m | awk '/Mem/ {print $2}')
  CPU_INFO=$(getconf _NPROCESSORS_ONLN)
  PFM=$(awk -F':' '/model name/ {print $2}' /proc/cpuinfo | head -n 1 | sed -e 's/^[[:space:]]*//')

  # Print system information
  printf "
+----------------------------------------------------------------------
| %s %s %s
+----------------------------------------------------------------------
| Bit: %s Mem: %sM Core: %s
+----------------------------------------------------------------------
| %s
+----------------------------------------------------------------------
| %s
+----------------------------------------------------------------------
| see more: cat /proc/cpuinfo    cat /etc/os-release
+----------------------------------------------------------------------
" "$SYS_VERSION" "$PRETTY_NAME" "$SYS_JG" "$SYS_BIT" "$MEM_TOTAL" "$CPU_INFO" "$SYS_INFO" "$PFM"

  # Check if the script is run as root
  if [[ $EUID -ne 0 ]]; then
    error_print "\n------ This script must be run as root ------\n"
    exit 1
  fi
}

# Call the function to get system information
get_sys_info
