microcode.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. msg_info() {
  25. local msg="$1"
  26. echo -ne " ${HOLD} ${YW}${msg}..."
  27. }
  28. msg_ok() {
  29. local msg="$1"
  30. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  31. }
  32. msg_error() {
  33. local msg="$1"
  34. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  35. }
  36. header_info
  37. current_microcode=$(dmesg | grep -o 'microcode updated early to revision [^,]*, date = [0-9\-]*')
  38. while true; do
  39. if [ -z "${current_microcode}" ]; then
  40. msg_error "Microcode update information not found."
  41. else
  42. msg_ok "Current ${current_microcode}"
  43. fi
  44. read -p "Install the latest Processor Microcode (y/n)?" yn
  45. case $yn in
  46. [Yy]*) break ;;
  47. [Nn]*) exit ;;
  48. *) echo "Please answer yes or no." ;;
  49. esac
  50. done
  51. header_info
  52. intel() {
  53. if ! dpkg -s iucode-tool >/dev/null 2>&1; then
  54. msg_info "Installing iucode-tool: a tool for updating Intel processor microcode"
  55. apt-get install -y iucode-tool &>/dev/null
  56. msg_ok "Installed iucode-tool"
  57. else
  58. msg_ok "Intel iucode-tool is already installed"
  59. fi
  60. msg_info "Downloading the latest Intel Processor Microcode Package for Linux"
  61. wget -q http://ftp.debian.org/debian/pool/non-free-firmware/i/intel-microcode/intel-microcode_3.20230808.1_amd64.deb
  62. msg_ok "Downloaded the latest Intel Processor Microcode Package"
  63. msg_info "Installing the Intel Processor Microcode (Patience)"
  64. dpkg -i intel-microcode_3.20230808.1_amd64.deb &>/dev/null
  65. msg_ok "Installed the Intel Processor Microcode"
  66. msg_info "Cleaning up"
  67. rm intel-microcode_3.20230808.1_amd64.deb
  68. msg_ok "Cleaned"
  69. echo -e "\n To apply the changes, the system will need to be rebooted.\n"
  70. }
  71. amd() {
  72. msg_info "Downloading the latest AMD Processor Microcode Package for Linux"
  73. wget -q http://ftp.debian.org/debian/pool/non-free-firmware/a/amd64-microcode/amd64-microcode_3.20230808.1.1_amd64.deb
  74. msg_ok "Downloaded the latest AMD Processor Microcode Package"
  75. msg_info "Installing the AMD Processor Microcode (Patience)"
  76. dpkg -i amd64-microcode_3.20230808.1.1_amd64.deb &>/dev/null
  77. msg_ok "Installed the AMD Processor Microcode"
  78. msg_info "Cleaning up"
  79. rm amd64-microcode_3.20230808.1.1_amd64.deb
  80. msg_ok "Cleaned"
  81. echo -e "\n To apply the changes, the system will need to be rebooted.\n"
  82. }
  83. if ! command -v pveversion >/dev/null 2>&1; then
  84. header_info
  85. msg_error "\n No PVE Detected!\n"
  86. exit
  87. fi
  88. msg_info "Checking CPU Vendor"
  89. cpu=$(lscpu | grep -oP 'Vendor ID:\s*\K\S+' | head -n 1)
  90. if [ "$cpu" == "GenuineIntel" ]; then
  91. msg_ok "${cpu} was detected"
  92. intel
  93. elif [ "$cpu" == "AuthenticAMD" ]; then
  94. msg_ok "${cpu} was detected"
  95. amd
  96. else
  97. msg_error "${cpu} is not supported"
  98. exit
  99. fi