rc.local.off 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. function err {
  3. printf %s": "%s"\n" "$(basename $0)" "$1"
  4. exit 1
  5. }
  6. ## some Superglue special checks
  7. ## USB drive should be already mounted here
  8. _WWW="/www"
  9. ## try to mount 30 times with 2 second breaks
  10. while ! mountpoint -q $_WWW; do [[ $n -gt 30 ]] && err 'failed to mount /www..';
  11. sleep 2
  12. block mount &>/dev/null
  13. let n++
  14. done
  15. ## if /www is mounted, then..
  16. _HTDOCS="$_WWW/htdocs"
  17. ## make ./htdocs if there is none
  18. [[ -e $_HTDOCS ]] || { mkdir $_HTDOCS; let E++; }
  19. ## if not writable chown with httpd
  20. [[ $(stat $_HTDOCS -c %U) == 'httpd' ]] || { chown -R httpd $_HTDOCS; let E++; }
  21. [[ ! $(stat $_HTDOCS -c %a) -lt '755' ]] || { chmod -R u+rwX $_HTDOCS; let E++; }
  22. ## check if index.html is present
  23. [[ -e $_HTDOCS/index.html ]] || (
  24. cp /opt/lib/resources/demo.html $_HTDOCS/default.html
  25. chown httpd $_HTDOCS/default.html
  26. )
  27. ## check for log directory
  28. [[ -e $_WWW/log ]] || {
  29. mkdir $_WWW/log;
  30. chown httpd $_WWW/log;
  31. let E++; }
  32. ## check for tmp directory
  33. [[ -e $_WWW/tmp ]] || {
  34. mkdir $_WWW/tmp;
  35. chown httpd $_WWW/tmp;
  36. let E++; }
  37. ## if any of the above triggered reload lighttpd
  38. [[ -z $E ]] || (
  39. echo 'reloading lighttpd'
  40. /etc/init.d/lighttpd reload
  41. )