#!/bin/bash

# Script to check and display Raspberry Pi parameters using libgpiod

echo "=== Raspberry Pi System Information ==="

# General system information
echo "Hostname: $(hostname)"
echo "Model: $(cat /proc/device-tree/model | tr -d '\0')"
echo "CPU Temperature: $(vcgencmd measure_temp | cut -d '=' -f2)"
echo "CPU Frequency: $(vcgencmd measure_clock arm | awk -F= '{print $2}') Hz"
echo "GPU Frequency: $(vcgencmd measure_clock core | awk -F= '{print $2}') Hz"
echo "Voltage: $(vcgencmd measure_volts | cut -d '=' -f2)"

# Memory and disk usage
echo "Total Memory: $(free -h | grep Mem | awk '{print $2}')"
echo "Used Memory: $(free -h | grep Mem | awk '{print $3}')"
echo "Free Memory: $(free -h | grep Mem | awk '{print $4}')"
echo "Disk Usage:"
df -h | grep '^/dev/root'

# Network information
echo "IP Address: $(hostname -I | awk '{print $1}')"
echo "MAC Address: $(cat /sys/class/net/eth0/address 2>/dev/null || echo 'No Ethernet')"

# Uptime
echo "Uptime: $(uptime -p)"
echo "Last Boot: $(who -b | awk '{print $3, $4}')"

# GPIO Information using libgpiod
echo "GPIO Chip Info:"
if command -v gpioinfo &>/dev/null; then
    gpioinfo
else
    echo "gpiod tools not installed. Please install libgpiod using 'sudo apt install gpiod'."
fi

echo "=== End of Raspberry Pi System Information ==="
