WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Detect Hardware and Download TCZ  (Read 82 times)

Offline Zendrael

  • Sr. Member
  • ****
  • Posts: 370
    • Zendrael's home of projects
Detect Hardware and Download TCZ
« on: May 07, 2025, 11:13:07 AM »
Hello!

Can anyone test if it works on your machine? It worked for me on an older Desktop PC but not on my current laptop... Any ideas or suggestions are appreciated!

PLEASE NOTE: some changes to package names IS required to make it really generic...

Code: [Select]
#!/bin/sh
# TinyCore Hardware Detection Script
# Detects hardware and suggests appropriate extensions to load
# Works on any hardware configuration

# Output files
DETECTED_HW="/tmp/detected_hardware.txt"
SUGGESTED_EXT="/tmp/suggested_extensions.txt"

# Clear previous files if they exist
rm -f "$DETECTED_HW" "$SUGGESTED_EXT"

echo "=== TinyCore Hardware Detection Script ==="
echo "Scanning system hardware..."

# Function to add a suggested extension
suggest_extension() {
    echo "$1" >> "$SUGGESTED_EXT"
}

# Detect CPU
echo "\n--- CPU Information ---" >> "$DETECTED_HW"
cpu_vendor=$(grep -m 1 "vendor_id" /proc/cpuinfo | awk '{print $3}')
cpu_model=$(grep -m 1 "model name" /proc/cpuinfo | sed 's/^.*: //')
echo "CPU: $cpu_vendor $cpu_model" | tee -a "$DETECTED_HW"

# Suggest CPU-specific extensions
case "$cpu_vendor" in
    "GenuineIntel")
        suggest_extension "intel-microcode"
        ;;
    "AuthenticAMD")
        suggest_extension "amd-microcode"
        ;;
esac

# Detect Graphics
echo "\n--- Graphics Cards ---" >> "$DETECTED_HW"
lspci | grep -i 'vga\|3d\|2d' | tee -a "$DETECTED_HW"

# Graphics cards detection and suggestions
if lspci | grep -i "intel.*graphics" > /dev/null; then
    echo "- Intel graphics detected" | tee -a "$DETECTED_HW"
    suggest_extension "xorg-video-intel"
fi

if lspci | grep -i "nvidia" > /dev/null; then
    echo "- NVIDIA graphics detected" | tee -a "$DETECTED_HW"
    suggest_extension "xorg-video-nouveau"
    suggest_extension "nvidia"  # Proprietary driver option
fi

if lspci | grep -i "amd\|ati" > /dev/null; then
    echo "- AMD/ATI graphics detected" | tee -a "$DETECTED_HW"
    suggest_extension "xorg-video-amdgpu"
    suggest_extension "xorg-video-ati"  # For older cards
fi

# Generic fallback for any other graphics cards
if ! (lspci | grep -i -E "intel.*graphics|nvidia|amd|ati" > /dev/null); then
    echo "- Generic/other graphics detected" | tee -a "$DETECTED_HW"
    suggest_extension "xorg-video-vesa"  # Generic VESA driver that works with most cards
    suggest_extension "xorg-video-fbdev"  # Framebuffer driver
fi

# Network devices
echo "\n--- Network Devices ---" >> "$DETECTED_HW"
lspci | grep -i 'net\|ethernet\|wireless' | tee -a "$DETECTED_HW"

# Wireless detection - check both PCI and USB devices
if lspci | grep -i -E "wireless|wifi" > /dev/null || lsusb | grep -i -E "wireless|wifi" > /dev/null; then
    echo "- Wireless adapter detected" | tee -a "$DETECTED_HW"
   
    # Check for specific wireless chipsets (PCI)
    if lspci | grep -i "intel.*wireless" > /dev/null; then
        echo "  - Intel wireless chipset" | tee -a "$DETECTED_HW"
        suggest_extension "firmware-iwlwifi"
    fi
   
    if lspci | grep -i "broadcom" > /dev/null || lsusb | grep -i "broadcom" > /dev/null; then
        echo "  - Broadcom wireless chipset" | tee -a "$DETECTED_HW"
        suggest_extension "b43-firmware"
        suggest_extension "broadcom-wl"
    fi
   
    if lspci | grep -i "realtek" > /dev/null || lsusb | grep -i "realtek" > /dev/null; then
        echo "  - Realtek wireless chipset" | tee -a "$DETECTED_HW"
        suggest_extension "firmware-rtlwifi"
    fi
   
    if lspci | grep -i "atheros" > /dev/null || lsusb | grep -i "atheros" > /dev/null; then
        echo "  - Atheros wireless chipset" | tee -a "$DETECTED_HW"
        suggest_extension "ath9k-firmware"
    fi
   
    if lspci | grep -i "ralink" > /dev/null || lsusb | grep -i "ralink" > /dev/null; then
        echo "  - Ralink wireless chipset" | tee -a "$DETECTED_HW"
        suggest_extension "rt2800-firmware"
    fi
   
    if lsusb | grep -i "mediatek" > /dev/null; then
        echo "  - MediaTek wireless chipset" | tee -a "$DETECTED_HW"
        suggest_extension "mt7601-firmware"
    fi
   
    # Common wireless tools regardless of chipset
    suggest_extension "wireless_tools"
    suggest_extension "wpa_supplicant"
    suggest_extension "wireless"
    suggest_extension "wifi"
