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

3 months ago
3 months ago
  1. #! /bin/bash
  2. # Usage stats at a glance
  3. # Author: samhunter@rawtext.club
  4. # https://git.rawtext.club/samhunter/rtc-shell-scripts
  5. #
  6. readonly PROGNAME="${0##/}"
  7. readonly VERSION="1.0"
  8. CACHE=$(mktemp "$HOME/tmp/starsXXXX")
  9. declare -gA GAB=()
  10. declare -gA IRIS=()
  11. declare -gA LINKULATOR=()
  12. declare -gA SHLOG=()
  13. declare -gA WHOIS=()
  14. declare -gA GITBBS=()
  15. declare -gA ONELINER=()
  16. declare -gA SL=()
  17. declare -gA TRAIN=()
  18. declare -gA WEB=()
  19. declare -gA GEMINI=()
  20. declare -gA GOPHER=()
  21. declare -gA ELIBRARY=()
  22. declare -gAi ACTIVE_USERS=()
  23. declare -gAi TOTALS=()
  24. recent -f |\
  25. if_possible user::filter |\
  26. sort -nr |\
  27. while read DATE TIME WHAT WHO ; do
  28. let ACTIVE_USERS[$WHO]+=1
  29. case "$WHAT" in
  30. "gab") GAB["$WHO"]="$DATE" ; ((++TOTALS["GAB"])) ;;
  31. "iris") IRIS["$WHO"]="$DATE"; ((++TOTALS["IRIS"])) ;;
  32. "linkulator") LINKULATOR["$WHO"]="$DATE"; ((++TOTALS["LINKULATOR"])) ;;
  33. "shlog") SHLOG["$WHO"]="$DATE"; ((++TOTALS["SHLOG"])) ;;
  34. "who-is") WHOIS["$WHO"]="$DATE"; ((++TOTALS["WHOIS"])) ;;
  35. "gitbbs") GITBBS["$WHO"]="$DATE"; ((++TOTALS["GITBBS"])) ;;
  36. "oneliner") ONELINER["$WHO"]="$DATE"; ((++TOTALS["ONELINER"])) ;;
  37. "sl") SL["$WHO"]="$DATE"; ((++TOTALS["SL"])) ;;
  38. "train") TRAIN["$WHO"]="$DATE"; ((++TOTALS["TRAIN"])) ;;
  39. "web") WEB["$WHO"]="$DATE"; ((++TOTALS["WEB"])) ;;
  40. "gemini") GEMINI["$WHO"]="$DATE"; ((++TOTALS["GEMINI"])) ;;
  41. "gopher") GOPHER["$WHO"]="$DATE"; ((++TOTALS["GOPHER"])) ;;
  42. "library") ELIBRARY["$WHO"]="$DATE"; ((++TOTALS["ELIBRARY"])) ;;
  43. esac
  44. typeset -p ACTIVE_USERS > "${CACHE}"
  45. typeset -p GAB >> "${CACHE}"
  46. typeset -p IRIS >> "${CACHE}"
  47. typeset -p LINKULATOR >> "${CACHE}"
  48. typeset -p SHLOG >> "${CACHE}"
  49. typeset -p WHOIS >> "${CACHE}"
  50. typeset -p GITBBS >> "${CACHE}"
  51. typeset -p ONELINER >> "${CACHE}"
  52. typeset -p SL >> "${CACHE}"
  53. typeset -p TRAIN >> "${CACHE}"
  54. typeset -p WEB >> "${CACHE}"
  55. typeset -p GEMINI >> "${CACHE}"
  56. typeset -p GOPHER >> "${CACHE}"
  57. typeset -p ELIBRARY >> "${CACHE}"
  58. typeset -p TOTALS >> "${CACHE}"
  59. echo >> "${CACHE}"
  60. done
  61. . "${CACHE}"
  62. if [ -n "$NO_FANCY_SHIT" ]; then
  63. 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" \
  64. "user" "gab" "iris" "linkulator" "shlog" "who-is" "gitbbs" "oneliner" "sl" "train" "web" "gemini" "gopher" "library"
  65. 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" \
  66. '-------------------' \
  67. '----------' \
  68. '----------' \
  69. '----------' \
  70. '----------' \
  71. '----------' \
  72. '----------' \
  73. '----------' \
  74. '----------' \
  75. '----------' \
  76. '----------' \
  77. '----------' \
  78. '----------' \
  79. '----------'
  80. else
  81. 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" \
  82. "user" "gab" "iris" "linkulator" "shlog" "who-is" "gitbbs" "oneliner" "sl" "train" "web" "gemini" "gopher" "library"
  83. fi
  84. FILLER='..........'
  85. for u in ${!ACTIVE_USERS[@]} ; do
  86. 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" \
  87. "$u" ${GAB["$u"]:="${FILLER}"} ${IRIS["$u"]:="${FILLER}"} ${LINKULATOR["$u"]:="${FILLER}"} ${SHLOG["$u"]:="${FILLER}"} ${WHOIS["$u"]:="${FILLER}"} \
  88. ${GITBBS["$u"]:="${FILLER}"} ${ONELINER["$u"]:="${FILLER}"} ${SL["$u"]:="${FILLER}"} ${TRAIN["$u"]:="${FILLER}"} ${WEB["$u"]:="${FILLER}"} \
  89. ${GEMINI["$u"]:="${FILLER}"} ${GOPHER["$u"]:="${FILLER}"} ${ELIBRARY["$u"]:="${FILLER}"}
  90. done | sort
  91. if [ -n "$NO_FANCY_SHIT" ]; then
  92. 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" \
  93. '-------------------' \
  94. '----------' \
  95. '----------' \
  96. '----------' \
  97. '----------' \
  98. '----------' \
  99. '----------' \
  100. '----------' \
  101. '----------' \
  102. '----------' \
  103. '----------' \
  104. '----------' \
  105. '----------' \
  106. '----------'
  107. 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" \
  108. "Totals" \
  109. ${TOTALS["GAB"]:-0} \
  110. ${TOTALS["IRIS"]:-0} \
  111. ${TOTALS["LINKULATOR"]:-0} \
  112. ${TOTALS["SHLOG"]:-0} \
  113. ${TOTALS["WHOIS"]:-0} \
  114. ${TOTALS["GITBBS"]:-0} \
  115. ${TOTALS["ONELINER"]:-0} \
  116. ${TOTALS["SL"]:-0} \
  117. ${TOTALS["TRAIN"]:-0} \
  118. ${TOTALS["WEB"]:-0} \
  119. ${TOTALS["GEMINI"]:-0} \
  120. ${TOTALS["GOPHER"]:-0} \
  121. ${TOTALS["ELIBRARY"]:-0}
  122. else
  123. 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" \
  124. "Totals" \
  125. ${TOTALS["GAB"]:-0} \
  126. ${TOTALS["IRIS"]:-0} \
  127. ${TOTALS["LINKULATOR"]:-0} \
  128. ${TOTALS["SHLOG"]:-0} \
  129. ${TOTALS["WHOIS"]:-0} \
  130. ${TOTALS["GITBBS"]:-0} \
  131. ${TOTALS["ONELINER"]:-0} \
  132. ${TOTALS["SL"]:-0} \
  133. ${TOTALS["TRAIN"]:-0} \
  134. ${TOTALS["WEB"]:-0} \
  135. ${TOTALS["GEMINI"]:-0} \
  136. ${TOTALS["GOPHER"]:-0} \
  137. ${TOTALS["ELIBRARY"]:-0}
  138. fi
  139. rm -f "${CACHE}"