mount.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. PID=0
  3. term() {
  4. if [ "$PID" -ne 0 ]
  5. then
  6. echo "Shutting down..." >&2
  7. umount.s3ql "$MOUNTPOINT"
  8. exit $?
  9. fi
  10. }
  11. error() {
  12. echo "An error occured. Exiting $0." >&2
  13. exit 1
  14. }
  15. # Create mountpoint if not exists
  16. if [ ! -d "$MOUNTPOINT" ]
  17. then
  18. echo "Creating $MOUNTPOINT..."
  19. mkdir -p "$MOUNTPOINT" || error
  20. fi
  21. # Mount FS
  22. if [ -f "$S3QL_AUTHFILE" ]
  23. then
  24. # Set S3QL_URL if empty with first storage-url of authfile
  25. if [ -z "$S3QL_URL" ]
  26. then
  27. S3QL_URL=$(sed -n 's/storage-url *: *\(.*\)/\1/p' "$S3QL_AUTHFILE"|head -n1)
  28. fi
  29. # shellcheck disable=SC2086
  30. fsck.s3ql $S3QL_FSCK_OPTIONS --authfile "$S3QL_AUTHFILE" --batch "$S3QL_URL" && FSCK_RESULT=$?
  31. if [ $FSCK_RESULT -ne 0 ] && [ $FSCK_RESULT -ne 128 ]; then
  32. echo "fsck.s3ql reported errors! Exit code $FSCK_RESULT - see http://www.rath.org/s3ql-docs/man/fsck.html"
  33. error
  34. fi
  35. trap 'term' TERM INT HUP
  36. # shellcheck disable=SC2086
  37. mount.s3ql $S3QL_MOUNT_OPTIONS --authfile "$S3QL_AUTHFILE" --fg "$S3QL_URL" "$MOUNTPOINT" & PID=$!
  38. wait $PID
  39. else
  40. echo "Authfile not found" >&2
  41. error
  42. fi