diff --git a/scripts/cloudron-setup b/scripts/cloudron-setup index 255ad0154..59be3f80a 100755 --- a/scripts/cloudron-setup +++ b/scripts/cloudron-setup @@ -236,20 +236,30 @@ while true; do sleep 10 done -if ! ip=$(curl -s --fail --connect-timeout 2 --max-time 2 https://ipv4.api.cloudron.io/api/v1/helper/public_ip | sed -n -e 's/.*"ip": "\(.*\)"/\1/p'); then - ip='' -fi +ip4=$(curl -s --fail --connect-timeout 2 --max-time 2 https://ipv4.api.cloudron.io/api/v1/helper/public_ip | sed -n -e 's/.*"ip": "\(.*\)"/\1/p' || true) +ip6=$(curl -s --fail --connect-timeout 2 --max-time 2 https://ipv6.api.cloudron.io/api/v1/helper/public_ip | sed -n -e 's/.*"ip": "\(.*\)"/\1/p' || true) + +url4="" +url6="" +fallbackUrl="" if [[ -z "${setupToken}" ]]; then - url="https://${ip}" + [[ -n "${ip4}" ]] && url4="https://${ip4}" + [[ -n "${ip6}" ]] && url6="https://[${ip6}]" + [[ -z "${ip4}" && -z "${ip6}" ]] && fallbackUrl="https://" else - url="https://${ip}/?setupToken=${setupToken}" + [[ -n "${ip4}" ]] && url4="https://${ip4}/?setupToken=${setupToken}" + [[ -n "${ip6}" ]] && url6="https://[${ip6}]/?setupToken=${setupToken}" + [[ -z "${ip4}" && -z "${ip6}" ]] && fallbackUrl="https://?setupToken=${setupToken}" fi -echo -e "\n\n${GREEN}After reboot, visit ${url} and accept the self-signed certificate to finish setup.${DONE}\n" +echo -e "\n\n${GREEN}After reboot, visit one of the following URLs and accept the self-signed certificate to finish setup.${DONE}\n" +[[ -n "${url4}" ]] && echo -e " * ${GREEN}${url4}${DONE}" +[[ -n "${url6}" ]] && echo -e " * ${GREEN}${url6}${DONE}" +[[ -n "${fallbackUrl}" ]] && echo -e " * ${GREEN}${fallbackUrl}${DONE}" if [[ "${rebootServer}" == "true" ]]; then systemctl stop box mysql # sometimes mysql ends up having corrupt privilege tables - read -p "The server has to be rebooted to apply all the settings. Reboot now ? [Y/n] " yn + read -p "\nThe server has to be rebooted to apply all the settings. Reboot now ? [Y/n] " yn yn=${yn:-y} case $yn in [Yy]* ) exitHandler; systemctl reboot;; diff --git a/setup/start/cloudron-motd b/setup/start/cloudron-motd index eecc525f5..320fc72a6 100755 --- a/setup/start/cloudron-motd +++ b/setup/start/cloudron-motd @@ -4,30 +4,51 @@ printf "**********************************************************************\n\n" -cache_file="/var/cache/cloudron-motd-cache" +readonly cache_file4="/var/cache/cloudron-motd-cache4" +readonly cache_file6="/var/cache/cloudron-motd-cache6" -if [[ -z "$(ls -A /home/yellowtent/platformdata/addons/mail/dkim)" ]]; then - if [[ ! -f "${cache_file}" ]]; then - curl --fail --connect-timeout 2 --max-time 2 -q https://ipv4.api.cloudron.io/api/v1/helper/public_ip --output "${cache_file}" || true - fi - if [[ -f "${cache_file}" ]]; then - ip=$(sed -n -e 's/.*"ip": "\(.*\)"/\1/p' /var/cache/cloudron-motd-cache) +url4="" +url6="" +fallbackUrl="" + +function detectIp() { + if [[ ! -f "${cache_file4}" ]]; then + ip4=$(curl -s --fail --connect-timeout 2 --max-time 2 https://ipv4.api.cloudron.io/api/v1/helper/public_ip | sed -n -e 's/.*"ip": "\(.*\)"/\1/p' || true) + [[ -n "${ip4}" ]] && echo "${ip4}" > "${cache_file4}" else - ip='' + ip4=$(cat "${cache_file4}") + fi + + if [[ ! -f "${cache_file6}" ]]; then + ip6=$(curl -s --fail --connect-timeout 2 --max-time 2 https://ipv6.api.cloudron.io/api/v1/helper/public_ip | sed -n -e 's/.*"ip": "\(.*\)"/\1/p' || true) + [[ -n "${ip6}" ]] && echo "${ip6}" > "${cache_file6}" + else + ip6=$(cat "${cache_file6}") fi if [[ ! -f /etc/cloudron/SETUP_TOKEN ]]; then - url="https://${ip}" + [[ -n "${ip4}" ]] && url4="https://${ip4}" + [[ -n "${ip6}" ]] && url6="https://[${ip6}]" + [[ -z "${ip4}" && -z "${ip6}" ]] && fallbackUrl="https://" else setupToken="$(cat /etc/cloudron/SETUP_TOKEN)" - url="https://${ip}/?setupToken=${setupToken}" + [[ -n "${ip4}" ]] && url4="https://${ip4}/?setupToken=${setupToken}" + [[ -n "${ip6}" ]] && url6="https://[${ip6}]/?setupToken=${setupToken}" + [[ -z "${ip4}" && -z "${ip6}" ]] && fallbackUrl="https://?setupToken=${setupToken}" fi +} + +if [[ -z "$(ls -A /home/yellowtent/platformdata/addons/mail/dkim)" ]]; then + detectIp printf "\t\t\tWELCOME TO CLOUDRON\n" printf "\t\t\t-------------------\n" - printf '\n\e[1;32m%-6s\e[m\n\n' "Visit ${url} on your browser and accept the self-signed certificate to finish setup." - printf "Cloudron overview - https://docs.cloudron.io/ \n" + printf '\n\e[1;32m%-6s\e[m\n' "Visit one of the following URLs on your browser and accept the self-signed certificate to finish setup." + [[ -n "${url4}" ]] && printf '\e[1;32m%-6s\e[m\n' " * ${url4}" + [[ -n "${url6}" ]] && printf '\e[1;32m%-6s\e[m\n' " * ${url6}" + [[ -n "${fallbackUrl}" ]] && printf '\e[1;32m%-6s\e[m\n' " * ${fallbackUrl}" + printf "\nCloudron overview - https://docs.cloudron.io/ \n" printf "Cloudron setup - https://docs.cloudron.io/installation/#setup \n" else printf "\t\t\tNOTE TO CLOUDRON ADMINS\n"