#!/bin/sh ######################################## # Description: This script is used to get system information on arm and arm64 # systems. ######################################## ######################### # Set variables ######################### PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin ######################### # This function displays the system name. ######################### name() { value=`hostname -f` echo $value } ######################### # This function displays the operating system. ######################### os() { os=`uname -s` os_release=`uname -r | cut -d - -f 1,2` value=`echo $os $os_release` echo $value } ######################### # This function displays the operating system (full details). ######################### osfull() { os_name=`uname -s` os_version=`freebsd-version -u` arch=`getconf LONG_BIT` os_arch=`uname -m` value=`echo $os_name $os_version' ('$arch'-bit '$os_arch')'` echo $value } ######################### # This function displays the operating system (short). ######################### osshort() { value=`uname -s` echo $value } ######################### # This function displays the chassis tag number. ######################### tag() { sudo ofwdump > /dev/null 2>&1 if [ $? -eq 0 ] then value=`sudo ofwdump -P serial-number -S /` else sysctl -n hw.board.serial > /dev/null 2>&1 if [ $? -eq 0 ] then value=`sysctl -n hw.board.serial` fi value=Unknown fi echo $value } ######################### # This function finds Raspberry Pi hardware revision and outputs the memory # total. # https://www.raspberrypi.com/documentation/computers/raspberry-pi.html # last updated these values on 4/16/22 ######################### rpi_ram() { mb256_ram_models="0002 0003 0004 0005 0006 0007 0008 0009 0012" mb512_ram_models="000d 000e 000f 0010 0010 0013 0014 0015 900021 900032 \ 900092 900093 9000c1 9020e0 920092 920093 900061 902120" gb1_ram_models="a01040 a01041 a02082 a020a0 a020d3 a02042 a21041 a22042 \ a22082 a220a0 a32082 a52082 a22083 a02100 a03111 a03140" gb2_ram_models="b03111 b03112 b03114 b03140" gb4_ram_models="c03111 c03112 c03114 c03130 c03140" gb8_ram_models="d03114 d03140" revision=`sysctl -n hw.board.revision` model=`printf "0x%04x" $revision | cut -c 3-` for item in $mb256_ram_models do echo $item | grep $model > /dev/null 2>&1 if [ $? -eq 0 ] then ram_total_pretty='256 MB' fi done for item in $mb512_ram_models do echo $item | grep $model > /dev/null 2>&1 if [ $? -eq 0 ] then ram_total_pretty='512 MB' fi done for item in $gb1_ram_models do echo $item | grep $model > /dev/null 2>&1 if [ $? -eq 0 ] then ram_total_pretty='1 GB' fi done for item in $gb2_ram_models do echo $item | grep $model > /dev/null 2>&1 if [ $? -eq 0 ] then ram_total_pretty='2 GB' fi done for item in $gb4_ram_models do echo $item | grep $model > /dev/null 2>&1 if [ $? -eq 0 ] then ram_total_pretty='4 GB' fi done for item in $gb8_ram_models do echo $item | grep $model > /dev/null 2>&1 if [ $? -eq 0 ] then ram_total_pretty='8 GB' fi done } ######################### # This function calculates the RAM. ######################### ram_calculate() { ram_total_b=`sysctl -n hw.realmem` ram_total=$(echo "scale=0; $ram_total_b / 1024 / 1024" | bc) if [ $ram_total -lt 1024 ] then ram_total_mb_exact=$(echo "scale=1; $ram_total_b / 1024 / 1024" | \ bc) ram_total_mb=`echo $ram_total_mb_exact | cut -d . -f 1` remainder=`echo $ram_total_mb_exact | cut -d . -f 2` if [ $remainder -ge 5 ] then ram_total_mb=$((ram_total_mb + 1)) fi ram_total_pretty=`echo $ram_total_mb' MB'` else ram_total_gb_exact=$(echo "scale=1; $ram_total_b / 1024 / 1024 / \ 1024" | bc) ram_total_gb=`echo $ram_total_gb_exact | cut -d . -f 1` remainder=`echo $ram_total_gb_exact | cut -d . -f 2` if [ $remainder -ge 5 ] then ram_total_gb=$((ram_total_gb + 1)) fi ram_total_pretty=`echo $ram_total_gb' GB'` fi } ######################### # This function displays the hardware (full details). ######################### hardwarefull() { # CPU model=`sysctl -n hw.model | sed 's/^ *//;s/ *$//' | sed 's/ */\ /g'` sysctl -n dev.cpu.0.freq_levels > /dev/null 2>&1 if [ $? -eq 0 ] then cpuspeed=`sysctl -n dev.cpu.0.freq_levels | awk '{print $1}' | \ cut -d / -f 1` if [ $cpuspeed -lt 1000 ] then cpuspeed_pretty=`echo $cpuspeed'MHz'` else cpuspeed_ghz=$(echo "scale=2; $cpuspeed / 1000" | bc) cpuspeed_pretty=`echo $cpuspeed_ghz'GHz'` fi else cpuspeed_pretty=Unknown fi cpu_model=`echo $model @ $cpuspeed_pretty` physical_cpus=1 logical_cpus=`sysctl -n hw.ncpu` cores_per_cpu=$(($logical_cpus / $physical_cpus)) cpu_value=`echo CPU: Model: $cpu_model, Physical CPU\'s: $physical_cpus, \ Cores per CPU: $cores_per_cpu, Logical CPU\'s: $logical_cpus` # RAM sudo ofwdump > /dev/null 2>&1 if [ $? -eq 0 ] then model=`sudo ofwdump -P model -S /` echo $model | grep 'Raspberry Pi' > /dev/null 2>&1 if [ $? -eq 0 ] then sysctl -n hw.board.revision > /dev/null 2>&1 if [ $? -eq 0 ] then rpi_ram else ram_calculate fi else ram_calculate fi else ram_calculate fi ram_value=`echo RAM: Total installed: $ram_total_pretty` echo $cpu_value echo $ram_value } ######################### # This function displays the chassis. ######################### chassis() { model=`sysctl -b hw.fdt.dtb | dtc -I dtb | sed -n '/\/ {/,/};/p' | grep \ "compatible = " | head -n 1 | cut -d = -f 2 | cut -d , -f 1 | sed \ 's/^[" \t]*//;s/[" \t]*$//'` case $model in pine64) value=Pine64 ;; raspberrypi) value='Raspberry Pi' ;; *) sysctl -n hw.platform > /dev/null 2>&1 if [ $? -eq 0 ] then value=`sysctl -n hw.platform` fi value=Unknown ;; esac echo $value } ######################### # This function displays the model. ######################### model() { sudo ofwdump > /dev/null 2>&1 if [ $? -eq 0 ] then value=`sudo ofwdump -P model -S /` else sysctl -n hw.board.revision > /dev/null 2>&1 if [ $? -eq 0 ] then value=`sysctl -n hw.board.revision` fi value=Unknown fi echo $value } ######################### # This is the main part of the script. ######################### if [ $# -ne 1 ] then echo usage: system_info.sh [option] echo echo " name Displays system name" echo " os Displays operating system" echo " osfull Displays operating system (full details)" echo " osshort Displays operating system (short)" echo " tag Displays chassis tag number" echo " hardwarefull Displays hardware (full details)" echo " chassis Displays chassis" echo " model Displays model" exit 0 else case $1 in name) name ;; os) os ;; osfull) osfull ;; osshort) osshort ;; tag) tag ;; hardwarefull) hardwarefull ;; chassis) chassis ;; model) model ;; *) echo Unknown option ;; esac fi exit 0