jattool-sessid 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. #shellcheck disable=SC1090
  3. . "$(sfpath)" || exit 3
  4. shellfu import pretty
  5. shellfu import saturnin
  6. usage() {
  7. mkusage "$@" "[options]" \
  8. -- \
  9. "Print current session id and exit with 0 or 1 if there is no" \
  10. "active session." \
  11. -o \
  12. "-d DIR Set JAT workdir to DIR. This is where state data" \
  13. " is kept. Default: /var/tmp/jat."
  14. }
  15. sessid() {
  16. #
  17. # Show session id or exit with 1
  18. #
  19. local sess="$SDir/session"
  20. debug -v sess
  21. test -f "$sess" || return 1
  22. test -s "$sess" || return 1
  23. grep . "$sess" || return 1
  24. return 0
  25. }
  26. main() {
  27. local SDir=$JAT__DIR
  28. while true; do case $1 in
  29. -d) SDir=$2; shift 2 || usage -w "missing SDIR" ;;
  30. -*) usage ;;
  31. *) break ;;
  32. esac done
  33. test -n "$SDir" && SDir=$(saturnin__conf -j -1 jattool.sdir)
  34. test -n "$SDir" || SDir=/var/tmp/jat
  35. debug -v SDir
  36. sessid
  37. }
  38. main "$@"