microcode.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2021-2023 tteck
  3. # Author: tteck (tteckster)
  4. # License: MIT
  5. # https://github.com/tteck/Proxmox/raw/main/LICENSE
  6. function header_info {
  7. clear
  8. cat <<"EOF"
  9. ____ __ ____ __
  10. / __ \_________ ________ ______________ _____ / |/ (_)_____________ _________ ____/ /__
  11. / /_/ / ___/ __ \/ ___/ _ \/ ___/ ___/ __ \/ ___/ / /|_/ / / ___/ ___/ __ \/ ___/ __ \/ __ / _ \
  12. / ____/ / / /_/ / /__/ __(__ |__ ) /_/ / / / / / / / /__/ / / /_/ / /__/ /_/ / /_/ / __/
  13. /_/ /_/ \____/\___/\___/____/____/\____/_/ /_/ /_/_/\___/_/ \____/\___/\____/\__,_/\___/
  14. EOF
  15. }
  16. RD=$(echo "\033[01;31m")
  17. YW=$(echo "\033[33m")
  18. GN=$(echo "\033[1;92m")
  19. CL=$(echo "\033[m")
  20. BFR="\\r\\033[K"
  21. HOLD="-"
  22. CM="${GN}✓${CL}"
  23. CROSS="${RD}✗${CL}"
  24. #set -euo pipefail
  25. #shopt -s inherit_errexit nullglob
  26. msg_info() {
  27. local msg="$1"
  28. echo -ne " ${HOLD} ${YW}${msg}..."
  29. }
  30. msg_ok() {
  31. local msg="$1"
  32. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  33. }
  34. msg_error() {
  35. local msg="$1"
  36. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  37. }
  38. header_info
  39. current_microcode=$(dmesg | grep -o 'microcode updated early to revision [^,]*, date = [0-9\-]*')
  40. while true; do
  41. if [ -z "${current_microcode}" ]; then
  42. msg_error "Microcode update information not found."
  43. else
  44. msg_ok "Current ${current_microcode}"
  45. fi
  46. read -p "Install the latest Processor Microcode (y/n)?" yn
  47. case $yn in
  48. [Yy]*) break ;;
  49. [Nn]*) exit ;;
  50. *) echo "Please answer yes or no." ;;
  51. esac
  52. done
  53. header_info
  54. intel() {
  55. if ! dpkg -s iucode-tool >/dev/null 2>&1; then
  56. msg_info "Installing iucode-tool: a tool for updating Intel processor microcode"
  57. apt-get install -y iucode-tool &>/dev/null
  58. msg_ok "Installed iucode-tool"
  59. else
  60. msg_ok "Intel iucode-tool is already installed"
  61. fi
  62. msg_info "Downloading the latest Intel Processor Microcode Package for Linux"
  63. wget -q http://ftp.debian.org/debian/pool/non-free-firmware/i/intel-microcode/intel-microcode_3.20230808.1_amd64.deb
  64. msg_ok "Downloaded the latest Intel Processor Microcode Package"
  65. msg_info "Installing the Intel Processor Microcode (Patience)"
  66. dpkg -i intel-microcode_3.20230808.1_amd64.deb &>/dev/null
  67. msg_ok "Installed the Intel Processor Microcode"
  68. msg_info "Cleaning up"
  69. rm intel-microcode_3.20230808.1_amd64.deb
  70. msg_ok "Cleaned"
  71. echo -e "\n To apply the changes, the system will need to be rebooted.\n"
  72. }
  73. amd() {
  74. msg_info "Downloading the latest AMD Processor Microcode Package for Linux"
  75. wget -q http://ftp.debian.org/debian/pool/non-free-firmware/a/amd64-microcode/amd64-microcode_3.20230808.1.1_amd64.deb
  76. msg_ok "Downloaded the latest AMD Processor Microcode Package"
  77. msg_info "Installing the AMD Processor Microcode (Patience)"
  78. dpkg -i amd64-microcode_3.20230808.1.1_amd64.deb &>/dev/null
  79. msg_ok "Installed the AMD Processor Microcode"
  80. msg_info "Cleaning up"
  81. rm amd64-microcode_3.20230808.1.1_amd64.deb
  82. msg_ok "Cleaned"
  83. echo -e "\n To apply the changes, the system will need to be rebooted.\n"
  84. }
  85. if ! command -v pveversion >/dev/null 2>&1; then
  86. header_info
  87. msg_error "\n No PVE Detected!\n"
  88. exit
  89. fi
  90. msg_info "Checking CPU Vendor"
  91. cpu=$(lscpu | grep -oP 'Vendor ID:\s*\K\S+' | head -n 1)
  92. if [ "$cpu" == "GenuineIntel" ]; then
  93. msg_ok "${cpu} was detected"
  94. intel
  95. elif [ "$cpu" == "AuthenticAMD" ]; then
  96. msg_ok "${cpu} was detected"
  97. amd
  98. else
  99. msg_error "${cpu} is not supported"
  100. exit
  101. fi