eeiam.in 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #!/bin/bash
  2. . <(ffoom init)
  3. FFOO_INI_PATH="__EECC_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 bbl
  15. echo bbldone
  16. echo deaf
  17. echo deafnomore
  18. echo gone
  19. echo listening
  20. echo moving
  21. echo ooo
  22. echo wfh
  23. echo writing
  24. }
  25. usage() {
  26. cmd_hint=$(
  27. available_commands \
  28. | head -c -1 \
  29. | tr '\n' '|'
  30. )
  31. usage_is "$cmd_hint"
  32. }
  33. #
  34. # querying
  35. #
  36. familiars_at() {
  37. #
  38. # daemons specific to $1 location plus the rest
  39. #
  40. test -n "$1" || usagef "location"
  41. iniread -p iam.running.at.$1
  42. iniread -p iam.running.at.ANYPLACE
  43. }
  44. where_i_am() {
  45. #
  46. # what is my physical location?
  47. #
  48. if=$(iniread -p iam.using.if)
  49. gwmac=$(arp | grep "^gateway\\>.*\\<$if\$" | tr ' ' '\n' | grep :)
  50. iniread -p iam.seeing.gw.$gwmac || echo OUT
  51. }
  52. start_familiar() {
  53. #
  54. # start familiar as indicated by ini file (unless running)
  55. #
  56. local f=$1
  57. pids_matching $f && return 0
  58. local like=$(iniread -p iam.starting.like.this.$f)
  59. debug -v f like
  60. if test -n "$like";
  61. then
  62. $like &
  63. else $f &
  64. fi
  65. }
  66. set_status() {
  67. #
  68. # set public status $1 by command in ini file
  69. #
  70. local what=$1
  71. iniread -p iam.saying.like.this.$what | bash
  72. }
  73. sound_is_muted() {
  74. #
  75. # At least one playback channel is muted
  76. #
  77. local master_status="$(amixer get Master)"
  78. echo "$master_status" \
  79. | grep "Playback channels" \
  80. | sed -e 's/.*: //; s/ - /\n/' \
  81. | while read chname
  82. do
  83. grep -e "^ *$chname" <<<"$master_status"
  84. done \
  85. | grep -qse '\[off\]$'
  86. }
  87. #
  88. # subcommand handlers
  89. #
  90. i_am_afk() {
  91. #
  92. # away from keyboard; blocks until i'm back again
  93. #
  94. mocp --pause
  95. set_status "afk"
  96. slock
  97. set_status "atk"
  98. }
  99. i_am_at() {
  100. #
  101. # Just say where I am
  102. #
  103. where_i_am
  104. }
  105. i_am_back() {
  106. #
  107. # returning to work (should be called by other subcommands)
  108. #
  109. local f
  110. for f in $(familiars_at $(where_i_am));
  111. do
  112. start_familiar $f
  113. done
  114. set_status "back"
  115. klist || urxvt -e kinit
  116. }
  117. i_am_bbl() {
  118. #
  119. # changing language
  120. #
  121. local cur=$(setxkbmap -v | grep '^symbols: ' | cut -d+ -f2)
  122. local all="$(iniread -p iam.typing.lang)"
  123. local def="$(iniread -1 -p iam.typing.lang)"
  124. local nxt=$(
  125. echo -e "$all\n$all" \
  126. | grep -m 1 -A 1 $cur \
  127. | tail -1
  128. )
  129. test -z "$nxt" && nxt=$def
  130. test -z "$nxt" && nxt=us
  131. debug -v all def cur nxt
  132. setxkbmap "$nxt"
  133. }
  134. i_am_bbldone() {
  135. #
  136. # changing language back to normal
  137. #
  138. setxkbmap "$(iniread -1 -p iam.typing.lang)"
  139. }
  140. i_am_deaf() {
  141. amixer -q sset Master 5%+
  142. }
  143. i_am_deafnomore() {
  144. amixer -q sset Master 5%-
  145. }
  146. i_am_gone() {
  147. #
  148. # gone fishin'
  149. #
  150. kdestroy
  151. ssh-add -D
  152. set_status "gone"
  153. i_am_afk
  154. i_am_back
  155. }
  156. i_am_listening() {
  157. if sound_is_muted;
  158. then
  159. amixer -q sset Master unmute;
  160. else
  161. amixer -q sset Master mute;
  162. fi
  163. }
  164. i_am_moving() {
  165. #
  166. # to other train or dreamland, but localhost must sleep now
  167. #
  168. die "not implemented" # hint: use zleep
  169. }
  170. i_am_ooo() {
  171. #
  172. # too dangerous to implement
  173. #
  174. die "not implemented"
  175. }
  176. i_am_wfh() {
  177. #
  178. # too dangerous to implement
  179. #
  180. die "not implemented"
  181. }
  182. i_am_writing() {
  183. #
  184. # writing in that language
  185. #
  186. set -x
  187. DISPLAY=:0 setxkbmap $1
  188. }
  189. cmd=$1
  190. test -n "$cmd" || usage
  191. available_commands | grep -qse ^$1 || usage
  192. shift
  193. i_am_$cmd $1