eeiam.in 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. }
  19. usage() {
  20. cmd_hint=$(
  21. available_commands \
  22. | head -c -1 \
  23. | tr '\n' '|'
  24. )
  25. usage_is "$cmd_hint"
  26. }
  27. #
  28. # querying
  29. #
  30. familiars_at() {
  31. #
  32. # daemons specific to $1 location plus the rest
  33. #
  34. test -n "$1" || usagef "location"
  35. iniread -p iam.running.at.$1 iam.ini
  36. iniread -p iam.running.at.ANYPLACE iam.ini
  37. }
  38. where_i_am() {
  39. #
  40. # what is my physical location?
  41. #
  42. if=$(iniread -p iam.using.if iam.ini)
  43. gwmac=$(arp | grep "^gateway\\>.*\\<$if\$" | tr ' ' '\n' | grep :)
  44. iniread -p iam.seeing.gw.$gwmac iam.ini || echo OUT
  45. }
  46. #
  47. # subcommand handlers
  48. #
  49. i_am_afk() {
  50. #
  51. # away from keyboard; blocks until i'm back again
  52. #
  53. mocp --pause
  54. slock
  55. }
  56. i_am_at() {
  57. where_i_am
  58. }
  59. i_am_back() {
  60. #
  61. # returning to work (should be called by other subcommands)
  62. #
  63. local f fbin
  64. for f in $(familiars_at $(where_i_am));
  65. do
  66. fbin=${f/ */}
  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. cmd=$1
  99. test -n "$cmd" || usage
  100. available_commands | grep -qse ^$1 || usage
  101. i_am_$cmd