General: Cache uname output for use later in the script

This commit is contained in:
Dylan Araps 2016-11-11 14:25:43 +11:00
parent 6a3e5e3f22
commit 1b8d8f6eaa

View file

@ -19,12 +19,15 @@ export LANG=C
# Set no case match. # Set no case match.
shopt -s nocasematch shopt -s nocasematch
# Cache uname output for use later in the script.
uname=($(uname -srm))
# Gather Info {{{ # Gather Info {{{
# Operating System {{{ # Operating System {{{
get_os() { get_os() {
case "$(uname)" in case "${uname[0]}" in
"Linux") os="Linux" ;; "Linux") os="Linux" ;;
"Darwin") os="$(sw_vers -productName)" ;; "Darwin") os="$(sw_vers -productName)" ;;
*"BSD" | "DragonFly" | "Bitrig") os="BSD" ;; *"BSD" | "DragonFly" | "Bitrig") os="BSD" ;;
@ -32,7 +35,7 @@ get_os() {
"SunOS") os="Solaris" ;; "SunOS") os="Solaris" ;;
"Haiku") os="Haiku" ;; "Haiku") os="Haiku" ;;
"GNU"*) os="GNU" ;; "GNU"*) os="GNU" ;;
*) printf "%s\n" "Unknown OS detected: $(uname)"; exit 1 ;; *) printf "%s\n" "Unknown OS detected: ${uname[0]}"; exit 1 ;;
esac esac
} }
@ -62,7 +65,7 @@ get_model() {
"Mac OS X") model="$(sysctl -n hw.model)" ;; "Mac OS X") model="$(sysctl -n hw.model)" ;;
"iPhone OS") "iPhone OS")
case "${ios_model:="$(uname -m)"}" in case "${uname[2]}" in
"iPad1,1") model="iPad" ;; "iPad1,1") model="iPad" ;;
"iPad2,"[1-4]) model="iPad2" ;; "iPad2,"[1-4]) model="iPad2" ;;
"iPad3,"[1-3]) model="iPad3" ;; "iPad3,"[1-3]) model="iPad3" ;;
@ -224,8 +227,8 @@ get_distro() {
"BSD") "BSD")
case "$distro_shorthand" in case "$distro_shorthand" in
"tiny" | "on") distro="$(uname -s)" ;; "tiny" | "on") distro="${uname[0]}" ;;
*) distro="$(uname -sr)" ;; *) distro="${uname[0]} ${uname[1]}" ;;
esac esac
distro="${distro/DragonFly/DragonFlyBSD}" distro="${distro/DragonFly/DragonFlyBSD}"
@ -258,7 +261,7 @@ get_distro() {
# Get architecture # Get architecture
[[ "$os_arch" == "on" ]] && \ [[ "$os_arch" == "on" ]] && \
distro+=" $(uname -m)" distro+=" ${uname[2]}"
[[ "${ascii_distro:-auto}" == "auto" ]] && \ [[ "${ascii_distro:-auto}" == "auto" ]] && \
ascii_distro="$(trim "$distro")" ascii_distro="$(trim "$distro")"
@ -278,18 +281,16 @@ get_title() {
get_kernel() { get_kernel() {
case "$kernel_shorthand" in case "$kernel_shorthand" in
"on") kernel_flags="-r" ;; "on") kernel="${uname[1]}" ;;
"off") kernel_flags="-sr" ;; "off") kernel="${uname[0]} ${uname[1]}" ;;
esac esac
# Hardcode kernel settings in BSDs # Hardcode kernel settings in BSDs
if [[ "$os" == "BSD" && ! "$distro" =~ (PacBSD|PCBSD) ]]; then if [[ "$os" == "BSD" && ! "$distro" =~ (PacBSD|PCBSD) ]]; then
case "$distro_shorthand" in case "$distro_shorthand" in
"on" | "tiny") kernel=$(uname -r) ;; "on" | "tiny") kernel="${uname[1]}" ;;
*) unset kernel ;; *) unset kernel ;;
esac esac
else
kernel="$(uname $kernel_flags)"
fi fi
} }
@ -773,7 +774,7 @@ get_cpu() {
;; ;;
"iPhone OS") "iPhone OS")
case "${ios_model:="$(uname -m)"}" in case "${uname[2]}" in
"iPhone1,"[1-2] | "iPod1,1") cpu="Samsung S5L8900 (1) @ 412MHz" ;; "iPhone1,"[1-2] | "iPod1,1") cpu="Samsung S5L8900 (1) @ 412MHz" ;;
"iPhone2,1") cpu="Samsung S5PC100 (1) @ 600MHz" ;; "iPhone2,1") cpu="Samsung S5PC100 (1) @ 600MHz" ;;
"iPhone3,"[1-3] | "iPod4,1") cpu="Apple A4 (1) @ 800MHz" ;; "iPhone3,"[1-3] | "iPod4,1") cpu="Apple A4 (1) @ 800MHz" ;;
@ -995,7 +996,7 @@ get_gpu() {
;; ;;
"iPhone OS") "iPhone OS")
case "${ios_model:="$(uname -m)"}" in case "${uname[2]}" in
"iPhone1,"[1-2]) gpu="PowerVR MBX Lite 3D" ;; "iPhone1,"[1-2]) gpu="PowerVR MBX Lite 3D" ;;
"iPhone5,"[1-4]) gpu="PowerVR SGX543MP3" ;; "iPhone5,"[1-4]) gpu="PowerVR SGX543MP3" ;;
"iPhone8,"[1-4]) gpu="PowerVR GT7600" ;; "iPhone8,"[1-4]) gpu="PowerVR GT7600" ;;