microcode.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. clear
  7. while true; do
  8. read -p "Install the latest Processor Microcode (y/n)?" yn
  9. case $yn in
  10. [Yy]*) break ;;
  11. [Nn]*) exit ;;
  12. *) echo "Please answer yes or no." ;;
  13. esac
  14. done
  15. clear
  16. cat <<"EOF"
  17. ____ __ ____ __
  18. / __ \_________ ________ ______________ _____ / |/ (_)_____________ _________ ____/ /__
  19. / /_/ / ___/ __ \/ ___/ _ \/ ___/ ___/ __ \/ ___/ / /|_/ / / ___/ ___/ __ \/ ___/ __ \/ __ / _ \
  20. / ____/ / / /_/ / /__/ __(__ |__ ) /_/ / / / / / / / /__/ / / /_/ / /__/ /_/ / /_/ / __/
  21. /_/ /_/ \____/\___/\___/____/____/\____/_/ /_/ /_/_/\___/_/ \____/\___/\____/\__,_/\___/
  22. EOF
  23. RD=$(echo "\033[01;31m")
  24. YW=$(echo "\033[33m")
  25. GN=$(echo "\033[1;92m")
  26. CL=$(echo "\033[m")
  27. BFR="\\r\\033[K"
  28. HOLD="-"
  29. CM="${GN}✓${CL}"
  30. CROSS="${RD}✗${CL}"
  31. set -euo pipefail
  32. shopt -s inherit_errexit nullglob
  33. msg_info() {
  34. local msg="$1"
  35. echo -ne " ${HOLD} ${YW}${msg}..."
  36. }
  37. msg_ok() {
  38. local msg="$1"
  39. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  40. }
  41. msg_error() {
  42. local msg="$1"
  43. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  44. }
  45. intel() {
  46. msg_info "Installing iucode-tool: a tool for updating Intel processor microcode"
  47. apt-get install -y iucode-tool &>/dev/null
  48. msg_ok "Installed iucode-tool"
  49. msg_info "Downloading the latest Intel Processor Microcode Package for Linux"
  50. wget -q http://ftp.debian.org/debian/pool/non-free-firmware/i/intel-microcode/intel-microcode_3.20230512.1_amd64.deb
  51. msg_ok "Downloaded the latest Intel Processor Microcode Package"
  52. msg_info "Installing the Intel Processor Microcode (Patience)"
  53. dpkg -i intel-microcode_3.20230512.1_amd64.deb &>/dev/null
  54. msg_ok "Installed the Intel Processor Microcode"
  55. msg_info "Cleaning up"
  56. rm intel-microcode_3.20230512.1_amd64.deb
  57. msg_ok "Cleaned"
  58. echo -e "\n To apply the changes, the system will need to be rebooted.\n"
  59. }
  60. amd() {
  61. msg_info "Downloading the latest AMD Processor Microcode Package for Linux"
  62. wget -q http://ftp.debian.org/debian/pool/non-free-firmware/a/amd64-microcode/amd64-microcode_3.20230414.1_amd64.deb
  63. msg_ok "Downloaded the latest AMD Processor Microcode Package"
  64. msg_info "Installing the AMD Processor Microcode (Patience)"
  65. dpkg -i amd64-microcode_3.20230414.1_amd64.deb &>/dev/null
  66. msg_ok "Installed the AMD Processor Microcode"
  67. msg_info "Cleaning up"
  68. rm amd64-microcode_3.20230414.1_amd64.deb
  69. msg_ok "Cleaned"
  70. echo -e "\n To apply the changes, the system will need to be rebooted.\n"
  71. }
  72. if [ $(pveversion | grep -c "pve-manager/7\.[0-9]") -eq 0 ]; then
  73. echo -e "${CROSS} Proxmox Virtual Environment Not Detected"
  74. echo -e "Exiting..."
  75. sleep 2
  76. exit
  77. fi
  78. msg_info "Checking CPU Vendor"
  79. cpu=$(lscpu | grep -oP 'Vendor ID:\s*\K\S+')
  80. if [ "$cpu" == "GenuineIntel" ]; then
  81. msg_ok "${cpu} was detected"
  82. intel
  83. elif [ "$cpu" == "AuthenticAMD" ]; then
  84. msg_ok "${cpu} was detected"
  85. amd
  86. else
  87. msg_error "${cpu} is not supported"
  88. exit
  89. fi