added mac introspection for versions in inventory script
[feisty_meow.git] / scripts / core / inventory.sh
1 #!/bin/bash
2
3 # a frivolous but useful script that shows information about the local
4 # computer in terms of an adventure game inventory listing.
5
6 source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh"
7
8 unset -v codename osname osver
9 if [ $OPERATING_SYSTEM == "UNIX" ]; then
10   if [ -z "$IS_DARWIN" ]; then
11     # we only try running lsb_release if not on a mac.
12     which lsb_release &>/dev/null
13     if [ $? -eq 0 ]; then
14       codename="$(lsb_release -cs 2>/dev/null)"
15       osname="$(lsb_release -is 2>/dev/null)"
16       osver="$(lsb_release -rs 2>/dev/null)"
17     fi
18   else
19     # darwin / mac doesn't have lsb since not linux.
20 #Usage: sw_vers [-productName|-productVersion|-buildVersion]
21     osname="$(sw_vers -productName 2>/dev/null)"
22     osver="$(sw_vers -productVersion 2>/dev/null)"
23     if [[ "$osver" =~ ^10\.15.*$ ]]; then
24       codename="Catalina"
25     elif [[ "$osver" =~ ^10\.14.*$ ]]; then
26       codename="Mojave"
27     elif [[ "$osver" =~ ^10\.13.*$ ]]; then
28       codename="High Sierra"
29     elif [[ "$osver" =~ ^11\.*$ ]]; then
30       codename="Big Sur"
31     elif [[ "$osver" =~ ^12\.*$ ]]; then
32       codename="Monterey"
33     else
34       codename="$(sw_vers -buildVersion 2>/dev/null)"
35     fi
36   fi
37 fi
38 if [ -z "$codename" ]; then
39   codename="mysterioso"
40   osname="unspecified"
41   osver="0.0?"
42 fi
43
44 # see if uptime even exists.
45 uptime &>/dev/null
46 if [ $? -eq 0 ]; then
47   # test if this uptime knows the -p flag.
48   uptime -p &>/dev/null
49   if [ $? -eq 0 ]; then
50     up="$(uptime -p)"
51   else
52     up="$(uptime | awk '{print $2 " " $3 " " $4 " plus " $1 " hours" }')"
53   fi
54 else
55   # if we can't do this, then we're not even on windows cygwin.  wth are we?
56   up="up a whole $(cat /proc/uptime|awk '{print $1}') seconds, yo"
57 fi
58
59 # decide whether they've got splitter available or not.
60 if [ -f "$FEISTY_MEOW_BINARIES/splitter" -o -f "$FEISTY_MEOW_BINARIES/splitter.exe" ]; then
61   # calculate the number of columsn in the terminal.
62   cols=$(get_maxcols)
63   splitter="$FEISTY_MEOW_BINARIES/splitter --maxcol $(($cols - 1))"
64 else
65   # not available, so just emit as huge overly long string.
66   splitter="cat"
67 fi
68 echo
69 echo "it is $(date +"%A at %H:%M hours on day %e of the %B moon in the gregorian year %Y" | tr A-Z a-z) and our intrepid adventurer $USER is exploring a computer named $(hostname) that is running in a thoughtspace called $osname $osver (code-name $codename), and $USER has deduced that the machine's OS platform is $(uname -m) and its current incarnation has been ${up}." | $splitter 
70 echo
71 echo "the following things appear to be lying around here..."
72 echo
73 ls -hFC $color_add
74 echo
75 echo "there appear to be these entities on this host..."
76 echo
77 who -suT
78 echo
79