Docker Image for Nextcloud software based on the original image https://hub.docker.com/r/r3pek/nextcloud/
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.

entrypoint.sh 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/bin/bash
  2. set -eu
  3. # version_greater A B returns whether A > B
  4. version_greater() {
  5. [ "$(printf '%s\n' "$@" | sort -t '.' -n -k1,1 -k2,2 -k3,3 -k4,4 | head -n 1)" != "$1" ]
  6. }
  7. # return true if specified directory is empty
  8. directory_empty() {
  9. [ -z "$(ls -A "$1/")" ]
  10. }
  11. run_as() {
  12. if [ "$(id -u)" = 0 ]; then
  13. su -p www-data -s /bin/sh -c "$1"
  14. else
  15. sh -c "$1"
  16. fi
  17. }
  18. #if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
  19. if [[ "$1" == *apache* ]] || [[ "$1" == *supervisord* ]] || [[ "$1" == *php-fpm* ]]; then
  20. installed_version="0.0.0.0"
  21. if [ -f /var/www/html/version.php ]; then
  22. # shellcheck disable=SC2016
  23. installed_version="$(php -r 'require "/var/www/html/version.php"; echo implode(".", $OC_Version);')"
  24. fi
  25. # shellcheck disable=SC2016
  26. image_version="$(php -r 'require "/usr/src/nextcloud/version.php"; echo implode(".", $OC_Version);')"
  27. if version_greater "$installed_version" "$image_version"; then
  28. echo "Can't start Nextcloud because the version of the data ($installed_version) is higher than the docker image version ($image_version) and downgrading is not supported. Are you sure you have pulled the newest image version?"
  29. exit 1
  30. fi
  31. if version_greater "$image_version" "$installed_version"; then
  32. echo "Initializing nextcloud $image_version ..."
  33. if [ "$installed_version" != "0.0.0.0" ]; then
  34. echo "Upgrading nextcloud from $installed_version ..."
  35. run_as 'php /var/www/html/occ app:list' | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_before
  36. fi
  37. if [ "$(id -u)" = 0 ]; then
  38. rsync_options="-rlDog --chown www-data:root"
  39. else
  40. rsync_options="-rlD"
  41. fi
  42. rsync $rsync_options --delete --exclude-from=/upgrade.exclude /usr/src/nextcloud/ /var/www/html/
  43. for dir in config data custom_apps themes; do
  44. if [ ! -d "/var/www/html/$dir" ] || directory_empty "/var/www/html/$dir"; then
  45. rsync $rsync_options --include "/$dir/" --exclude '/*' /usr/src/nextcloud/ /var/www/html/
  46. fi
  47. done
  48. echo "Initializing finished"
  49. #install
  50. if [ "$installed_version" = "0.0.0.0" ]; then
  51. echo "New nextcloud instance"
  52. if [ -n "${NEXTCLOUD_ADMIN_USER+x}" ] && [ -n "${NEXTCLOUD_ADMIN_PASSWORD+x}" ]; then
  53. # shellcheck disable=SC2016
  54. install_options='-n --admin-user "$NEXTCLOUD_ADMIN_USER" --admin-pass "$NEXTCLOUD_ADMIN_PASSWORD"'
  55. if [ -n "${NEXTCLOUD_TABLE_PREFIX+x}" ]; then
  56. # shellcheck disable=SC2016
  57. install_options=$install_options' --database-table-prefix "$NEXTCLOUD_TABLE_PREFIX"'
  58. else
  59. install_options=$install_options' --database-table-prefix ""'
  60. fi
  61. if [ -n "${NEXTCLOUD_DATA_DIR+x}" ]; then
  62. # shellcheck disable=SC2016
  63. install_options=$install_options' --data-dir "$NEXTCLOUD_DATA_DIR"'
  64. fi
  65. install=false
  66. if [ -n "${SQLITE_DATABASE+x}" ]; then
  67. echo "Installing with SQLite database"
  68. # shellcheck disable=SC2016
  69. install_options=$install_options' --database-name "$SQLITE_DATABASE"'
  70. install=true
  71. elif [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_USER+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ]; then
  72. echo "Installing with MySQL database"
  73. # shellcheck disable=SC2016
  74. install_options=$install_options' --database mysql --database-name "$MYSQL_DATABASE" --database-user "$MYSQL_USER" --database-pass "$MYSQL_PASSWORD" --database-host "$MYSQL_HOST"'
  75. install=true
  76. elif [ -n "${POSTGRES_DB+x}" ] && [ -n "${POSTGRES_USER+x}" ] && [ -n "${POSTGRES_PASSWORD+x}" ] && [ -n "${POSTGRES_HOST+x}" ]; then
  77. echo "Installing with PostgreSQL database"
  78. # shellcheck disable=SC2016
  79. install_options=$install_options' --database pgsql --database-name "$POSTGRES_DB" --database-user "$POSTGRES_USER" --database-pass "$POSTGRES_PASSWORD" --database-host "$POSTGRES_HOST"'
  80. install=true
  81. fi
  82. if [ "$install" = true ]; then
  83. echo "starting nexcloud installation"
  84. max_retries=10
  85. try=0
  86. until run_as "php /var/www/html/occ maintenance:install $install_options" || [ "$try" -gt "$max_retries" ]
  87. do
  88. echo "retrying install..."
  89. try=$((try+1))
  90. sleep 3s
  91. done
  92. if [ "$try" -gt "$max_retries" ]; then
  93. echo "installing of nextcloud failed!"
  94. exit 1
  95. fi
  96. else
  97. echo "running web-based installer on first connect!"
  98. fi
  99. fi
  100. #upgrade
  101. else
  102. run_as 'php /var/www/html/occ upgrade'
  103. run_as 'php /var/www/html/occ app:list' | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after
  104. echo "The following apps have been disabled:"
  105. diff /tmp/list_before /tmp/list_after | grep '<' | cut -d- -f2 | cut -d: -f1
  106. rm -f /tmp/list_before /tmp/list_after
  107. fi
  108. # Update htaccess
  109. run_as 'php /var/www/html/occ maintenance:update:htaccess'
  110. fi
  111. fi
  112. exec "$@"