44 lines
1.2 KiB
Bash
Executable file
44 lines
1.2 KiB
Bash
Executable file
#!/bin/sh
|
|
# Fast, cross-platform POSIX fetch script
|
|
# Mostly stolen from 6kg@github
|
|
|
|
## Distro
|
|
# freedesktop.org/software/systemd/man/os-release.html
|
|
# a common file that has variables about the distro
|
|
for os in /etc/os-release /usr/lib/os-release; do
|
|
# some POSIX shells exit when trying to source a file that doesn't exist
|
|
[ -f $os ] && . $os && break
|
|
done
|
|
[ -e "/data/data/com.termux" ] && ID="android $(getprop ro.build.version.release)"
|
|
|
|
## Kernel
|
|
# First try to get kernel veriosn from /proc/version
|
|
# Try uname command otherwise
|
|
[ -e "/proc/version" ] && read -r _ _ version _ < /proc/version
|
|
[ -z "$version" ] && version=$(uname -r)
|
|
kernel=${version%%-*}
|
|
|
|
## Uptime
|
|
# the simple math is shamefully stolen from aosync
|
|
[ -e "/proc/uptime" ] && IFS=. read -r uptime _ < /proc/uptime
|
|
d=$((uptime / 60 / 60 / 24))
|
|
up=$(printf %02d:%02d $((uptime / 60 / 60 % 24)) $((uptime / 60 % 60)))
|
|
[ "$d" -gt 0 ] && up="${d}d $up"
|
|
|
|
print() {
|
|
[ "$2" ] && printf '\033[1m %b\033[0m %b%s\n' \
|
|
"$1" "$2"
|
|
}
|
|
|
|
## Output
|
|
echo
|
|
print DIST "$ID"
|
|
print KERN "$kernel"
|
|
print SHLL "${SHELL##*/}"
|
|
print UPTM "$up"
|
|
# Colors
|
|
printf ' '
|
|
for i in 1 2 3 4 5 6; do
|
|
printf '\033[9%sm%s\033[0m%b%s' "$i" "${colourblocks:-▅▅}"
|
|
done
|
|
echo
|