aboutsummaryrefslogtreecommitdiffstats
path: root/system/usr
diff options
context:
space:
mode:
authorSpacedio <spacedio@thernusen.net>2026-05-24 21:07:04 -0400
committerSpacedio <spacedio@thernusen.net>2026-05-24 21:07:04 -0400
commit7999b9ad79a5aba6b12be73a938c823fc5b329e8 (patch)
tree35fab2c4b53b498c22bb0b701957f67d52366354 /system/usr
parenta82c20fbc2d736cba174502fccbcba648ce978e9 (diff)
downloaddotfiles-7999b9ad79a5aba6b12be73a938c823fc5b329e8.tar.gz
Reorganization of files.
Diffstat (limited to 'system/usr')
-rwxr-xr-xsystem/usr/gpu-toggle87
-rwxr-xr-xsystem/usr/system-maintenance29
-rwxr-xr-xsystem/usr/system-update36
3 files changed, 152 insertions, 0 deletions
diff --git a/system/usr/gpu-toggle b/system/usr/gpu-toggle
new file mode 100755
index 0000000..4325829
--- /dev/null
+++ b/system/usr/gpu-toggle
@@ -0,0 +1,87 @@
+#!/bin/bash
+
+# -------------------------------------------------------------------------
+# GPU-TOGGLE: Discrete Graphics Power & Bus Management
+# Target: Razer Blade Stealth 13 (Late 2019) | Void Linux
+# -------------------------------------------------------------------------
+
+# Configuration: Static PCI Identifier for Turing dGPU
+# We use a static ID because the device disappears from the bus when disabled.
+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_status() {
+ echo "--- System Graphics Status ---"
+ if [ -d "$PCI_PATH" ]; then
+ echo "Hardware State: [ ONLINE ] at $DEVICE_ID"
+ if lsmod | grep -q "nvidia"; then
+ echo "Driver State: [ LOADED ]"
+ else
+ echo "Driver State: [ UNLOADED ]"
+ fi
+ else
+ echo "Hardware State: [ OFFLINE ] (Device removed from PCI bus)"
+ echo "Driver State: [ UNLOADED ]"
+ fi
+ echo "------------------------------"
+}
+
+disable_gpu() {
+ echo "[INFO] Initializing dGPU shutdown sequence..."
+
+ # 1. Unload Kernel Modules
+ echo "[STEP 1/2] Terminating NVIDIA kernel modules..."
+ for mod in "${REQUIRED_MODULES[@]}"; do
+ if lsmod | grep -q "$mod"; then
+ modprobe -r "$mod" 2>/dev/null
+ if [ $? -ne 0 ]; then
+ echo "[WARN] Module $mod is currently in use. Ensure Xorg/i3 is not using the dGPU."
+ fi
+ fi
+ done
+
+ # 2. Physical Bus Removal
+ if [ -d "$PCI_PATH" ]; then
+ echo "[STEP 2/2] Detaching device from PCI bus..."
+ echo 1 > "$PCI_PATH/remove"
+ echo "[SUCCESS] dGPU has been isolated and powered down."
+ else
+ echo "[SKIP] Device is already detached from the bus."
+ fi
+}
+
+enable_gpu() {
+ echo "[INFO] Initializing dGPU activation sequence..."
+
+ # 1. Trigger PCI Rescan
+ echo "[STEP 1/2] Scanning PCI bridge for hardware changes..."
+ echo 1 > /sys/bus/pci/rescan
+
+ # Allow firmware-level handshake
+ sleep 2
+
+ # 2. Validate and Load Drivers
+ if [ -d "$PCI_PATH" ]; then
+ echo "[STEP 2/2] Hardware detected at $DEVICE_ID. Loading modules..."
+ for mod in "nvidia" "nvidia_uvm" "nvidia_modeset" "nvidia_drm"; do
+ modprobe "$mod"
+ done
+ echo "[SUCCESS] dGPU is now online and available for Prime Offload."
+ else
+ echo "[FATAL] Hardware failed to initialize at $DEVICE_ID."
+ echo "[DEBUG] Check 'dmesg | tail' for PCI link training errors."
+ fi
+}
+
+case "$1" in
+ on) enable_gpu ;;
+ off) disable_gpu ;;
+ status) check_status ;;
+ *) echo "Usage: gpu-toggle {on|off|status}" ;;
+esac
diff --git a/system/usr/system-maintenance b/system/usr/system-maintenance
new file mode 100755
index 0000000..d2918c6
--- /dev/null
+++ b/system/usr/system-maintenance
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+# Configuration
+MARKER_FILE="/var/log/last_maintenance_timestamp"
+LOG_OUT="/var/log/maintenance.log"
+# 604800 seconds = 7 days
+INTERVAL=604800
+
+# Get last run time or 0 if file doesn't exist
+LAST_RUN=$(stat -c %Y "$MARKER_FILE" 2>/dev/null || echo 0)
+CURRENT_TIME=$(date +%s)
+
+if [ $((CURRENT_TIME - LAST_RUN)) -ge $INTERVAL ]; then
+ {
+ echo "-------------------------------------------"
+ echo "[$(date)] Starting weekly maintenance..."
+
+ # 1. Trim SSD
+ /usr/sbin/fstrim -v /
+
+ # 2. Run Backup (Example)
+ # /usr/local/bin/backup.sh 2>&1
+
+ # Update timestamp marker
+ touch "$MARKER_FILE"
+
+ echo "[$(date)] Maintenance complete."
+ } >> "$LOG_OUT" 2>&1
+fi
diff --git a/system/usr/system-update b/system/usr/system-update
new file mode 100755
index 0000000..4187e46
--- /dev/null
+++ b/system/usr/system-update
@@ -0,0 +1,36 @@
+#!/bin/bash
+# /usr/local/bin/sys-update
+# Formal system maintenance utility with administrative enforcement
+
+LOG_FILE="/var/log/system-update.log"
+
+# Administrative Privileges Check
+if [ "$EUID" -ne 0 ]; then
+ printf ":: [ERROR] This utility requires administrative privileges. Please execute with 'sudo'.\n" >&2
+ exit 1
+fi
+
+set -e
+
+log_message() {
+ printf "[$(date +'%Y-%m-%d %H:%M:%S')] %s\n" "$1" >> "$LOG_FILE"
+}
+
+log_message "START: Commencing system maintenance cycle."
+printf ":: Initializing hardware state: Activating discrete GPU...\n"
+gpu-toggle on
+
+printf ":: Synchronizing package repositories and performing system upgrade...\n"
+xbps-install -Su
+
+printf ":: Commencing filesystem optimization and orphan removal...\n"
+xbps-remove -Oo
+
+printf ":: Executing kernel image purge for obsolete versions...\n"
+vkpurge rm all
+
+printf ":: Restoring power-efficient state: Deactivating discrete GPU...\n"
+gpu-toggle off
+
+log_message "FINISH: Maintenance cycle completed successfully."
+printf ":: [SUCCESS] Operation logged to %s\n" "$LOG_FILE"