mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-06-28 04:06:54 +00:00
Update configure_igpu.sh
This commit is contained in:
parent
23c565b07f
commit
358a4edc98
@ -1,36 +1,46 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Variables globales
|
# ==========================================================
|
||||||
CHANGES_MADE=0 # Indica si se hicieron cambios en el contenedor
|
# ProxMenu - A menu-driven script for Proxmox VE management
|
||||||
|
# ==========================================================
|
||||||
|
# Author : MacRimi
|
||||||
|
# Copyright : (c) 2024 MacRimi
|
||||||
|
# License : MIT (https://raw.githubusercontent.com/MacRimi/ProxMenux/main/LICENSE)
|
||||||
|
# Version : 1.0
|
||||||
|
# Last Updated: 28/01/2025
|
||||||
|
# ==========================================================
|
||||||
|
|
||||||
# Colores para salida
|
|
||||||
YW="\033[33m"
|
|
||||||
GN="\033[1;92m"
|
|
||||||
RD="\033[01;31m"
|
|
||||||
CL="\033[m"
|
|
||||||
|
|
||||||
# Funciones auxiliares
|
# Configuration ============================================
|
||||||
log() {
|
REPO_URL="https://raw.githubusercontent.com/MacRimi/ProxMenux/main"
|
||||||
echo -e "$(date '+%Y-%m-%d %H:%M:%S') - $1"
|
UTILS_URL="https://raw.githubusercontent.com/MacRimi/ProxMenux/main/scripts/utils.sh"
|
||||||
}
|
BASE_DIR="/usr/local/share/proxmenux"
|
||||||
msg_info() {
|
CACHE_FILE="$BASE_DIR/cache.json"
|
||||||
echo -ne " ${YW}[INFO] $1...${CL}"
|
CONFIG_FILE="$BASE_DIR/config.json"
|
||||||
}
|
VENV_PATH="/opt/googletrans-env"
|
||||||
msg_ok() {
|
|
||||||
echo -e " ${GN}[OK] $1${CL}"
|
|
||||||
}
|
|
||||||
msg_error() {
|
|
||||||
echo -e " ${RD}[ERROR] $1${CL}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Validar que el contenedor seleccionado es válido
|
if ! source <(curl -sSf "$UTILS_URL"); then
|
||||||
validate_container_id() {
|
echo "$(translate 'Error: Could not load utils.sh from') $UTILS_URL"
|
||||||
if [ -z "$CONTAINER_ID" ]; then
|
|
||||||
msg_error "ID del contenedor no definido. Asegúrate de seleccionar un contenedor primero."
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
initialize_cache() {
|
||||||
|
if [ ! -f "$CACHE_FILE" ]; then
|
||||||
|
echo "{}" > "$CACHE_FILE"
|
||||||
|
return
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
load_language() {
|
||||||
|
if [ -f "$CONFIG_FILE" ]; then
|
||||||
|
LANGUAGE=$(jq -r '.language' "$CONFIG_FILE")
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# ==========================================================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Selección del contenedor LXC
|
# Selección del contenedor LXC
|
||||||
select_container() {
|
select_container() {
|
||||||
CONTAINERS=$(pct list | awk 'NR>1 {print $1, $3}' | xargs -n2)
|
CONTAINERS=$(pct list | awk 'NR>1 {print $1, $3}' | xargs -n2)
|
||||||
@ -47,12 +57,38 @@ select_container() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! pct list | awk 'NR>1 {print $1}' | grep -qw "$CONTAINER_ID"; then
|
||||||
|
msg_error "El contenedor con ID $CONTAINER_ID no existe. Saliendo."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
msg_ok "Contenedor seleccionado: $CONTAINER_ID"
|
msg_ok "Contenedor seleccionado: $CONTAINER_ID"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Validar y cambiar a privilegiado si es necesario
|
||||||
|
ensure_privileged_container() {
|
||||||
|
validate_container_id
|
||||||
|
CONFIG_FILE="/etc/pve/lxc/${CONTAINER_ID}.conf"
|
||||||
|
if [ ! -f "$CONFIG_FILE" ]; then
|
||||||
|
msg_error "Archivo de configuración del contenedor $CONTAINER_ID no encontrado."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep -q "^unprivileged: 1" "$CONFIG_FILE"; then
|
||||||
|
msg_info "El contenedor es no privilegiado. Cambiando a privilegiado..."
|
||||||
|
sed -i "s/^unprivileged: 1/unprivileged: 0/" "$CONFIG_FILE"
|
||||||
|
STORAGE_TYPE=$(pct config "$CONTAINER_ID" | grep "^rootfs:" | awk -F, '{print $2}' | cut -d'=' -f2)
|
||||||
|
if [[ "$STORAGE_TYPE" == "dir" ]]; then
|
||||||
|
STORAGE_PATH=$(pct config "$CONTAINER_ID" | grep "^rootfs:" | awk '{print $2}' | cut -d',' -f1)
|
||||||
|
chown -R root:root "$STORAGE_PATH"
|
||||||
|
fi
|
||||||
|
msg_ok "Contenedor cambiado a privilegiado."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Configurar iGPU en el contenedor
|
# Configurar iGPU en el contenedor
|
||||||
configure_lxc_for_igpu() {
|
configure_lxc_for_igpu() {
|
||||||
validate_container_id
|
ensure_privileged_container
|
||||||
CONFIG_FILE="/etc/pve/lxc/${CONTAINER_ID}.conf"
|
CONFIG_FILE="/etc/pve/lxc/${CONTAINER_ID}.conf"
|
||||||
|
|
||||||
if ! grep -q "features: nesting=1" "$CONFIG_FILE"; then
|
if ! grep -q "features: nesting=1" "$CONFIG_FILE"; then
|
||||||
@ -63,6 +99,15 @@ configure_lxc_for_igpu() {
|
|||||||
echo "lxc.cgroup2.devices.allow: c 226:0 rwm # iGPU" >> "$CONFIG_FILE"
|
echo "lxc.cgroup2.devices.allow: c 226:0 rwm # iGPU" >> "$CONFIG_FILE"
|
||||||
echo "lxc.cgroup2.devices.allow: c 226:128 rwm # iGPU" >> "$CONFIG_FILE"
|
echo "lxc.cgroup2.devices.allow: c 226:128 rwm # iGPU" >> "$CONFIG_FILE"
|
||||||
echo "lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir" >> "$CONFIG_FILE"
|
echo "lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir" >> "$CONFIG_FILE"
|
||||||
|
echo "lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file" >> "$CONFIG_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! grep -q "c 29:0 rwm # Framebuffer" "$CONFIG_FILE"; then
|
||||||
|
echo "lxc.cgroup2.devices.allow: c 29:0 rwm # Framebuffer" >> "$CONFIG_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! grep -q "lxc.mount.entry: /dev/fb0" "$CONFIG_FILE"; then
|
||||||
|
echo "lxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=file" >> "$CONFIG_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
msg_ok "Configuración de iGPU añadida al contenedor $CONTAINER_ID."
|
msg_ok "Configuración de iGPU añadida al contenedor $CONTAINER_ID."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user