Basic FreeBSD support

Working: user@host, distro name, shell, cpu, mem
This commit is contained in:
GaugeK committed 2020-08-21 12:43:26 +10:00
1 parent 16a223b6c9
commit 2815feda67
1 file changed
+32 -9
+32 -9
View File
@@ -94,26 +94,49 @@ if [ -e /proc/$$/comm ]; then
read -r host < /proc/sys/kernel/hostname read -r host < /proc/sys/kernel/hostname
elif [ -f /var/run/dmesg.boot ]; then elif [ -f /var/run/dmesg.boot ]; then
## Even by SH standards this is ugly
# @TODO Clean up
# Both OpenBSD and FreeBSD use this file, however they're formatted differently
read -r open < /var/run/dmesg.boot
case $open in
Open*)
## OpenBSD cpu/mem/name ## OpenBSD cpu/mem/name
while read -r line; do while read -r line; do
case $line in case $line in
# set $mem to the nicely formatted brackets # set $mem to the nicely formatted brackets
"real mem"*) "real mem"*) mem=${line##*\(}; mem=${mem%\)*};;
mem=${line##*\(}; mem=${mem%\)*}
;;
# set $cpu to everything before a comma and after the field name # set $cpu to everything before a comma and after the field name
cpu0:*) cpu0:*) cpu=${line##cpu0: }; cpu=${cpu%%,*}
set -- $line; vendor="${2%\(*} " vendor=${cpu%%[\( ]*}; break;;
cpu=${line##cpu0: }; cpu=${cpu%%,*}; break
;;
# First 2 words in the file are OpenBSD <version> # First 2 words in the file are OpenBSD <version>
*) *) [ "$ID" ] || { set -- $line; ID="$1 $2"; }
[ "$ID" ] || { set -- $line; ID="$1 $2"; }
esac esac
done < /var/run/dmesg.boot done < /var/run/dmesg.boot
[ -d /var/db/pkg ] && set -- /var/db/pkg/* && pkgs=$# [ -d /var/db/pkg ] && set -- /var/db/pkg/* && pkgs=$#
read -r host < /etc/myname read -r host < /etc/myname
host=${host%.*} host=${host%.*}
;;
# Everything else, assume FreeBSD (first line is ---<<BOOT>> or something)
*)
. /etc/rc.conf
host=$hostname
while read -r line; do
case $line in
# Ignore useless lines at the top
-*|' '*) ;;
*trademark*) ;;
# os version
FreeBSD*) [ "$ID" ] || { set -- $line; ID="$1 ${2%-*}"; };;
# cpu
CPU:*) cpu=${line%\(*}; cpu=${cpu#CPU: };;
*Origin=*) vendor=${line#*Origin=\"}; vendor="${vendor%%\"*} ";;
# Memory
"real memory"*) mem=${line##*\(}; mem=${mem%\)*}; break
esac
done < /var/run/dmesg.boot
;;
esac
fi fi
## GTK ## GTK