version 1.40.130 release
[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 #echo "osname = '$osname' and osver = '$osver'"
24     if [[ "$osver" =~ ^10\.15.*$ ]]; then
25       codename="Catalina"
26     elif [[ "$osver" =~ ^10\.14.*$ ]]; then
27       codename="Mojave"
28     elif [[ "$osver" =~ ^10\.13.*$ ]]; then
29       codename="High Sierra"
30     elif [[ "$osver" =~ ^11\..*$ ]]; then
31       codename="Big Sur"
32     elif [[ "$osver" =~ ^12\..*$ ]]; then
33       codename="Monterey"
34     else
35       codename="$(sw_vers -buildVersion 2>/dev/null)"
36     fi
37   fi
38 fi
39 if [ -z "$codename" ]; then
40   codename="mysterioso"
41   osname="unspecified"
42   osver="0.0?"
43 fi
44
45 # see if uptime even exists.
46 uptime &>/dev/null
47 if [ $? -eq 0 ]; then
48   # test if this uptime knows the -p flag.
49   uptime -p &>/dev/null
50   if [ $? -eq 0 ]; then
51     up="$(uptime -p)"
52   else
53     up="$(uptime | awk '{print $2 " " $3 " " $4 " plus " $1 " hours" }')"
54   fi
55 else
56   # if we can't do this, then we're not even on windows cygwin.  wth are we?
57   up="up a whole $(cat /proc/uptime|awk '{print $1}') seconds, yo"
58 fi
59
60 # decide whether they've got splitter available or not.
61 if [ -f "$FEISTY_MEOW_BINARIES/splitter" -o -f "$FEISTY_MEOW_BINARIES/splitter.exe" ]; then
62   # calculate the number of columsn in the terminal.
63   cols=$(get_maxcols)
64   splitter="$FEISTY_MEOW_BINARIES/splitter --maxcol $(($cols - 1))"
65 else
66   # not available, so just emit as huge overly long string.
67   splitter="cat"
68 fi
69 echo
70 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 
71 echo
72 echo "the following things appear to be lying around here..."
73 echo
74 ls -hFC $color_add
75 echo
76 echo "there appear to be these entities on this host..."
77 echo
78 who -suT
79 echo
80