fi

# Audio devices
echo "\n--- Audio Devices ---" >> "$DETECTED_HW"
lspci | grep -i audio | tee -a "$DETECTED_HW"

if lspci | grep -i audio > /dev/null; then
    echo "- Audio hardware detected" | tee -a "$DETECTED_HW"
    suggest_extension "alsa"
    suggest_extension "alsa-utils"
    suggest_extension "pulseaudio"
fi

# Check for webcam
echo "\n--- Webcam Detection ---" >> "$DETECTED_HW"
if lsusb | grep -i "camera\|webcam\|cam" > /dev/null; then
    echo "- Webcam detected" | tee -a "$DETECTED_HW"
    lsusb | grep -i "camera\|webcam\|cam" | tee -a "$DETECTED_HW"
    suggest_extension "v4l-utils"
    suggest_extension "uvc-driver"
fi

# Check for input devices
echo "\n--- Input Devices ---" >> "$DETECTED_HW"
cat /proc/bus/input/devices >> "$DETECTED_HW" 2>/dev/null

# Input device detection - check for various types
if grep -i -E "touch|synap|glide|track" /proc/bus/input/devices > /dev/null 2>&1; then
    echo "- Touchpad detected" | tee -a "$DETECTED_HW"
    suggest_extension "xorg-input-synaptics"
    suggest_extension "xorg-input-libinput"
fi

if grep -i -E "tablet|wacom|pen" /proc/bus/input/devices > /dev/null 2>&1; then
    echo "- Tablet/drawing device detected" | tee -a "$DETECTED_HW"
    suggest_extension "xorg-input-wacom"
fi

# Always suggest basic input drivers for mice and keyboards
echo "- Adding basic input device drivers" | tee -a "$DETECTED_HW"
suggest_extension "xorg-input-evdev"
suggest_extension "xorg-input-libinput"

# Check for Bluetooth
if lsusb | grep -i "bluetooth" > /dev/null || lspci | grep -i "bluetooth" > /dev/null; then
    echo "- Bluetooth hardware detected" | tee -a "$DETECTED_HW"
    lsusb | grep -i "bluetooth" | tee -a "$DETECTED_HW"
    suggest_extension "bluez"
    suggest_extension "bluez-utils"
fi

# Always recommend Xorg and base utilities
echo "\n--- Recommending base X environment ---" | tee -a "$DETECTED_HW"
suggest_extension "Xorg-7.7-3d"
suggest_extension "Xlibs"
suggest_extension "Xproto"
suggest_extension "xauth"
suggest_extension "xinit"

# Recommend window manager based on system resources
mem_total=$(grep MemTotal /proc/meminfo | awk '{print $2}')
echo "Total system memory: ${mem_total}KB" | tee -a "$DETECTED_HW"

if [ "$mem_total" -lt 524288 ]; then  # Less than 512MB
    echo "Low memory system detected, suggesting minimal window manager" | tee -a "$DETECTED_HW"
    suggest_extension "flwm"  # Ultra lightweight window manager
    suggest_extension "aterm"  # Minimal terminal
elif [ "$mem_total" -lt 1048576 ]; then  # Less than 1GB
    echo "Medium memory system detected, suggesting lightweight window manager" | tee -a "$DETECTED_HW"
    suggest_extension "jwm"   # Lightweight window manager
    suggest_extension "aterm"
    suggest_extension "wbar"  # Application launcher
else  # 1GB or more
    echo "Sufficient memory detected, suggesting standard window manager" | tee -a "$DETECTED_HW"
    suggest_extension "openbox"  # More feature-rich window manager
    suggest_extension "tint2"    # Panel/taskbar
    suggest_extension "xterm"
    suggest_extension "pcmanfm"  # File manager
fi

# Recommend common utilities
echo "\n--- Recommending common utilities ---" | tee -a "$DETECTED_HW"
suggest_extension "bash"
suggest_extension "coreutils"
suggest_extension "nano"
suggest_extension "gzip"
suggest_extension "tar"
suggest_extension "wget"
suggest_extension "ntfs-3g"
suggest_extension "exfat-utils"
suggest_extension "zip"
suggest_extension "unzip"
suggest_extension "htop"      # System monitor
suggest_extension "curl"      # Network utility

# Output suggested tce load command
echo "\n=== Suggested Extensions ==="
echo "Based on your hardware, the following extensions are recommended:"
cat "$SUGGESTED_EXT" | sort | uniq | tee "/home/tc/recommended_extensions.txt"

