saturnin-iam 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/bash
  2. . "$(ffoom path)" || exit 3
  3. ffoo import inigrep
  4. ffoo import pretty
  5. ffoo import sync
  6. ffoo import saturnin_meta
  7. ffoo import saturnin_zleep
  8. #
  9. # self help
  10. #
  11. available_commands="afk at back gone ooo wfh undocking zleeping"
  12. usage() {
  13. mkusage "$available_commands"
  14. }
  15. #
  16. # querying
  17. #
  18. where_i_am() {
  19. #
  20. # what is my physical location?
  21. #
  22. if=$(inigrep -p iam.using.if)
  23. gwmac=$(arp | grep "^gateway\\>.*\\<$if\$" | tr ' ' '\n' | grep :)
  24. inigrep -p "iam.seeing.gw.$gwmac" || echo OUT
  25. }
  26. set_status() {
  27. #
  28. # set public status $1 by command in conf file
  29. #
  30. local what=$1
  31. saturnin_runhook "say_$what"
  32. saturnin_runhook "log_$what"
  33. }
  34. #
  35. # subcommand handlers
  36. #
  37. i_am_afk() {
  38. #
  39. # away from keyboard; blocks until i'm back again
  40. #
  41. mocp --pause
  42. set_status "afk"
  43. saturnin kb home # make sure to set lang to default before locking
  44. slock
  45. set_status "atk"
  46. }
  47. i_am_at() {
  48. #
  49. # Just say where I am
  50. #
  51. where_i_am
  52. }
  53. i_am_back() {
  54. #
  55. # returning to work (should be called by other subcommands)
  56. #
  57. set_status "back"
  58. klist -s || urxvt -e kinit
  59. }
  60. i_am_gone() {
  61. #
  62. # gone fishin'
  63. #
  64. kdestroy
  65. ssh-add -D
  66. set_status "gone"
  67. i_am_afk
  68. i_am_back
  69. }
  70. i_am_ooo() {
  71. #
  72. # too dangerous to implement
  73. #
  74. die "not implemented"
  75. }
  76. i_am_wfh() {
  77. #
  78. # too dangerous to implement
  79. #
  80. die "not implemented"
  81. }
  82. i_am_undocking() {
  83. #
  84. # i.e. hibernated
  85. #
  86. inigrep -p iam.undocking.like | bash -
  87. }
  88. i_am_zleeping() {
  89. #
  90. # i.e. hibernated
  91. #
  92. set_status "zleeping"
  93. zleep
  94. i_am_back
  95. }
  96. cmd=$1
  97. test -n "$cmd" || usage
  98. echo "$available_commands" | grep -qw "$cmd" || usage
  99. shift
  100. "i_am_$cmd" "$1"