Update hw-acceleration.sh

- code refactoring
- add non-verbose option
This commit is contained in:
tteckster 2023-12-20 22:13:31 -05:00 committed by GitHub
parent c2a3eb52ca
commit d94dacc53b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 5 deletions

View File

@ -17,24 +17,55 @@ function header_info {
EOF EOF
} }
YW=$(echo "\033[33m")
BL=$(echo "\033[36m")
RD=$(echo "\033[01;31m")
GN=$(echo "\033[1;92m")
CL=$(echo "\033[m")
BFR="\\r\\033[K"
HOLD="-"
CM="${GN}${CL}"
set -e
header_info header_info
echo "Loading..." echo "Loading..."
function msg_info() {
local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..."
}
function msg_ok() {
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
}
whiptail --backtitle "Proxmox VE Helper Scripts" --title "Add Intel HW Acceleration" --yesno "This Will Add Intel HW Acceleration to an existing LXC Container. Proceed?" 8 72 || exit whiptail --backtitle "Proxmox VE Helper Scripts" --title "Add Intel HW Acceleration" --yesno "This Will Add Intel HW Acceleration to an existing LXC Container. Proceed?" 8 72 || exit
NODE=$(hostname) NODE=$(hostname)
PREV_MENU=() PREV_MENU=()
MSG_MAX_LENGTH=0 MSG_MAX_LENGTH=0
privileged_containers=$(pct list | awk 'NR>1 && system("grep -q \047unprivileged: 1\047 /etc/pve/lxc/" $1 ".conf")') privileged_containers=$(pct list | awk 'NR>1 && system("grep -q \047unprivileged: 1\047 /etc/pve/lxc/" $1 ".conf")')
if [ -z "$privileged_containers" ]; then if [ -z "$privileged_containers" ]; then
whiptail --msgbox "No Privileged Containers Found." 10 58 whiptail --msgbox "No Privileged Containers Found." 10 58
exit exit
fi fi
while read -r TAG ITEM; do while read -r TAG ITEM; do
OFFSET=2 OFFSET=2
((${#ITEM} + OFFSET > MSG_MAX_LENGTH)) && MSG_MAX_LENGTH=${#ITEM}+OFFSET ((${#ITEM} + OFFSET > MSG_MAX_LENGTH)) && MSG_MAX_LENGTH=${#ITEM}+OFFSET
PREV_MENU+=("$TAG" "$ITEM " "OFF") PREV_MENU+=("$TAG" "$ITEM " "OFF")
done < <(echo "$privileged_containers") done < <(echo "$privileged_containers")
privileged_container=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Privileged Containers on $NODE" --checklist "\nSelect a Container To Add Intel HW Acceleration:\n" 16 $((MSG_MAX_LENGTH + 23)) 6 "${PREV_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit privileged_container=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Privileged Containers on $NODE" --checklist "\nSelect a Container To Add Intel HW Acceleration:\n" 16 $((MSG_MAX_LENGTH + 23)) 6 "${PREV_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit
header_info header_info
read -r -p "Verbose mode? <y/N> " prompt
if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then
STD=""
else
STD="silent"
fi
header_info
cat <<EOF >>/etc/pve/lxc/${privileged_container}.conf cat <<EOF >>/etc/pve/lxc/${privileged_container}.conf
lxc.cgroup2.devices.allow: c 226:0 rwm lxc.cgroup2.devices.allow: c 226:0 rwm
lxc.cgroup2.devices.allow: c 226:128 rwm lxc.cgroup2.devices.allow: c 226:128 rwm
@ -43,9 +74,11 @@ lxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=file
lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir
lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file
EOF EOF
read -r -p "Do you need the intel-media-va-driver-non-free driver (Sources change)? <y/N> " prompt read -r -p "Do you need the intel-media-va-driver-non-free driver (Sources change)? <y/N> " prompt
if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then
header_info header_info
msg_info "Installing Hardware Acceleration (non-free)"
pct exec ${privileged_container} -- bash -c "cat <<EOF >/etc/apt/sources.list pct exec ${privileged_container} -- bash -c "cat <<EOF >/etc/apt/sources.list
deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
@ -58,12 +91,16 @@ deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free
deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
EOF" EOF"
pct exec ${privileged_container} -- bash -c "apt-get update && apt-get install -y intel-media-va-driver-non-free ocl-icd-libopencl1 intel-opencl-icd vainfo intel-gpu-tools && chgrp video /dev/dri && chmod 755 /dev/dri && adduser \$(id -u -n) video && adduser \$(id -u -n) render" pct exec ${privileged_container} -- bash -c "silent() { \"\$@\" >/dev/null 2>&1; } && $STD apt-get update && $STD apt-get install -y intel-media-va-driver-non-free ocl-icd-libopencl1 intel-opencl-icd vainfo intel-gpu-tools && chgrp video /dev/dri && chmod 755 /dev/dri && $STD adduser \$(id -u -n) video && $STD adduser \$(id -u -n) render"
msg_ok "Installed Hardware Acceleration (non-free)"
else else
header_info header_info
pct exec ${privileged_container} -- bash -c "apt-get install -y va-driver-all ocl-icd-libopencl1 intel-opencl-icd vainfo intel-gpu-tools && chgrp video /dev/dri && chmod 755 /dev/dri && adduser \$(id -u -n) video && adduser \$(id -u -n) render" msg_info "Installing Hardware Acceleration"
pct exec ${privileged_container} -- bash -c "silent() { \"\$@\" >/dev/null 2>&1; } && $STD apt-get install -y va-driver-all ocl-icd-libopencl1 intel-opencl-icd vainfo intel-gpu-tools && chgrp video /dev/dri && chmod 755 /dev/dri && $STD adduser \$(id -u -n) video && $STD adduser \$(id -u -n) render"
msg_ok "Installed Hardware Acceleration"
fi fi
sleep 1
whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Added tools" "vainfo, execute command 'vainfo'\nintel-gpu-tools, execute command 'intel_gpu_top'" 8 58 whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Added tools" "vainfo, execute command 'vainfo'\nintel-gpu-tools, execute command 'intel_gpu_top'" 8 58
header_info
echo -e "Completed Successfully!\n" msg_ok "Completed Successfully!\n"
echo -e "Reboot container $privileged_container to apply the new settings\n" echo -e "Reboot container ${BL}$privileged_container${CL} to apply the new settings\n"