docker-entrypoint.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. set -e
  3. # Allow to run complementary processes or to enter the container without
  4. # running this init script.
  5. if [ "$1" == '/usr/bin/rsync' ]; then
  6. # Ensure time is in sync with host
  7. # see https://wiki.alpinelinux.org/wiki/Setting_the_timezone
  8. if [ -n ${TZ} ] && [ -f /usr/share/zoneinfo/${TZ} ]; then
  9. ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime
  10. echo ${TZ} > /etc/timezone
  11. fi
  12. # Defaults
  13. VOLUME_PATH=${VOLUME_PATH:-/docker}
  14. HOSTS_ALLOW=${HOSTS_ALLOW:-0.0.0.0/0}
  15. READ_ONLY=${READ_ONLY:-false}
  16. CHROOT=${CHROOT:-no}
  17. VOLUME_NAME=${VOLUME_NAME:-volume}
  18. USERNAME=${USERNAME:-rsyncuser}
  19. # Ensure VOLUME PATH exists
  20. if [ ! -e $VOLUME_PATH ]; then
  21. mkdir -p /$VOLUME_PATH
  22. fi
  23. # Grab UID of owner of the volume directory
  24. if [ -z $OWNER_ID ]; then
  25. OWNER_ID=$(stat -c '%u' $VOLUME_PATH)
  26. else
  27. echo "OWNER_ID is set forced to: $OWNER_ID"
  28. fi
  29. if [ -z $GROUP_ID ]; then
  30. GROUP_ID=$(stat -c '%g' $VOLUME_PATH)
  31. else
  32. echo "GROUP_ID is set forced to: $GROUP_ID"
  33. fi
  34. # Generate password file
  35. if [ ! -z $PASSWORD ]; then
  36. echo "$USERNAME:$PASSWORD" > /etc/rsyncd.secrets
  37. chmod 600 /etc/rsyncd.secrets
  38. fi
  39. # Generate configuration
  40. eval "echo \"$(cat /rsyncd.tpl.conf)\"" > /etc/rsyncd.conf
  41. # Check if a script is available in /docker-entrypoint.d and source it
  42. # You can use it for example to create additional sftp users
  43. for f in /docker-entrypoint.d/*; do
  44. case "$f" in
  45. *.sh) echo "$0: running $f"; . "$f" ;;
  46. *) echo "$0: ignoring $f" ;;
  47. esac
  48. done
  49. fi
  50. exec "$@"