#!/hint/bash

FB_WIDTH="$(fbset | grep geometry | awk '{print $3}')"

FONT_SIZE=20
if ((FB_WIDTH < 901)); then
  FONT_SIZE=16
elif ((FB_WIDTH >= 901 && FB_WIDTH < 1081)); then
  FONT_SIZE=20
else
  FONT_SIZE=27
fi

if [ -z "$SSH_CONNECTION" ]; then
  if [[ "$(tty)" =~ /dev/(pts|tty) ]] \
    && ! pgrep fbterm >/dev/null && [ -e /dev/fb0 ]; then
    exec fbterm -s "$FONT_SIZE" -n Hack
  fi
fi

# shellcheck source=./bash_colors
[ -r "$HOME/.bash_colors" ] && source "$HOME/.bash_colors"
# shellcheck source=./bash_aux
[ -r "$HOME/.bash_aux" ] && source "$HOME/.bash_aux"

# Sourcing of autocomplete scripts
[ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion

# [ -d "/opt/admin" ] && cd "/opt/admin" || exit 0

latest="$(/opt/admin/bin/tl-comp-latest desktop)"
all="$(basename "$(find /srv/desktop -type f -name 'v*.*.*.tar.gz' | cut -d'/' -f4)" .tar.gz)"
admin="$(tail -n1 /opt/admin/.version)"

tl_role="installer"
if grep recovery /proc/cmdline; then
  tl_role="recovery"
fi
#
# Print help every time
#
lsblk
say "
  \t \t \t Welcome to the TechLit $tl_role system $(cat /etc/tl-recovery-version)

Hints:
  $c#$y use $(g lsblk) to list block devices.
  $c#$y use $(g nmtui) to setup WiFi.
  $c#$y use $(g tmux) to multitask.
\n
To Install or Update:
  Note: Replace tl-xxxx with the tag and /dev/sdX with the drive
  
  - Partition hard drive and provision a techlit-system (one-time per machine)
      $(c $) $(g tl-hw-prepare)  $(c /dev/sdx)  $(c tl-xxxx)

  - Update TechLit OS (every machine for every update)
      $(c $) $(g tl-hw-update-desktop)  $(c /dev/sdx)

  VERSIONS
    Desktop: $(c $latest)
        All: $(c $all)
      Admin: $(c $admin)


Shortcuts(fbterm):
  $(c CTRL_ALT_\{C,D,E\}): {create,Destroy} a window or quit FbTerm
  $(c CTRL_ALT_1): switch to window n
  $(c SHIFT_\{PAGEUP,PAGEDOWN\}): history scroll up or down
"
