Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 25th, 2011  |  syntax: Bash  |  size: 1.73 KB  |  views: 652  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2.  
  3. read cvmPid < /var/run/cvm.pid
  4.  
  5. if [[ -z "$cvmPid" ]]; then
  6.         echo "cvm isn't running..."
  7.         exit 2
  8. fi
  9.  
  10. if [[ ! -e "/var/run/progRem.pid" ]]; then
  11.         echo $$ > "/var/run/progRem.pid"
  12. else
  13.         echo "Progress bar remover is already running"
  14.         exit 1
  15. fi
  16.  
  17. trap "rm /var/run/progRem.pid ; exit" SIGINT SIGTERM
  18.  
  19. ## Print white space over progress bar
  20. eraseProgress() {
  21.         waitForEink
  22.  
  23.         eips -n 0 38 "                                                  "
  24.         eips 0 39 "                                                  "
  25. }
  26.  
  27. ## Check if we need to look for a book/check if current book is open
  28. bookCheck() {
  29.         ## Check if cvm has a open file descriptor for a file in /mnt/us/documents/
  30.         if [[ -n "$fd" -a -n "$book" ]]; then
  31.                 if [[ "$(realpath /proc/$cvmPid/fd/$fd 2> /dev/null)" == "$book" ]]; then
  32.                         if [[ "$bookType" != "BAD" ]]; then
  33.                                 eraseProgress
  34.                         fi
  35.                 else
  36.                         book=""
  37.                         bookType=""
  38.                         findBook
  39.                 fi
  40.         else
  41.                 findBook
  42.         fi
  43. }
  44.  
  45. ## Check if cvm has a file descriptor open in /mnt/us/documents
  46. findBook() {
  47.         fd="$(ls -l /proc/$cvmPid/fd/ | awk '/\/mnt\/us\/documents\// {print $9}')"
  48.         if [[ -n "$fd" ]]; then
  49.                 book="$(realpath /proc/$cvmPid/fd/$fd 2> /dev/null)"
  50.                 bookType="${book##*.}"
  51.                 case $bookType in
  52.                         [Mm][Oo][Bb][Ii]|[Pp][Dd][Ff]|[Pp][Rr][Cc]|[Aa][Zz][Ww]*|[Tt][Xx][Tt])
  53.                                 eraseProgress
  54.                         ;;
  55.                         *)
  56.                                 bookType="BAD"
  57.                         ;;
  58.                 esac
  59.         fi
  60. }
  61.  
  62. ## Check if /var/log/messages has changed within the last second
  63. waitForEink() {
  64.         c=1
  65.         while [[ "$(stat -c %Y /var/log/messages)" -lt "$time" -a "$c" -lt "10" ]]; do
  66.                 let c+=1
  67.                 usleep 100000
  68.         done
  69. }
  70.  
  71. ## Wait for page turn
  72. while :; do
  73.         case "$(waitforkey)" in
  74.                 191*|109*|104*|193*)
  75.                         time="$(($(date +%s)-1))"
  76.                         bookCheck
  77.                 ;;
  78.         esac
  79. done
clone this paste RAW Paste Data