This commit is contained in:
2026-02-11 22:03:06 +00:00
parent 3030d51fd1
commit 547fb2c462
9 changed files with 2038 additions and 0 deletions
+435
View File
@@ -0,0 +1,435 @@
#!/bin/bash
# =============================================
# Welcome Script for Raspberry Pi/Debian Login
# Displays comprehensive system information in an appealing format
# =============================================
# Function to print separators
print_separator() {
printf "%*s\n" "${COLUMNS:-$(tput cols)}" '' | tr ' ' '='
}
# Function to print section titles
print_title() {
echo -e "\n\033[1;34m$1\033[0m" # Bold blue
print_separator
}
# Function to print labeled values
print_value() {
printf "\033[1;32m%-25s\033[0m %s\n" "$1:" "$2" # Bold green for label
}
# Function to detect system type
detect_system_type() {
local model=""
local system_type=""
# Check for Raspberry Pi
if [ -f /proc/device-tree/model ]; then
model=$(tr -d '\0' < /proc/device-tree/model)
if [[ "$model" == *"Raspberry Pi"* ]]; then
system_type="Raspberry Pi - $model"
else
system_type="ARM Device - $model"
fi
# Check for other common SBCs
elif grep -q "Orange Pi" /proc/cpuinfo 2>/dev/null; then
system_type="Orange Pi"
elif grep -q "Banana Pi" /proc/cpuinfo 2>/dev/null; then
system_type="Banana Pi"
elif grep -q "Odroid" /proc/cpuinfo 2>/dev/null; then
system_type="Odroid"
# Check for x86/x86_64 systems
elif grep -q "x86" /proc/cpuinfo 2>/dev/null; then
if grep -q "64" /proc/cpuinfo 2>/dev/null; then
system_type="x86_64 System"
else
system_type="x86 System"
fi
else
system_type="Unknown System"
fi
echo "$system_type"
}
# Function to get processor info
get_processor_info() {
local processor=""
local cores=""
local architecture=""
# Get processor model
if [ -f /proc/cpuinfo ]; then
processor=$(grep -m 1 "model name" /proc/cpuinfo | cut -d':' -f2 | sed 's/^ *//')
if [ -z "$processor" ]; then
processor=$(grep -m 1 "Processor" /proc/cpuinfo | cut -d':' -f2 | sed 's/^ *//')
fi
if [ -z "$processor" ]; then
processor=$(grep -m 1 "Hardware" /proc/cpuinfo | cut -d':' -f2 | sed 's/^ *//')
fi
fi
# Get number of cores
cores=$(grep -c "^processor" /proc/cpuinfo 2>/dev/null)
if [ -z "$cores" ] || [ "$cores" = "0" ]; then
cores=$(nproc 2>/dev/null)
fi
# Get architecture
architecture=$(uname -m 2>/dev/null)
# Format output
if [ -n "$processor" ]; then
echo "$processor ($cores cores, $architecture)"
else
echo "Unknown ($cores cores, $architecture)"
fi
}
# Function to get OS info
get_os_info() {
local os_name=""
local os_version=""
local kernel_version=""
# Get OS name and version
if [ -f /etc/os-release ]; then
os_name=$(grep "^PRETTY_NAME=" /etc/os-release | cut -d'"' -f2)
os_version=$(grep "^VERSION=" /etc/os-release | cut -d'"' -f2)
elif [ -f /etc/debian_version ]; then
os_name="Debian"
os_version=$(cat /etc/debian_version)
fi
# Get kernel version
kernel_version=$(uname -r)
# Format output
if [ -n "$os_name" ]; then
if [ -n "$os_version" ]; then
echo "$os_name $os_version (Kernel: $kernel_version)"
else
echo "$os_name (Kernel: $kernel_version)"
fi
else
echo "Unknown OS (Kernel: $kernel_version)"
fi
}
# Function to get GPU info (Raspberry Pi specific)
get_gpu_info() {
local gpu_mem=""
local gpu_model=""
# Check if vcgencmd is available (Raspberry Pi)
if command -v vcgencmd >/dev/null 2>&1; then
gpu_mem=$(vcgencmd get_mem gpu | cut -d'=' -f2)
gpu_model="VideoCore IV"
else
gpu_mem="Not available"
# Try to get GPU info from lspci
if command -v lspci >/dev/null 2>&1; then
gpu_model=$(lspci | grep -i vga | cut -d':' -f3 | sed 's/^ *//')
if [ -z "$gpu_model" ]; then
gpu_model="Unknown GPU"
fi
else
gpu_model="Unknown GPU"
fi
fi
echo "$gpu_model ($gpu_mem)"
}
# Function to get system load
get_system_load() {
local load_avg=""
local uptime_info=""
load_avg=$(uptime | awk -F'load average: ' '{print $2}')
uptime_info=$(uptime -p)
echo "Load: $load_avg | Uptime: $uptime_info"
}
# Function to get network connections
get_network_connections() {
local connections=""
if command -v ss >/dev/null 2>&1; then
connections=$(ss -s | grep "TCP:" | awk '{print $2 " connections"}')
elif command -v netstat >/dev/null 2>&1; then
connections=$(netstat -tun | grep -c ESTABLISHED)
connections="$connections active connections"
else
connections="Not available"
fi
echo "$connections"
}
# =============================================
# System Information
# =============================================
# Welcome header
clear
print_separator
echo -e "\033[1;36m" # Bold cyan
figlet -f small "Welcome to $(hostname)"
echo -e "\033[0m"
print_separator
# System Overview
print_title "System Overview"
print_value "System Type" "$(detect_system_type)"
print_value "Processor" "$(get_processor_info)"
print_value "Operating System" "$(get_os_info)"
print_value "GPU" "$(get_gpu_info)"
print_value "System Load" "$(get_system_load)"
# Current date and time
print_title "General Information"
print_value "Date/Time" "$(date '+%Y-%m-%d %H:%M:%S')"
print_value "User" "$(whoami)"
print_value "Hostname" "$(hostname)"
print_value "IP Address" "$(hostname -I | awk '{print $1}')"
print_value "Active Network Connections" "$(get_network_connections)"
# =============================================
# CPU Information
# =============================================
print_title "CPU Status"
# CPU Temperature
temp=$(vcgencmd measure_temp 2>/dev/null | awk -F'=' '{print $2}' | awk -F"'" '{print $1}')
if [ -n "$temp" ]; then
print_value "Temperature" "$temp°C"
else
# Try alternative method for non-RPi systems
if [ -f /sys/class/thermal/thermal_zone0/temp ]; then
temp=$(cat /sys/class/thermal/thermal_zone0/temp)
temp=$(echo "scale=1; $temp/1000" | bc 2>/dev/null)
print_value "Temperature" "${temp}°C"
else
print_value "Temperature" "Not available"
fi
fi
# CPU Frequencies
arm_freq=$(vcgencmd measure_clock arm 2>/dev/null | awk -F'=' '{print $2}')
core_freq=$(vcgencmd measure_clock core 2>/dev/null | awk -F'=' '{print $2}')
if [ -n "$arm_freq" ]; then
print_value "ARM Frequency" "$(echo "scale=2; $arm_freq/1000000" | bc) MHz"
fi
if [ -n "$core_freq" ]; then
print_value "Core Frequency" "$(echo "scale=2; $core_freq/1000000" | bc) MHz"
fi
# CPU Usage
cpu_usage=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}')
print_value "CPU Usage" "$(printf "%.1f" $cpu_usage)%"
# =============================================
# Memory Information
# =============================================
print_title "Memory"
# Total and used memory
total_mem=$(free -m | awk '/Mem:/ {print $2}')
used_mem=$(free -m | awk '/Mem:/ {print $3}')
mem_percent=$(echo "scale=1; $used_mem/$total_mem*100" | bc)
print_value "Total Memory" "$total_mem MB"
print_value "Used Memory" "$used_mem MB ($mem_percent%)"
# Swap information
total_swap=$(free -m | awk '/Swap:/ {print $2}')
used_swap=$(free -m | awk '/Swap:/ {print $3}')
if [ "$total_swap" -gt 0 ]; then
swap_percent=$(echo "scale=1; $used_swap/$total_swap*100" | bc)
print_value "Total Swap" "$total_swap MB"
print_value "Used Swap" "$used_swap MB ($swap_percent%)"
else
print_value "Swap" "Not enabled"
fi
# =============================================
# Storage Information
# =============================================
print_title "Storage"
# Disk space
root_usage=$(df -h / | awk 'NR==2 {print $5}')
root_size=$(df -h / | awk 'NR==2 {print $2}')
root_avail=$(df -h / | awk 'NR==2 {print $4}')
print_value "Root Partition" "$root_size total, $root_usage used, $root_avail available"
# Boot partition space (if exists)
if [ -d "/boot" ]; then
boot_usage=$(df -h /boot | awk 'NR==2 {print $5}')
boot_size=$(df -h /boot | awk 'NR==2 {print $2}')
boot_avail=$(df -h /boot | awk 'NR==2 {print $4}')
print_value "Boot Partition" "$boot_size total, $boot_usage used, $boot_avail available"
fi
# Disk I/O (if available)
if command -v iostat >/dev/null 2>&1; then
disk_io=$(iostat -d -x 1 1 | grep -A1 "Device" | tail -n +2)
if [ -n "$disk_io" ]; then
print_value "Disk I/O" "\n$disk_io"
fi
fi
# =============================================
# Network Information
# =============================================
print_title "Network"
# Network interfaces
interfaces=$(ip -o link show | awk -F': ' '{print $2}' | tr '\n' ' ')
print_value "Interfaces" "$interfaces"
# IP addresses for each interface
for iface in $(ip -o link show | awk -F': ' '{print $2}'); do
ip_addr=$(ip -4 addr show $iface 2>/dev/null | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | tr '\n' ' ')
if [ -n "$ip_addr" ]; then
print_value " $iface IP" "$ip_addr"
fi
done
# Network speed (if available)
if command -v ethtool >/dev/null 2>&1; then
for iface in eth0 enp0s3 enx*; do
if ip link show $iface >/dev/null 2>&1; then
eth_speed=$(ethtool $iface 2>/dev/null | grep -i speed | awk '{print $2}')
if [ -n "$eth_speed" ]; then
print_value " $iface Speed" "$eth_speed"
fi
fi
done
fi
# Network connections
print_value "Active Connections" "$(get_network_connections)"
# =============================================
# Additional System Information
# =============================================
print_title "Additional Information"
# Last login - with fallback if 'last' command is not available
if command -v last >/dev/null 2>&1; then
last_login=$(last -n 1 $(whoami) 2>/dev/null | head -n 1 | awk '{print $1, $2, $3, $4, $5, $6, $7}')
if [ -z "$last_login" ]; then
last_login="No login history found"
fi
else
last_login="Command 'last' not available"
fi
print_value "Last Login" "$last_login"
# Users currently logged in
if command -v who >/dev/null 2>&1; then
current_users=$(who | awk '{print $1}' | sort | uniq | paste -sd ",")
if [ -z "$current_users" ]; then
current_users="No users logged in"
fi
else
current_users="Command 'who' not available"
fi
print_value "Logged in Users" "$current_users"
# System uptime in different formats
if command -v uptime >/dev/null 2>&1; then
uptime_pretty=$(uptime -p)
uptime_since=$(uptime -s)
print_value "Uptime" "$uptime_pretty (since $uptime_since)"
else
print_value "Uptime" "Command 'uptime' not available"
fi
# Running services (top 5 by memory)
print_title "Running Services"
if command -v systemctl >/dev/null 2>&1; then
echo -e "\033[1;32m UNIT LOAD ACTIVE SUB DESCRIPTION\033[0m"
echo -e " ----------------------------------------------------------------"
systemctl list-units --type=service --state=running --no-pager | head -n 6 | tail -n +2 | while read -r line; do
unit=$(echo "$line" | awk '{print $1}')
load=$(echo "$line" | awk '{print $2}')
active=$(echo "$line" | awk '{print $3}')
sub=$(echo "$line" | awk '{print $4}')
desc=$(echo "$line" | awk '{for(i=5;i<=NF;i++) printf $i" "; print ""}')
# Truncate long descriptions
if [ ${#desc} -gt 40 ]; then
desc="${desc:0:37}..."
fi
printf " \033[1;37m%-23s\033[0m \033[1;35m%-6s\033[0m \033[1;36m%-6s\033[0m \033[1;34m%-6s\033[0m %s\n" "$unit" "$load" "$active" "$sub" "$desc"
done
else
print_value "Running Services" "systemctl not available"
fi
# # Scheduled tasks (cron jobs)
# print_title "Scheduled Tasks"
# if command -v crontab >/dev/null 2>&1; then
# if crontab -l 2>/dev/null | grep -q .; then
# echo -e "\033[1;32m User Crontab:\033[0m"
# crontab -l 2>/dev/null | sed 's/^/ /'
# else
# echo -e " \033[1;33mNo user crontab entries\033[0m"
# fi
# if [ -d /etc/cron.d ] || [ -f /etc/crontab ]; then
# echo -e "\n\033[1;32m System Crontab:\033[0m"
# if [ -f /etc/crontab ]; then
# cat /etc/crontab 2>/dev/null | grep -v "^#" | grep -v "^$" | sed 's/^/ /'
# fi
# if [ -d /etc/cron.d ]; then
# for cronfile in /etc/cron.d/*; do
# if [ -f "$cronfile" ]; then
# echo -e "\n\033[1;32m $cronfile:\033[0m"
# cat "$cronfile" 2>/dev/null | grep -v "^#" | grep -v "^$" | sed 's/^/ /'
# fi
# done
# fi
# else
# echo -e " \033[1;33mNo system crontab entries\033[0m"
# fi
# else
# print_value "Scheduled Tasks" "crontab command not available"
# fi
# # Systemd timers (if available)
# if command -v systemctl >/dev/null 2>&1; then
# if systemctl list-timers --no-pager 2>/dev/null | grep -q .; then
# echo -e "\n\033[1;32m Systemd Timers:\033[0m"
# systemctl list-timers --no-pager | sed 's/^/ /'
# fi
# fi
# Open files and network connections
print_title "Open Files and Network Connections"
if command -v lsof >/dev/null 2>&1; then
echo -e "\033[1;32m Top 5 processes with most open files:\033[0m"
lsof -n | awk '{print $1}' | sort | uniq -c | sort -nr | head -n 5 | sed 's/^/ /'
echo -e "\n\033[1;32m Network connections by type:\033[0m"
echo -e " \033[1;36mTCP:\033[0m $(lsof -i TCP | wc -l)"
echo -e " \033[1;36mUDP:\033[0m $(lsof -i UDP | wc -l)"
echo -e " \033[1;36mTotal:\033[0m $(lsof -i | wc -l)"
else
print_value "Open Files" "lsof command not available"
fi
# =============================================
# Final Message
# =============================================
print_separator
echo -e "\033[1;33mSystem ready! $(date '+%H:%M')\033[0m" # Bold yellow
print_separator
echo