#!/bin/sh ######################################## # Description: This script is used to get system information on armhf and arm64 systems. ######################################## ######################### # Set variables ######################### PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin hostname_file=/proc/sys/kernel/hostname openwrt_release=/etc/openwrt_release raspberry_pi_release=/etc/rpi-issue synology_release=/etc.defaults/VERSION raspberry_pi_repo=/etc/apt/sources.list.d/raspi.list lsbrelease_file=/etc/lsb-release synology_sn_file=/proc/sys/kernel/syno_serial sn_file=/sys/firmware/devicetree/base/serial-number cpuinfo_file=/proc/cpuinfo synology_cpu_arch_file=/proc/syno_cpu_arch synology_cpu_clock_file=/proc/sys/kernel/syno_CPU_info_clock soc_arm_pmu_file=/sys/firmware/devicetree/base/soc/arm-pmu/compatible arm_pmu_file=/sys/firmware/devicetree/base/arm-pmu/compatible pmu_file=/sys/firmware/devicetree/base/pmu/compatible cpufreq_file=/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq cpuclk_file=/sys/kernel/debug/clk/clk_summary synology_conf=/etc.defaults/synoinfo.conf model_file=/sys/firmware/devicetree/base/model meminfo_file=/proc/meminfo firmware_chassis_file=/sys/firmware/devicetree/base/soc/firmware/compatible chassis_file=/sys/firmware/devicetree/base/compatible ######################### # This function displays the system name. ######################### name() { hostname -f > /dev/null 2>&1 if [ $? -eq 0 ] then value=`hostname -f` else hostname > /dev/null 2>&1 if [ $? -eq 0 ] then value=`hostname` else value=`cat $hostname_file` fi fi echo $value } ######################### # This function displays the operating system. ######################### os() { release_files="$openwrt_release $raspberry_pi_release $synology_release" value=Unknown for item in $release_files do ls -1 $item > /dev/null 2>&1 if [ $? -eq 0 ] then case "$item" in $openwrt_release) value=`grep ^DISTRIB_DESCRIPTION= $openwrt_release | \ cut -d = -f 2- | sed -e "s/'//g" | awk \ '{print $1,$2}'` ;; $raspberry_pi_release) os=`head -n 1 $raspberry_pi_release | \ sed 's/ reference.*/ OS/g'` dpkg -l | grep xorg > /dev/null 2>&1 if [ $? -eq 0 ] then variant='with desktop' else variant=Lite fi productversion=`grep -v ^# $raspberry_pi_repo | \ grep '^deb ' | awk '{print $3}'` value=`echo $os $variant ' ('$productversion')'` ;; $synology_release) productversion=`get_key_value $synology_release \ productversion` value=`echo 'DSM '$productversion` ;; esac fi done if [ "$value" = "Unknown" ] then if [ -e $lsbrelease_file ] then value=`lsb_release -d | cut -d : -f 2- | \ sed 's/^[ \t]*//;s/[ \t]*$//'` else grep ^PRETTY_NAME /etc/*release > /dev/null 2>&1 if [ $? -eq 0 ] then value=`grep ^PRETTY_NAME /etc/*release | uniq | \ cut -d = -f 2 | sed 's/^["]*//;s/["]$*//'` else lsb_release -d > /dev/null 2>&1 if [ $? -eq 0 ] then value=`lsb_release -d | cut -d : -f 2- | \ sed 's/^[ \t]*//;s/[ \t]*$//'` else value=Unknown fi fi fi fi echo $value } ######################### # This function displays the operating system (full details). ######################### osfull() { release_files="$openwrt_release $raspberry_pi_release $synology_release" distro=Unknown for item in $release_files do ls -1 $item > /dev/null 2>&1 if [ $? -eq 0 ] then case "$item" in $openwrt_release) productversion=`grep ^DISTRIB_DESCRIPTION= \ $openwrt_release | cut -d = -f 2- | sed -e "s/'//g"` distro=`echo $productversion` ;; $raspberry_pi_release) os=`head -n 1 $raspberry_pi_release | \ sed 's/ reference.*/ OS/g'` dpkg -l | grep xorg > /dev/null 2>&1 if [ $? -eq 0 ] then variant='with desktop' else variant=Lite fi productversion=`grep -v ^# $raspberry_pi_repo | \ grep '^deb ' | awk '{print $3}'` distro=`echo $os $variant ' ('$productversion')'` ;; $synology_release) productversion=`get_key_value $synology_release \ productversion` buildnumber=`get_key_value $synology_release \ buildnumber` grep ^smallfixnumber= $synology_release > /dev/null 2>&1 if [ $? -eq 0 ] then smallfixnumber=`get_key_value $synology_release \ smallfixnumber` distro=`echo 'DSM '$productversion'-'$buildnumber' \ Update '$smallfixnumber` else distro=`echo 'DSM '$productversion'-'$buildnumber` fi ;; esac fi done if [ "$distro" = "Unknown" ] then if [ -e $lsbrelease_file ] then distro=`lsb_release -d | cut -d : -f 2- | \ sed 's/^[ \t]*//;s/[ \t]*$//'` else grep ^PRETTY_NAME /etc/*release > /dev/null 2>&1 if [ $? -eq 0 ] then distro=`grep ^PRETTY_NAME /etc/*release | uniq | \ cut -d = -f 2 | sed 's/^["]*//;s/["]$*//'` else lsb_release -d > /dev/null 2>&1 if [ $? -eq 0 ] then distro=`lsb_release -d | cut -d : -f 2- | \ sed 's/^[ \t]*//;s/[ \t]*$//'` else distro=Unknown fi fi fi fi getconf LONG_BIT > /dev/null 2>&1 if [ $? -ne 0 ] then ls -1 /lib64 > /dev/null 2>&1 if [ $? -ne 0 ] then arch=32 else arch=64 fi else arch=`getconf LONG_BIT` fi distro_arch=`uname -m` value=`echo $distro' ('$arch'-bit '$distro_arch')'` echo $value } ######################### # This function displays the operating system (short). ######################### osshort() { release_files="$openwrt_release $raspberry_pi_release $synology_release" value=Unknown for item in $release_files do ls -1 $item > /dev/null 2>&1 if [ $? -eq 0 ] then case "$item" in $openwrt_release) value=`grep ^DISTRIB_ID= $openwrt_release | \ cut -d = -f 2- | sed -e "s/'//g"` ;; $raspberry_pi_release) value=`head -n 1 $raspberry_pi_release | \ sed 's/ reference.*/ OS/g'` ;; $synology_release) value=DSM ;; esac fi done if [ "$value" = "Unknown" ] then if [ -e $lsbrelease_file ] then value=`lsb_release -i | cut -d : -f 2- | \ ed 's/^[ \t]*//;s/[ \t]*$//'` else grep ^NAME /etc/*release > /dev/null 2>&1 if [ $? -eq 0 ] then value=`grep ^NAME /etc/*release | uniq | cut -d = \ -f 2 | sed 's/^["]*//;s/["]$*//'` else value=Unknown fi fi fi echo $value } ######################### # This function displays the chassis tag number. ######################### tag() { if [ -e $synology_sn_file ] then value=`cat $synology_sn_file` else if [ -e $sn_file ] then value=`cat $sn_file` else grep ^Serial $cpuinfo_file > /dev/null 2>&1 if [ $? -eq 0 ] then serial=`grep ^Serial $cpuinfo_file | \ cut -d : -f 2- | sed 's/^[ \t]*//;s/[ \t]*$//'` if [ "$serial" != "0000000000000000" ] then value=`echo $serial` else value=Unknown fi else value=Unknown fi fi fi echo $value } ######################### # This function parses the CPU files. ######################### cpu_parse() { manufacturer=`cat $file | cut -d , -f 1 | uniq` case "$manufacturer" in arm) man=`echo $manufacturer | tr '[a-z]' '[A-Z]'` cat $file | cut -d , -f 2- | sed 's/,/ /;s/-pmu//' | \ grep -c - > /dev/null 2>&1 if [ $? -eq 0 ] then model=`cat $file | cut -d , -f 2- | \ sed 's/,/ /;s/-pmu//' | cut -d - -f 1 | uniq | head -n 1` case "$model" in cortex) mod1a=`echo $model | cut -c 1 | tr '[a-z]' '[A-Z]'` mod1b=`echo $model | cut -c 2-` mod1=`echo $mod1a$mod1b` lines=`cat $file | cut -d , -f 2- | wc -l` if [ $lines -eq 1 ] then mod2=`cat $file | sed 's/arm//g' | \ sed 's/cortex-//g' | sed 's/-pmu//g' | \ cut -d , -f 2 | tr '[a-z]' '[A-Z]'` else mod2=`cat $file | sed s'/arm//g' | \ sed 's/cortex-//g' | sed 's/-pmu//g' | \ cut -d , -f 1- | head -n 1 | tr '[a-z]' \ '[A-Z]' | sed 's/,//g'` fi mod=`echo $mod1-$mod2` ;; *) mod=Unknown ;; esac model=`echo $man $mod` else mod=`cat $file | cut -d , -f 2- | sed 's/,/ /;s/-pmu//' | \ tr '[a-z]' '[A-Z]'` model=`echo $man $mod` fi ;; *) model=Unknown ;; esac } ######################### # 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 1/7/24 ######################### 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 b03115 b03140" gb4_ram_models="c03111 c03112 c03114 c03115 c03130 c03140 c04170" gb8_ram_models="d03114 d03115 d03140 d04170" model=`grep ^Revision $cpuinfo_file | cut -d : -f 2- | \ sed 's/^[ \t]*//;s/[ \t]*$//'` 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_k=`grep ^MemTotal $meminfo_file | cut -d : -f 2- | \ awk '{print $1}'` ram_total=$(echo "scale=0; $ram_total_k / 1000" | bc) if [ $ram_total -lt 1024 ] then ram_total_mb_exact=$(echo "scale=1; $ram_total_k / 1000" | 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_k / 1000 / 1000" | \ 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 if [ -e $synology_cpu_arch_file ] then man1=`cut -d , -f 1 $synology_cpu_arch_file | cut -c 1` man2=`cut -d , -f 1 $synology_cpu_arch_file | cut -c 2- | \ tr '[A-Z]' '[a-z]'` manufacturer=`echo $man1$man2` mod1=`cut -d , -f 2 $synology_cpu_arch_file | sed 's/^ *//'` mod2=`cut -d , -f 3 $synology_cpu_arch_file | sed 's/^ *//'` mod3=`cut -d , -f 4 $synology_cpu_arch_file | sed 's/^ */Rev /'` model=`echo $manufacturer $mod1 $mod2 $mod3` cpuspeed=`cat $synology_cpu_clock_file` if [ $cpuspeed -lt 1000 ] then cpuspeed_pretty=`echo $cpuspeed'MHz'` else cpuspeed_ghz=`echo $cpuspeed | sed 's/...$/.&/'` cpuspeed_pretty=`echo $cpuspeed_ghz'GHz'` fi cpu_model=`echo $model @ $cpuspeed_pretty` else if [ -e $soc_arm_pmu_file ] then file=$soc_arm_pmu_file cpu_parse else if [ -e $arm_pmu_file ] then file=$arm_pmu_file cpu_parse else if [ -e $pmu_file ] then file=$pmu_file cpu_parse else model=`grep ^Hardware $cpuinfo_file | \ uniq | cut -d : -f 2- | \ sed 's/^[ \t]*//;s/[ \t]*$//'` fi fi fi if [ -e $cpufreq_file ] then cpuspeed=$((`cat $cpufreq_file` / 1000)) 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 if [ -e $cpuclk_file ] then cat $cpuclk_file | grep cpuclk > /dev/null 2>&1 if [ $? -eq 0 ] then clk_fields=`cat $cpuclk_file | \ grep cpuclk | awk '{print NF}'` if [ $clk_fields -gt 6 ] then cpuspeed=$((`cat $cpuclk_file | \ grep cpuclk | awk '{print $5}'` \ / 1000000)) else cpuspeed=$((`cat $cpuclk_file | \ grep cpuclk | awk '{print $4}'` \ / 1000000)) fi fi if [ $cpuspeed -lt 1000 ] then cpuspeed_pretty=`echp $cpuspeed'MHz'` else cpuspeed_ghz=$(echo "scale=2; $cpuspeed / 1000" | \ bc) cpuspeed_pretty=`echo $cpuspeed_ghz'GHz'` fi else cpuspeed_pretty=Unknown fi fi cpu_model=`echo $model @ $cpuspeed_pretty` fi physical_cpus=1 logical_cpus=`grep ^processor $cpuinfo_file | uniq | wc -l` 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 if [ -e $synology_conf ] then grep ^mem_max_ $synology_conf | grep ^mem_max_mb > /dev/null 2>&1 if [ $? -eq 0 ] then ram_total_mb=`grep ^mem_max_mb $synology_conf | \ cut -d = -f 2 | sed 's/\"//g'` ram_total_pretty=`echo $ram_total_mb' MB'` else ram_total_gb=`grep ^mem_max_gb $synology_conf | \ cut -d = -f 2 | sed 's/\"//g'` ram_total_pretty=`echo $ram_total_gb' GB'` fi else if [ -e $model_file ] then chassis=`cat $model_file` echo $chassis | grep '^Raspberry Pi' > /dev/null 2>&1 if [ $? -eq 0 ] then rpi_ram else ram_calculate fi else ram_calculate fi fi ram_value=`echo RAM: Total installed: $ram_total_pretty` echo $cpu_value echo $ram_value } ######################### # This function sets the values for a chassis that is known. ######################### chassis_manufacturer() { case "$manufacturer" in linksys) value=Linksys ;; raspberrypi) value='Raspberry Pi' ;; *) value=Unknown ;; esac } ######################### # This function displays the chassis. ######################### chassis() { if [ -e $synology_conf ] then value=`get_key_value $synology_conf company_title` else if [ -e $firmware_chassis_file ] then manufacturer=`cat $firmware_chassis_file | \ cut -d , -f 1 | head -n 1` chassis_manufacturer else if [ -e $chassis_file ] then manufacturer=`cat $chassis_file | cut -d , -f 1 | \ head -n 1` chassis_manufacturer else value=Unknown fi fi fi echo $value } ######################### # This function displays the model. ######################### model() { if [ -e $synology_conf ] then value=`get_key_value $synology_conf upnpmodelname` else if [ -e $model_file ] then value=`cat $model_file` else value=Unknown fi 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