aboutsummaryrefslogtreecommitdiffstats
path: root/system/usr
diff options
context:
space:
mode:
Diffstat (limited to 'system/usr')
-rwxr-xr-xsystem/usr/gpu-toggle18
1 files changed, 13 insertions, 5 deletions
diff --git a/system/usr/gpu-toggle b/system/usr/gpu-toggle
index 4325829..35d6c47 100755
--- a/system/usr/gpu-toggle
+++ b/system/usr/gpu-toggle
@@ -11,12 +11,15 @@ DEVICE_ID="57:00.0"
PCI_PATH="/sys/bus/pci/devices/0000:$DEVICE_ID"
REQUIRED_MODULES=("nvidia_drm" "nvidia_modeset" "nvidia_uvm" "nvidia")
-if [[ $EUID -ne 0 ]]; then
- echo "[ERROR] Elevated privileges required. Please execute with sudo."
- exit 1
-fi
+check_sudo() {
+ if [[ $EUID -ne 0 ]]; then
+ echo "[ERROR] Elevated privileges required. Please execute with sudo."
+ exit 1
+ fi
+}
check_status() {
+ local is_active=0
echo "--- System Graphics Status ---"
if [ -d "$PCI_PATH" ]; then
echo "Hardware State: [ ONLINE ] at $DEVICE_ID"
@@ -25,14 +28,18 @@ check_status() {
else
echo "Driver State: [ UNLOADED ]"
fi
+ is_active=0
else
echo "Hardware State: [ OFFLINE ] (Device removed from PCI bus)"
echo "Driver State: [ UNLOADED ]"
+ is_active=1
fi
echo "------------------------------"
+ return $is_active
}
disable_gpu() {
+ check_sudo
echo "[INFO] Initializing dGPU shutdown sequence..."
# 1. Unload Kernel Modules
@@ -57,6 +64,7 @@ disable_gpu() {
}
enable_gpu() {
+ check_sudo
echo "[INFO] Initializing dGPU activation sequence..."
# 1. Trigger PCI Rescan
@@ -82,6 +90,6 @@ enable_gpu() {
case "$1" in
on) enable_gpu ;;
off) disable_gpu ;;
- status) check_status ;;
+ status) check_status; exit $? ;;
*) echo "Usage: gpu-toggle {on|off|status}" ;;
esac