Pictures!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

client.sh 1008B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. REMOTE='http://localhost:8080'
  3. INTERVAL=1
  4. requirecmd()
  5. {
  6. which "$1" 2>1 > /dev/null
  7. if [ "$?" -ne 0 ]; then
  8. echo "Missing command: $1"
  9. exit 1
  10. fi
  11. }
  12. requirecmd curl
  13. requirecmd fbv
  14. requirecmd shasum
  15. calchash()
  16. {
  17. shasum --algorithm 1 "$1" 2>/dev/null | cut -d ' ' -f 1
  18. }
  19. PICFILE="pic"
  20. PICHASH=$(calchash "$PICFILE")
  21. PROGPID=$$
  22. # Loop responsible for requesting to the server
  23. # and updating the picture if necessary
  24. requestloop()
  25. {
  26. while :; do
  27. URL="$REMOTE/$PICHASH"
  28. curl --silent "$URL" > refresh
  29. # Empty response means the file hasn't changed
  30. if [ $(file refresh | cut -d ' ' -f 2) = "empty" ]; then
  31. rm refresh
  32. # If the response is non-empty, we received an image file.
  33. # We move that file to $PICFILE, then display it
  34. else
  35. mv refresh "$PICFILE"
  36. PICHASH=$(calchash "$PICFILE")
  37. pkill --parent "$PROGPID" fbv
  38. fi
  39. sleep "$INTERVAL"
  40. done
  41. }
  42. requestloop &
  43. while :; do
  44. if [ -f "$PICFILE" ]; then
  45. fbv --noclear --noinfo "$PICFILE"
  46. else
  47. sleep 2;
  48. fi
  49. done