123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/bin/bash
  2. . __FFOO_INIT__
  3. FFOO_INIPATH="__FFOO_INIPATH__"
  4. ffoo import core
  5. ffoo import ini
  6. ffoo import recon
  7. #
  8. # self help
  9. #
  10. available_commands() {
  11. echo afk
  12. echo at
  13. echo back
  14. echo gone
  15. echo moving
  16. echo ooo
  17. echo wfh
  18. echo writing
  19. }
  20. usage() {
  21. cmd_hint=$(
  22. available_commands \
  23. | head -c -1 \
  24. | tr '\n' '|'
  25. )
  26. usage_is "$cmd_hint"
  27. }
  28. #
  29. # querying
  30. #
  31. familiars_at() {
  32. #
  33. # daemons specific to $1 location plus the rest
  34. #
  35. test -n "$1" || usagef "location"
  36. iniread -p iam.running.at.$1 iam.ini
  37. iniread -p iam.running.at.ANYPLACE iam.ini
  38. }
  39. where_i_am() {
  40. #
  41. # what is my physical location?
  42. #
  43. if=$(iniread -p iam.using.if iam.ini)
  44. gwmac=$(arp | grep "^gateway\\>.*\\<$if\$" | tr ' ' '\n' | grep :)
  45. iniread -p iam.seeing.gw.$gwmac iam.ini || echo OUT
  46. }
  47. #
  48. # subcommand handlers
  49. #
  50. i_am_afk() {
  51. #
  52. # away from keyboard; blocks until i'm back again
  53. #
  54. mocp --pause
  55. slock
  56. }
  57. i_am_at() {
  58. where_i_am
  59. }
  60. i_am_back() {
  61. #
  62. # returning to work (should be called by other subcommands)
  63. #
  64. local f
  65. for f in $(familiars_at $(where_i_am));
  66. do
  67. pids_matching $f || $f &
  68. done
  69. klist || urxvt -e kinit
  70. }
  71. i_am_gone() {
  72. #
  73. # gone fishin'
  74. #
  75. kdestroy
  76. killall $(familiars_at $(where_i_am))
  77. i_am_afk
  78. i_am_back
  79. }
  80. i_am_moving() {
  81. #
  82. # to other train or dreamland, but localhost must sleep now
  83. #
  84. die "not implemented" # hint: use zleep
  85. }
  86. i_am_ooo() {
  87. #
  88. # too dangerous to implement
  89. #
  90. die "not implemented"
  91. }
  92. i_am_wfh() {
  93. #
  94. # too dangerous to implement
  95. #
  96. die "not implemented"
  97. }
  98. i_am_writing() {
  99. #
  100. # writing in that language
  101. #
  102. set -x
  103. DISPLAY=:0 setxkbmap $1
  104. }
  105. cmd=$1
  106. test -n "$cmd" || usage
  107. available_commands | grep -qse ^$1 || usage
  108. shift
  109. i_am_$cmd $1