Various shell scripts for use on the RTC server. Not your official RTC stuff!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

144 lines
5.3 KiB

#! /bin/bash
# Usage stats at a glance
# Author: samhunter@rawtext.club
# https://git.rawtext.club/samhunter/rtc-shell-scripts
#
readonly PROGNAME="${0##/}"
readonly VERSION="1.0"
CACHE=$(mktemp "$HOME/tmp/starsXXXX")
declare -gA GAB=()
declare -gA IRIS=()
declare -gA LINKULATOR=()
declare -gA SHLOG=()
declare -gA WHOIS=()
declare -gA GITBBS=()
declare -gA ONELINER=()
declare -gA SL=()
declare -gA TRAIN=()
declare -gA WEB=()
declare -gA GEMINI=()
declare -gA GOPHER=()
declare -gA ELIBRARY=()
declare -gAi ACTIVE_USERS=()
declare -gAi TOTALS=()
recent -f |\
if_possible user::filter |\
sort -nr |\
while read DATE TIME WHAT WHO ; do
let ACTIVE_USERS[$WHO]+=1
case "$WHAT" in
"gab") GAB["$WHO"]="$DATE" ; ((++TOTALS["GAB"])) ;;
"iris") IRIS["$WHO"]="$DATE"; ((++TOTALS["IRIS"])) ;;
"linkulator") LINKULATOR["$WHO"]="$DATE"; ((++TOTALS["LINKULATOR"])) ;;
"shlog") SHLOG["$WHO"]="$DATE"; ((++TOTALS["SHLOG"])) ;;
"who-is") WHOIS["$WHO"]="$DATE"; ((++TOTALS["WHOIS"])) ;;
"gitbbs") GITBBS["$WHO"]="$DATE"; ((++TOTALS["GITBBS"])) ;;
"oneliner") ONELINER["$WHO"]="$DATE"; ((++TOTALS["ONELINER"])) ;;
"sl") SL["$WHO"]="$DATE"; ((++TOTALS["SL"])) ;;
"train") TRAIN["$WHO"]="$DATE"; ((++TOTALS["TRAIN"])) ;;
"web") WEB["$WHO"]="$DATE"; ((++TOTALS["WEB"])) ;;
"gemini") GEMINI["$WHO"]="$DATE"; ((++TOTALS["GEMINI"])) ;;
"gopher") GOPHER["$WHO"]="$DATE"; ((++TOTALS["GOPHER"])) ;;
"library") ELIBRARY["$WHO"]="$DATE"; ((++TOTALS["ELIBRARY"])) ;;
esac
typeset -p ACTIVE_USERS > "${CACHE}"
typeset -p GAB >> "${CACHE}"
typeset -p IRIS >> "${CACHE}"
typeset -p LINKULATOR >> "${CACHE}"
typeset -p SHLOG >> "${CACHE}"
typeset -p WHOIS >> "${CACHE}"
typeset -p GITBBS >> "${CACHE}"
typeset -p ONELINER >> "${CACHE}"
typeset -p SL >> "${CACHE}"
typeset -p TRAIN >> "${CACHE}"
typeset -p WEB >> "${CACHE}"
typeset -p GEMINI >> "${CACHE}"
typeset -p GOPHER >> "${CACHE}"
typeset -p ELIBRARY >> "${CACHE}"
typeset -p TOTALS >> "${CACHE}"
echo >> "${CACHE}"
done
. "${CACHE}"
if [ -n "$NO_FANCY_SHIT" ]; then
printf "%20.20s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s |\n" \
"user" "gab" "iris" "linkulator" "shlog" "who-is" "gitbbs" "oneliner" "sl" "train" "web" "gemini" "gopher" "library"
printf "%20.20s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s |\n" \
'-------------------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------'
else
printf "\x1b[7;1m%20.20s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s |\x1b[0m\n" \
"user" "gab" "iris" "linkulator" "shlog" "who-is" "gitbbs" "oneliner" "sl" "train" "web" "gemini" "gopher" "library"
fi
FILLER='..........'
for u in ${!ACTIVE_USERS[@]} ; do
printf "%20.20s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s |\n" \
"$u" ${GAB["$u"]:="${FILLER}"} ${IRIS["$u"]:="${FILLER}"} ${LINKULATOR["$u"]:="${FILLER}"} ${SHLOG["$u"]:="${FILLER}"} ${WHOIS["$u"]:="${FILLER}"} \
${GITBBS["$u"]:="${FILLER}"} ${ONELINER["$u"]:="${FILLER}"} ${SL["$u"]:="${FILLER}"} ${TRAIN["$u"]:="${FILLER}"} ${WEB["$u"]:="${FILLER}"} \
${GEMINI["$u"]:="${FILLER}"} ${GOPHER["$u"]:="${FILLER}"} ${ELIBRARY["$u"]:="${FILLER}"}
done | sort
if [ -n "$NO_FANCY_SHIT" ]; then
printf "%20.20s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s |\n" \
'-------------------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------' \
'----------'
printf "%20.20s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s |\n" \
"Totals" \
${TOTALS["GAB"]:-0} \
${TOTALS["IRIS"]:-0} \
${TOTALS["LINKULATOR"]:-0} \
${TOTALS["SHLOG"]:-0} \
${TOTALS["WHOIS"]:-0} \
${TOTALS["GITBBS"]:-0} \
${TOTALS["ONELINER"]:-0} \
${TOTALS["SL"]:-0} \
${TOTALS["TRAIN"]:-0} \
${TOTALS["WEB"]:-0} \
${TOTALS["GEMINI"]:-0} \
${TOTALS["GOPHER"]:-0} \
${TOTALS["ELIBRARY"]:-0}
else
printf "\x1b[7;1m%20.20s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s | %-10.10s |\x1b[0m\n" \
"Totals" \
${TOTALS["GAB"]:-0} \
${TOTALS["IRIS"]:-0} \
${TOTALS["LINKULATOR"]:-0} \
${TOTALS["SHLOG"]:-0} \
${TOTALS["WHOIS"]:-0} \
${TOTALS["GITBBS"]:-0} \
${TOTALS["ONELINER"]:-0} \
${TOTALS["SL"]:-0} \
${TOTALS["TRAIN"]:-0} \
${TOTALS["WEB"]:-0} \
${TOTALS["GEMINI"]:-0} \
${TOTALS["GOPHER"]:-0} \
${TOTALS["ELIBRARY"]:-0}
fi
rm -f "${CACHE}"