Here's something I put together that spits out most of the information about a system (other than e.g. the build log for a port that failed to install/update) that might be of interest when problems arise.  Sample output:

sh-3.2$ vers
Hardware Version: MacBook Pro (15-inch, 2017)
Model Identifier: MacBookPro14,3
Mac OS X 10.13.6 17G65 (High Sierra)
Server Version: 5.6.1
System Integrity Protection status: disabled.
Xcode 9.4.1 9F2000
MacPorts Version: 2.5.3
warning: /usr/local exists


Some of those lines only appear if applicable, i.e. those starting with Server Version.

I may have posted this before, but it's had some updates.  The URL to fetch the marketing model name ("Hardware Version" above) now has to be https.  Added Mojave for conversion of OS version number to name.  I think that's most of the recent changes.

Just rename to "vers", and set the permissions to be executable; that should be all that's needed.  It should work whether or not Server or MacPorts is installed, although of course it won't say anything about them if they aren't there, and won't warn about /usr/local if MacPorts isn't installed.  Fetching the marketing model name does require being online, and passes the last four characters of the system's serial number to Apple.

If you can think of something else that might be interesting to add, let me know, keeping in mind that it's intended to cover the basics but not be a comprehensive hardware, OS, or application report; there are other tools, which the script mostly uses, that will provide more in one or another of those areas; bringing together just the right bits was what I wanted.  Having at least a GB or two free space in / would probably be good, but I'd hope people would have noticed that by other means.  Unless they've disabled swap or are very tight on disk space, RAM shouldn't be that relevant save for performance.

#! /bin/ksh

# credit for trick to find marketing name to "bmike" on the page
# 
http://apple.stackexchange.com/questions/98080/can-a-macs-model-year-be-determined-via-terminal-command

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin"
function vers2codename {
        case "${1}" in
        10.0|10.0.*) echo "Cheetah";;
        10.1|10.1.*) echo "Puma";;
        10.2|10.2.*) echo "Jaguar";;
        10.3|10.3.*) echo "Panther";;
        10.4|10.4.*) echo "Tiger";;
        10.5|10.5.*) echo "Leopard";;
        10.6|10.6.*) echo "Snow Leopard";;
        10.7|10.7.*) echo "Lion";;
        10.8|10.8.*) echo "Mountain Lion";;
        10.9|10.9.*) echo "Mavericks";;
        10.10|10.10.*) echo "Yosemite";;
        10.11|10.11.*) echo "El Capitan";;
        10.12|10.12.*) echo "Sierra";;
        10.13|10.13.*) echo "High Sierra";;
        10.14|10.14.*) echo "Mojave";;
        *) echo "version \"${1}\" name unknown";;
        esac
}

hardwareVersion="$(
curl -s https://support-sp.apple.com/sp/product?cc="$(system_profiler 
SPHardwareDataType 2>/dev/null | awk '/Serial/ {print $4}' | cut -c 9-)" 
2>/dev/null |
    sed 's|.*<configCode>\(.*\)</configCode>.*|\1|')"

productVersion="$(sw_vers -productVersion)"
if [ -n "${hardwareVersion}" ]; then
        echo "Hardware Version: ${hardwareVersion}"
fi
system_profiler SPHardwareDataType 2>/dev/null|sed -n -e '/Model 
Identifier:/s/^  *//p'
echo "$(sw_vers -productName) ${productVersion} $(sw_vers -buildVersion) 
($(vers2codename "${productVersion}"))"
ServerVersionFile=/Applications/Server.app/Contents/version.plist
if [ -f "${ServerVersionFile}" -a -r "${ServerVersionFile}" ]; then
        print -n "Server Version: "
        defaults read "${ServerVersionFile}" CFBundleShortVersionString
fi
if [ -x /usr/bin/csrutil ]; then
        csrutil status
fi
if xcode-select -print-path >/dev/null 2>&1
then
        xcodebuild -version|awk 'NR==1 {prod_vers=$0} NR==2 {build=$NF} END 
{printf "%s %s\n",prod_vers,build}'
fi
if whence port >/dev/null 2>&1
then
        echo "MacPorts $(port version)"
        if [ -d /usr/local/. ]; then
                echo "warning: /usr/local exists"
        fi
fi

Attachment: signature.asc
Description: Message signed with OpenPGP

Reply via email to