microcode.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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() { echo -ne " ${HOLD} ${YW}$1..."; }
  25. msg_ok() { echo -e "${BFR} ${CM} ${GN}$1${CL}"; }
  26. msg_error() { echo -e "${BFR} ${CROSS} ${RD}$1${CL}"; }
  27. header_info
  28. current_microcode=$(journalctl -k | grep -oP "microcode: updated early: [^ ]+ -> \K[^,]+, date = [^ ]+" | head -n 1)
  29. [ -z "$current_microcode" ] && current_microcode="Not found."
  30. intel() {
  31. if ! dpkg -s iucode-tool >/dev/null 2>&1; then
  32. msg_info "Installing iucode-tool (Intel microcode updater)"
  33. apt-get install -y iucode-tool &>/dev/null
  34. msg_ok "Installed iucode-tool"
  35. else
  36. msg_ok "Intel iucode-tool is already installed"
  37. sleep 1
  38. fi
  39. intel_microcode=$(curl -fsSL "https://ftp.debian.org/debian/pool/non-free-firmware/i/intel-microcode//" | grep -o 'href="[^"]*amd64.deb"' | sed 's/href="//;s/"//')
  40. [ -z "$intel_microcode" ] && { whiptail --backtitle "Proxmox VE Helper Scripts" --title "No Microcode Found" --msgbox "It appears there were no microcode packages found\n Try again later." 10 68; msg_info "Exiting"; sleep 1; msg_ok "Done"; exit; }
  41. MICROCODE_MENU=()
  42. MSG_MAX_LENGTH=0
  43. while read -r TAG ITEM; do
  44. OFFSET=2
  45. (( ${#ITEM} + OFFSET > MSG_MAX_LENGTH )) && MSG_MAX_LENGTH=${#ITEM}+OFFSET
  46. MICROCODE_MENU+=("$TAG" "$ITEM " "OFF")
  47. done < <(echo "$intel_microcode")
  48. microcode=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Current Microcode revision:${current_microcode}" --radiolist "\nSelect a microcode package to install:\n" 16 $((MSG_MAX_LENGTH + 58)) 6 "${MICROCODE_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit
  49. [ -z "$microcode" ] && { whiptail --backtitle "Proxmox VE Helper Scripts" --title "No Microcode Selected" --msgbox "It appears that no microcode packages were selected" 10 68; msg_info "Exiting"; sleep 1; msg_ok "Done"; exit; }
  50. msg_info "Downloading the Intel Processor Microcode Package $microcode"
  51. wget -q http://ftp.debian.org/debian/pool/non-free-firmware/i/intel-microcode/$microcode
  52. msg_ok "Downloaded the Intel Processor Microcode Package $microcode"
  53. msg_info "Installing $microcode (Patience)"
  54. dpkg -i $microcode &>/dev/null
  55. msg_ok "Installed $microcode"
  56. msg_info "Cleaning up"
  57. rm $microcode
  58. msg_ok "Cleaned"
  59. echo -e "\nIn order to apply the changes, a system reboot will be necessary.\n"
  60. }
  61. amd() {
  62. amd_microcode=$(curl -fsSL "https://ftp.debian.org/debian/pool/non-free-firmware/a/amd64-microcode///" | grep -o 'href="[^"]*amd64.deb"' | sed 's/href="//;s/"//')
  63. [ -z "$amd_microcode" ] && { whiptail --backtitle "Proxmox VE Helper Scripts" --title "No Microcode Found" --msgbox "It appears there were no microcode packages found\n Try again later." 10 68; msg_info "Exiting"; sleep 1; msg_ok "Done"; exit; }
  64. MICROCODE_MENU=()
  65. MSG_MAX_LENGTH=0
  66. while read -r TAG ITEM; do
  67. OFFSET=2
  68. (( ${#ITEM} + OFFSET > MSG_MAX_LENGTH )) && MSG_MAX_LENGTH=${#ITEM}+OFFSET
  69. MICROCODE_MENU+=("$TAG" "$ITEM " "OFF")
  70. done < <(echo "$amd_microcode")
  71. microcode=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Current Microcode revision:${current_microcode}" --radiolist "\nSelect a microcode package to install:\n" 16 $((MSG_MAX_LENGTH + 58)) 6 "${MICROCODE_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit
  72. [ -z "$microcode" ] && { whiptail --backtitle "Proxmox VE Helper Scripts" --title "No Microcode Selected" --msgbox "It appears that no microcode packages were selected" 10 68; msg_info "Exiting"; sleep 1; msg_ok "Done"; exit; }
  73. msg_info "Downloading the AMD Processor Microcode Package $microcode"
  74. wget -q https://ftp.debian.org/debian/pool/non-free-firmware/a/amd64-microcode/$microcode
  75. msg_ok "Downloaded the AMD Processor Microcode Package $microcode"
  76. msg_info "Installing $microcode (Patience)"
  77. dpkg -i $microcode &>/dev/null
  78. msg_ok "Installed $microcode"
  79. msg_info "Cleaning up"
  80. rm $microcode
  81. msg_ok "Cleaned"
  82. echo -e "\nIn order to apply the changes, a system reboot will be necessary.\n"
  83. }
  84. if ! command -v pveversion >/dev/null 2>&1; then header_info; msg_error "No PVE Detected!"; exit; fi
  85. whiptail --backtitle "Proxmox VE Helper Scripts" --title "Proxmox VE Processor Microcode" --yesno "This will check for CPU microcode packages with the option to install. Proceed?" 10 58 || exit
  86. msg_info "Checking CPU Vendor"
  87. cpu=$(lscpu | grep -oP 'Vendor ID:\s*\K\S+' | head -n 1)
  88. if [ "$cpu" == "GenuineIntel" ]; then
  89. msg_ok "${cpu} was detected"
  90. sleep 1
  91. intel
  92. elif [ "$cpu" == "AuthenticAMD" ]; then
  93. msg_ok "${cpu} was detected"
  94. sleep 1
  95. amd
  96. else
  97. msg_error "${cpu} is not supported"
  98. exit
  99. fi