eeiam.in 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. start_familiar() {
  48. local f=$1
  49. pids_matching $f && return 0
  50. local like=$(iniread -p iam.starting.like.this.$f iam.ini)
  51. debug -v f like
  52. if test -n "$like";
  53. then
  54. $like &
  55. else $f &
  56. fi
  57. }
  58. #
  59. # subcommand handlers
  60. #
  61. i_am_afk() {
  62. #
  63. # away from keyboard; blocks until i'm back again
  64. #
  65. mocp --pause
  66. slock
  67. }
  68. i_am_at() {
  69. where_i_am
  70. }
  71. i_am_back() {
  72. #
  73. # returning to work (should be called by other subcommands)
  74. #
  75. local f
  76. for f in $(familiars_at $(where_i_am));
  77. do
  78. start_familiar $f
  79. done
  80. klist || urxvt -e kinit
  81. }
  82. i_am_gone() {
  83. #
  84. # gone fishin'
  85. #
  86. kdestroy
  87. killall $(familiars_at $(where_i_am))
  88. i_am_afk
  89. i_am_back
  90. }
  91. i_am_moving() {
  92. #
  93. # to other train or dreamland, but localhost must sleep now
  94. #
  95. die "not implemented" # hint: use zleep
  96. }
  97. i_am_ooo() {
  98. #
  99. # too dangerous to implement
  100. #
  101. die "not implemented"
  102. }
  103. i_am_wfh() {
  104. #
  105. # too dangerous to implement
  106. #
  107. die "not implemented"
  108. }
  109. i_am_writing() {
  110. #
  111. # writing in that language
  112. #
  113. set -x
  114. DISPLAY=:0 setxkbmap $1
  115. }
  116. cmd=$1
  117. test -n "$cmd" || usage
  118. available_commands | grep -qse ^$1 || usage
  119. shift
  120. i_am_$cmd $1