# Create a script to load all recommended extensions
cat > "/home/tc/load_extensions.sh" << EOF
#!/bin/sh
# Auto-generated script to load recommended extensions

for ext in \$(cat /home/tc/recommended_extensions.txt); do
    echo "Loading \$ext..."
    tce-load -wi "\$ext" || echo "Warning: Failed to install \$ext"
done

echo "Done loading extensions"
EOF

chmod +x "/home/tc/load_extensions.sh"

# Create an onboot.lst file for extensions
echo "Creating onboot.lst file with recommended extensions..."
cat "$SUGGESTED_EXT" | sort | uniq > "/home/tc/onboot.lst"
echo "Created /home/tc/onboot.lst"

# Create mydata.tgz setup script for persistent configurations
cat > "/home/tc/setup_persistence.sh" << EOF
#!/bin/sh
# Creates mydata.tgz with recommended configurations

# Create X configuration directory
mkdir -p /tmp/xorg/etc/X11

# Create basic xorg.conf that should work on most systems
cat > /tmp/xorg/etc/X11/xorg.conf << XORG
Section "ServerLayout"
    Identifier     "Default Layout"
    Screen         0  "Screen0" 0 0
    InputDevice    "Mouse0" "CorePointer"
    InputDevice    "Keyboard0" "CoreKeyboard"
EndSection

Section "InputDevice"
    Identifier     "Keyboard0"
    Driver         "kbd"
    Option         "XkbLayout" "us"
EndSection

Section "InputDevice"
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/input/mice"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    Option         "DPMS" "true"
EndSection

Section "Device"
    Identifier     "Card0"
    # Driver will be automatically selected
EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Card0"
    Monitor        "Monitor0"
    DefaultDepth    24
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection
XORG

# Create backup.lst for filetool
mkdir -p /tmp/xorg/opt
cat > /tmp/xorg/opt/.filetool.lst << BACKUP
/etc/X11
/home/tc/.xinitrc
/home/tc/.Xdefaults
/home/tc/onboot.lst
BACKUP

# Create a simple .xinitrc
cat > /tmp/xorg/.xinitrc << XINITRC
#!/bin/sh
xsetroot -solid darkgrey &

# If a window manager is detected, use it
if command -v openbox >/dev/null; then
  exec openbox
elif command -v jwm >/dev/null; then
  exec jwm
elif command -v flwm >/dev/null; then
  exec flwm
else
  # Fallback to twm if it exists
  if command -v twm >/dev/null; then
    exec twm
  fi
fi
XINITRC

# Make the mydata.tgz
cd /tmp/xorg
tar czf /home/tc/mydata.tgz .
cd /home/tc
echo "Created /home/tc/mydata.tgz with basic X configuration"
EOF

chmod +x "/home/tc/setup_persistence.sh"

echo "\n=== Next Steps ==="
echo "1. Extension list saved to /home/tc/recommended_extensions.txt"
echo "2. To install all recommended extensions, run: /home/tc/load_extensions.sh"
echo "3. To have extensions load on boot, copy onboot.lst to your TCE directory:"
echo "   cp /home/tc/onboot.lst /tce/onboot.lst"
echo "4. To set up basic X configuration, run: /home/tc/setup_persistence.sh"
echo "5. To use the persistent configuration: tce-load -i Xorg-7.7-3d; mv /home/tc/mydata.tgz /opt/"
echo "   Then reboot with 'mydata.tgz' as a boot parameter"
echo ""
echo "Hardware detection complete! Full hardware report in $DETECTED_HW"
« Last Edit: May 07, 2025, 11:17:08 AM by Zendrael »

Offline CentralWare

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 838
Re: Detect Hardware and Download TCZ
« Reply #1 on: May 07, 2025, 08:24:21 PM »
Good evening, @Zendrael!

I just did a quick viewing and can already tell you "generic" won't cover it as it stands.

1. lspci and lsusb are not installed by default on any existing release, so you're assuming wireless and/or Ethernet are online using generic drivers that DO come with the running kernel - which for me, covers about 1/2 of the hardware we test on.

2. Networking can't call home to the repo to suggest or install extensions if networking drivers aren't available.  (I have a Tyan motherboard, for example, which require a number of drivers to make HDD and ETH0 functional.)

3. Based on your inclusion of Xorg.conf entries it's assumed Xorg is installed.

To create a truly beneficial hardware management system, you'd have to first start off with a reasonably complete kernel for networking along with support files for wireless.  These excess drivers only need to be loaded if eth0/wlan0 are not already found.  Afterward, scan for a working eth0 - if it's unplugged, load wireless drivers (many people have Ethernet ports...  but nothing to plug them into - wireless only options.)  Finally, based on the above results, load wireless tools if necessary.

Good luck!