eeiam.in 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/bin/bash
  2. . <(ffoom init)
  3. FFOO_INI_PATH="__FFOO_INI_PATH__"
  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
  37. iniread -p iam.running.at.ANYPLACE
  38. }
  39. where_i_am() {
  40. #
  41. # what is my physical location?
  42. #
  43. if=$(iniread -p iam.using.if)
  44. gwmac=$(arp | grep "^gateway\\>.*\\<$if\$" | tr ' ' '\n' | grep :)
  45. iniread -p iam.seeing.gw.$gwmac || echo OUT
  46. }
  47. start_familiar() {
  48. #
  49. # start familiar as indicated by ini file (unless running)
  50. #
  51. local f=$1
  52. pids_matching $f && return 0
  53. local like=$(iniread -p iam.starting.like.this.$f)
  54. debug -v f like
  55. if test -n "$like";
  56. then
  57. $like &
  58. else $f &
  59. fi
  60. }
  61. set_status() {
  62. #
  63. # set public status $1 by command in ini file
  64. #
  65. local what=$1
  66. iniread -p iam.saying.like.this.$what | bash
  67. }
  68. #
  69. # subcommand handlers
  70. #
  71. i_am_afk() {
  72. #
  73. # away from keyboard; blocks until i'm back again
  74. #
  75. mocp --pause
  76. set_status "afk"
  77. slock
  78. set_status "atk"
  79. }
  80. i_am_at() {
  81. #
  82. # Just say where I am
  83. #
  84. where_i_am
  85. }
  86. i_am_back() {
  87. #
  88. # returning to work (should be called by other subcommands)
  89. #
  90. local f
  91. for f in $(familiars_at $(where_i_am));
  92. do
  93. start_familiar $f
  94. done
  95. set_status "back"
  96. klist || urxvt -e kinit
  97. }
  98. i_am_gone() {
  99. #
  100. # gone fishin'
  101. #
  102. kdestroy
  103. ssh-add -D
  104. set_status "gone"
  105. i_am_afk
  106. i_am_back
  107. }
  108. i_am_moving() {
  109. #
  110. # to other train or dreamland, but localhost must sleep now
  111. #
  112. die "not implemented" # hint: use zleep
  113. }
  114. i_am_ooo() {
  115. #
  116. # too dangerous to implement
  117. #
  118. die "not implemented"
  119. }
  120. i_am_wfh() {
  121. #
  122. # too dangerous to implement
  123. #
  124. die "not implemented"
  125. }
  126. i_am_writing() {
  127. #
  128. # writing in that language
  129. #
  130. set -x
  131. DISPLAY=:0 setxkbmap $1
  132. }
  133. cmd=$1
  134. test -n "$cmd" || usage
  135. available_commands | grep -qse ^$1 || usage
  136. shift
  137. i_am_$cmd $1