Update microcode.sh

code refactoring
pull/1851/head
tteckster 1 year ago committed by GitHub
parent 6df6d1c2fb
commit 64bdc91b67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,8 +5,8 @@
# https://github.com/tteck/Proxmox/raw/main/LICENSE # https://github.com/tteck/Proxmox/raw/main/LICENSE
function header_info { function header_info {
clear clear
cat <<"EOF" cat <<"EOF"
____ __ ____ __ ____ __ ____ __
/ __ \_________ ________ ______________ _____ / |/ (_)_____________ _________ ____/ /__ / __ \_________ ________ ______________ _____ / |/ (_)_____________ _________ ____/ /__
/ /_/ / ___/ __ \/ ___/ _ \/ ___/ ___/ __ \/ ___/ / /|_/ / / ___/ ___/ __ \/ ___/ __ \/ __ / _ \ / /_/ / ___/ __ \/ ___/ _ \/ ___/ ___/ __ \/ ___/ / /|_/ / / ___/ ___/ __ \/ ___/ __ \/ __ / _ \
@ -25,90 +25,99 @@ HOLD="-"
CM="${GN}${CL}" CM="${GN}${CL}"
CROSS="${RD}${CL}" CROSS="${RD}${CL}"
msg_info() { msg_info() { echo -ne " ${HOLD} ${YW}$1..."; }
local msg="$1" msg_ok() { echo -e "${BFR} ${CM} ${GN}$1${CL}"; }
echo -ne " ${HOLD} ${YW}${msg}..." msg_error() { echo -e "${BFR} ${CROSS} ${RD}$1${CL}"; }
}
msg_ok() {
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
}
msg_error() {
local msg="$1"
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
}
header_info header_info
current_microcode=$(dmesg | grep -o 'microcode updated early to revision [^,]*, date = [0-9\-]*') current_microcode=$(journalctl -k | grep -E "microcode: microcode" | awk -F 'microcode: microcode updated early to revision |, date = ' '{print $2 ", date = " $3}')
while true; do [ -z "$current_microcode" ] && current_microcode="Not found."
if [ -z "${current_microcode}" ]; then
msg_error "Microcode update information not found."
else
msg_ok "Current ${current_microcode}"
fi
read -p "Install the latest Processor Microcode (y/n)?" yn
case $yn in
[Yy]*) break ;;
[Nn]*) exit ;;
*) echo "Please answer yes or no." ;;
esac
done
header_info
intel() { intel() {
if ! dpkg -s iucode-tool >/dev/null 2>&1; then if ! dpkg -s iucode-tool >/dev/null 2>&1; then
msg_info "Installing iucode-tool: a tool for updating Intel processor microcode" msg_info "Installing iucode-tool (Intel microcode updater)"
apt-get install -y iucode-tool &>/dev/null apt-get install -y iucode-tool &>/dev/null
msg_ok "Installed iucode-tool" msg_ok "Installed iucode-tool"
else else
msg_ok "Intel iucode-tool is already installed" msg_ok "Intel iucode-tool is already installed"
sleep 1
fi fi
msg_info "Downloading the latest Intel Processor Microcode Package for Linux" 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/"//')
wget -q http://ftp.debian.org/debian/pool/non-free-firmware/i/intel-microcode/intel-microcode_3.20230808.1_amd64.deb [ -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; }
msg_ok "Downloaded the latest Intel Processor Microcode Package"
CTID_MENU=()
MSG_MAX_LENGTH=0
while read -r TAG ITEM; do
OFFSET=2
(( ${#ITEM} + OFFSET > MSG_MAX_LENGTH )) && MSG_MAX_LENGTH=${#ITEM}+OFFSET
CTID_MENU+=("$TAG" "$ITEM " "OFF")
done < <(echo "$intel_microcode")
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 "${CTID_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit
[ -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; }
msg_info "Downloading the Intel Processor Microcode Package $microcode"
wget -q http://ftp.debian.org/debian/pool/non-free-firmware/i/intel-microcode/$microcode
msg_ok "Downloaded the Intel Processor Microcode Package $microcode"
msg_info "Installing the Intel Processor Microcode (Patience)" msg_info "Installing $microcode (Patience)"
dpkg -i intel-microcode_3.20230808.1_amd64.deb &>/dev/null dpkg -i $microcode &>/dev/null
msg_ok "Installed the Intel Processor Microcode" msg_ok "Installed $microcode"
msg_info "Cleaning up" msg_info "Cleaning up"
rm intel-microcode_3.20230808.1_amd64.deb rm $microcode
msg_ok "Cleaned" msg_ok "Cleaned"
echo -e "\nIn order to apply the changes, a system reboot will be necessary.\n"
echo -e "\n To apply the changes, the system will need to be rebooted.\n"
} }
amd() { amd() {
msg_info "Downloading the latest AMD Processor Microcode Package for Linux" 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/"//')
wget -q http://ftp.debian.org/debian/pool/non-free-firmware/a/amd64-microcode/amd64-microcode_3.20230808.1.1_amd64.deb
msg_ok "Downloaded the latest AMD Processor Microcode Package" [ -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; }
CTID_MENU=()
MSG_MAX_LENGTH=0
while read -r TAG ITEM; do
OFFSET=2
(( ${#ITEM} + OFFSET > MSG_MAX_LENGTH )) && MSG_MAX_LENGTH=${#ITEM}+OFFSET
CTID_MENU+=("$TAG" "$ITEM " "OFF")
done < <(echo "$amd_microcode")
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 "${CTID_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit
[ -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; }
msg_info "Installing the AMD Processor Microcode (Patience)" msg_info "Downloading the AMD Processor Microcode Package $microcode"
dpkg -i amd64-microcode_3.20230808.1.1_amd64.deb &>/dev/null wget -q https://ftp.debian.org/debian/pool/non-free-firmware/a/amd64-microcode/$microcode
msg_ok "Installed the AMD Processor Microcode" msg_ok "Downloaded the AMD Processor Microcode Package $microcode"
msg_info "Installing $microcode (Patience)"
dpkg -i $microcode &>/dev/null
msg_ok "Installed $microcode"
msg_info "Cleaning up" msg_info "Cleaning up"
rm amd64-microcode_3.20230808.1.1_amd64.deb rm $microcode
msg_ok "Cleaned" msg_ok "Cleaned"
echo -e "\nIn order to apply the changes, a system reboot will be necessary.\n"
echo -e "\n To apply the changes, the system will need to be rebooted.\n"
} }
if ! command -v pveversion >/dev/null 2>&1; then if ! command -v pveversion >/dev/null 2>&1; then header_info; msg_error "No PVE Detected!"; exit; fi
header_info
msg_error "\n No PVE Detected!\n" 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
exit
fi
msg_info "Checking CPU Vendor" msg_info "Checking CPU Vendor"
cpu=$(lscpu | grep -oP 'Vendor ID:\s*\K\S+' | head -n 1) cpu=$(lscpu | grep -oP 'Vendor ID:\s*\K\S+' | head -n 1)
if [ "$cpu" == "GenuineIntel" ]; then if [ "$cpu" == "GenuineIntel" ]; then
msg_ok "${cpu} was detected" msg_ok "${cpu} was detected"
sleep 1
intel intel
elif [ "$cpu" == "AuthenticAMD" ]; then elif [ "$cpu" == "AuthenticAMD" ]; then
msg_ok "${cpu} was detected" msg_ok "${cpu} was detected"
sleep 1
amd amd
else else
msg_error "${cpu} is not supported" msg_error "${cpu} is not supported"

Loading…
Cancel
Save

Powered by BW's shoe-string budget.