Guest User

Untitled

a guest
Jan 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #!/sbin/runscript
  2. # Copyright 1999-2011 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. # $Header: $
  5.  
  6. opts="run"
  7. script="/etc/init.d/rfkill-event"
  8. pidfile="/var/run/rfkill-event.pid"
  9.  
  10. # op=2 - status change
  11. # op=0 - init device
  12. # op=1 - destroy device
  13.  
  14. # (soft|hard)=0 - flag not setted (device enable)
  15. # (soft|hard)=1 - flag setted (device disabled)
  16.  
  17. # stop at (op=1 || hwst=1)
  18. # start at ((op=0 && hwst=0 ) || (op=2 && hwst=0)) # || (op!=1 && hwst=0)
  19. run() {
  20. LIST=""
  21. rfkill event\
  22. | sed -u -e 's/.*idx \([0-9]*\) type [0-9]* op \([0-2]\) soft [0-1] hard \([0-1]\)\|.*/\1 \2 \3/' -e '/^$/d'\
  23. | while read idx op hwst;
  24. do
  25. # update rf indexes
  26. [ -z "$LIST" -o x"$op" != x"1" ] && LIST=$(rfkill list | grep -v '^[[:space:]].*')
  27. sys=$(echo "$LIST" | sed -e "s/${idx}: \([a-z]*\).*\|.*/\1/" -e '/^$/d' | head -n1)
  28. [ -z "$sys" ] && continue
  29. if [ x"$op" = x"1" -o x"$hwst" = x"1" ];
  30. then
  31. # rf set off
  32. einfo "RF $sys got down"
  33. find -L "/etc/runlevels/rf-${sys}" -type f -exec sh -c "[ -x '{}' ] && '{}' stop" \; 2>/dev/null
  34. elif [ x"$op" != x"1" -a x"$hwst" = x"0" ];
  35. then
  36. # rf set on
  37. einfo "RF $sys got up"
  38. find -L "/etc/runlevels/rf-${sys}" -type f -exec sh -c "[ -x '{}' ] && '{}' start" \; 2>/dev/null
  39. fi
  40. done
  41. }
  42.  
  43. start() {
  44. ebegin "Start rfkill event catcher"
  45. start-stop-daemon -S -x ${script} --pidfile "$pidfile" -mb -- run
  46. R=$?
  47. if [ $R -eq 0 ];
  48. then
  49. (
  50. sleep 3
  51. P=$( (ps --ppid $(cat "$pidfile") -o pid | tail -n1 | xargs -I {} ps --ppid {} -o pid | tail -n+2) 2>/dev/null)
  52. [ ! -z "$P" ] && echo "$P" >"$pidfile"
  53. ) &
  54. fi
  55. eend $R
  56. }
  57.  
  58. stop() {
  59. ebegin "Stop rfkill event catcher"
  60. start-stop-daemon -K -x ${script} --pidfile "$pidfile"
  61. eend $?
  62. }
Add Comment
Please, Sign In to add comment