nextcloud.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env bash
  2. while true;do ls | grep -q dockerbunker.sh;if [[ $? == 0 ]];then BASE_DIR=$PWD;break;else cd ../;fi;done
  3. PROPER_NAME="Nextcloud"
  4. SERVICE_NAME="$(echo -e "${PROPER_NAME,,}" | tr -d '[:space:]')"
  5. PROMPT_SSL=1
  6. declare -a environment=( "data/env/dockerbunker.env" "data/include/init.sh" )
  7. for env in "${environment[@]}";do
  8. [[ -f "${BASE_DIR}"/$env ]] && source "${BASE_DIR}"/$env
  9. done
  10. declare -A WEB_SERVICES
  11. declare -a containers=( "${SERVICE_NAME}-service-dockerbunker" "${SERVICE_NAME}-db-dockerbunker" )
  12. declare -a add_to_network=( "${SERVICE_NAME}-service-dockerbunker" )
  13. declare -A IMAGES=( [service]="nextcloud:stable" [db]="mariadb:10.2" )
  14. declare -A volumes=( [${SERVICE_NAME}-data-vol-1]="/var/www/html/custom_apps" [${SERVICE_NAME}-data-vol-2]="/var/www/html/config" [${SERVICE_NAME}-data-vol-3]="/var/www/html/data" [${SERVICE_NAME}-db-vol-1]="/var/lib/mysql" )
  15. declare -a networks=( "dockerbunker-${SERVICE_NAME}" )
  16. [[ -z $1 ]] && options_menu
  17. configure() {
  18. pre_configure_routine
  19. echo -e "# \e[4mNextcloud Settings\e[0m"
  20. set_domain
  21. unset NEXTCLOUD_ADMIN_USER
  22. if [ "$NEXTCLOUD_ADMIN_USER" ]; then
  23. read -p "Nextcloud Admin User: " -ei "$NEXTCLOUD_ADMIN_USER" NEXTCLOUD_ADMIN_USER
  24. else
  25. while [[ -z $NEXTCLOUD_ADMIN_USER || $NEXTCLOUD_ADMIN_USER == "admin" ]];do
  26. read -p "Nextcloud Admin User: " -ei "$NEXTCLOUD_ADMIN_USER" NEXTCLOUD_ADMIN_USER
  27. [[ ${NEXTCLOUD_ADMIN_USER} == "admin" ]] && echo -e "\n\e[31mAdmin account setting is invalid: name is reserved [name: admin]\e[0m\n"
  28. done
  29. fi
  30. unset NEXTCLOUD_ADMIN_PASSWORD
  31. while [[ "${#NEXTCLOUD_ADMIN_PASSWORD}" -le 6 || "$NEXTCLOUD_ADMIN_PASSWORD" != *[A-Z]* || "$NEXTCLOUD_ADMIN_PASSWORD" != *[a-z]* || "$NEXTCLOUD_ADMIN_PASSWORD" != *[0-9]* ]];do
  32. if [ $VALIDATE ];then
  33. echo -e "\n\e[31m Password does not meet requirements\e[0m"
  34. fi
  35. stty_orig=$(stty -g)
  36. stty -echo
  37. read -p " $(printf "\n \e[4mPassword requirements\e[0m\n Minimum Length 6,Uppercase, Lowercase, Integer\n\n Enter Password:") " -ei "" NEXTCLOUD_ADMIN_PASSWORD
  38. stty "$stty_orig"
  39. echo ""
  40. VALIDATE=1
  41. done
  42. unset VALIDATE
  43. echo ""
  44. # avoid tr illegal byte sequence in macOS when generating random strings
  45. if [[ $OSTYPE =~ "darwin" ]];then
  46. if [[ $LC_ALL ]];then
  47. oldLC_ALL=$LC_ALL
  48. export LC_ALL=C
  49. else
  50. export LC_ALL=C
  51. fi
  52. fi
  53. cat <<-EOF >> "${SERVICE_ENV}"
  54. PROPER_NAME=${PROPER_NAME}
  55. SERVICE_NAME=${SERVICE_NAME}
  56. SSL_CHOICE=${SSL_CHOICE}
  57. LE_EMAIL=${LE_EMAIL}
  58. SERVICE_DOMAIN=${SERVICE_DOMAIN}
  59. NEXTCLOUD_ADMIN_USER=${NEXTCLOUD_ADMIN_USER}
  60. NEXTCLOUD_ADMIN_PASSWORD=${NEXTCLOUD_ADMIN_PASSWORD}
  61. NEXTCLOUD_TRUSTED_DOMAINS=${SERVICE_DOMAIN}
  62. # ------------------------------
  63. # SQL database configuration
  64. # ------------------------------
  65. MYSQL_DATABASE=nextcloud
  66. MYSQL_USER=nextcloud
  67. MYSQL_HOST=db
  68. # Please use long, random alphanumeric strings (A-Za-z0-9)
  69. MYSQL_PASSWORD=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 28)
  70. MYSQL_ROOT_PASSWORD=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 28)
  71. EOF
  72. if [[ $OSTYPE =~ "darwin" ]];then
  73. [[ $oldLC_ALL ]] && export LC_ALL=$oldLC_ALL || unset LC_ALL
  74. fi
  75. post_configure_routine
  76. }
  77. if [[ $1 == "letsencrypt" ]];then
  78. $1 $*
  79. else
  80. $1
  81. fi