#!/bin/bash set -eu -o pipefail if [[ ${EUID} -ne 0 ]]; then echo "This script should be run as root." > /dev/stderr exit 1 fi ask() { # http://djm.me/ask local prompt default REPLY while true; do if [ "${2:-}" = "Y" ]; then prompt="Y/n" default=Y elif [ "${2:-}" = "N" ]; then prompt="y/N" default=N else prompt="y/n" default= fi # Ask the question (not using "read -p" as it uses stderr not stdout) echo -n "$1 [$prompt] " # Read the answer (use /dev/tty in case stdin is redirected from somewhere else) read REPLY Update package repositories ..." if ! apt-get update &>> "${LOG_FILE}"; then echo "Could not update package repositories" exit 1 fi echo "=> Installing setup dependencies ..." if ! apt-get install curl dnsutils -y &>> "${LOG_FILE}"; then echo "Could not install setup dependencies (curl and dnsutils)" exit 1 fi ip=$(dig a "my.${domain}" +short) echo "" if [[ -z "${ip}" ]]; then echo "No DNS A record found for my.${domain}" echo "First create a new DNS A record for my.${domain} pointing to the public ip address of this server." exit 1 fi echo "Found DNS A record for my.${domain} pointing to:" echo "${ip}" echo "" if ! ask "Is this correct?"; then echo "Please ensure that the A record for my.${domain} is pointing to the correct public ip address of this server." exit 1 fi echo "" echo "=> Downloading initialization script" if ! curl -s "${INIT_BASESYSTEM_SCRIPT_URL}" > /tmp/initializeBaseUbuntuImage.sh; then echo "Could not download initialization script" exit 1 fi echo "=> Installing base dependencies ... (this takes some time)" if ! /bin/bash /tmp/initializeBaseUbuntuImage.sh "${INSTALLER_REVISION}" "${provider}" &>> "${LOG_FILE}"; then echo "Init script failed. See ${LOG_FILE} for details" exit 1 fi rm /tmp/initializeBaseUbuntuImage.sh echo "=> Checking version" NPM_BIN=$(npm bin -g 2>/dev/null) if ! version=$(${NPM_BIN}/cloudron-version --out version --versions-url "${versionsUrl}" --version "${version}"); then echo "No such version ${version}" exit 1 fi if ! sourceTarballUrl=$(${NPM_BIN}/cloudron-version --out tarballUrl --versions-url "${versionsUrl}" --version "${version}"); then echo "No source code for version ${version}" exit 1 fi echo "=> Run base init service" systemctl start cloudron-system-setup if [[ -z "${restoreUrl}" ]]; then data=$(cat < Run installer.sh for version ${version} with ${sourceTarballUrl} ... (this takes some time)" if ! ${INSTALLER_SOURCE_DIR}/scripts/installer.sh --sourcetarballurl "${sourceTarballUrl}" --data "${data}" &>> "${LOG_FILE}"; then echo "Failed to install cloudron. See ${LOG_FILE} for details" exit 1 fi echo -n "=> Waiting for cloudron to be ready" while true; do echo -n "." if journalctl -u box -a | grep "platformReady: configured, resuming tasks" >/dev/null; then break fi sleep 10 done echo "" echo "Visit https://my.${domain} to finish setup" echo ""