If we provide the backup key we have to provide other values to prevent having to perform value merging in settings.js defaults
141 lines
4.1 KiB
Bash
Executable File
141 lines
4.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -eu -o pipefail
|
|
|
|
if [[ ${EUID} -ne 0 ]]; then
|
|
echo "This script should be run as root." > /dev/stderr
|
|
exit 1
|
|
fi
|
|
|
|
# change this to a hash when we make a upgrade release
|
|
readonly INSTALLER_REVISION=master
|
|
readonly INIT_BASESYSTEM_SCRIPT_URL="https://git.cloudron.io/cloudron/box/raw/${INSTALLER_REVISION}/baseimage/initializeBaseUbuntuImage.sh"
|
|
readonly INSTALLER_SOURCE_DIR="/home/yellowtent/installer"
|
|
readonly LOG_FILE="/var/log/cloudron-setup.log"
|
|
|
|
domain=""
|
|
provider=""
|
|
encryptionKey=""
|
|
restoreUrl=""
|
|
tlsProvider="letsencrypt-prod"
|
|
versionsUrl="https://s3.amazonaws.com/prod-cloudron-releases/versions.json"
|
|
version="latest"
|
|
|
|
args=$(getopt -o "" -l "domain:,help,provider:,encryption-key:,restore-url:,tls-provider:,version:,versions-url:" -n "$0" -- "$@")
|
|
eval set -- "${args}"
|
|
|
|
while true; do
|
|
case "$1" in
|
|
--domain) domain="$2"; shift 2;;
|
|
--help) echo "See https://cloudron.io/references/selfhosting.html on how to install Cloudron"; exit 0;;
|
|
--provider) provider="$2"; shift 2;;
|
|
--encryption-key) encryptionKey="$2"; shift 2;;
|
|
--restore-url) restoreUrl="$2"; shift 2;;
|
|
--tls-provider) tlsProvider="$2"; shift 2;;
|
|
--version) version="$2"; shift 2;;
|
|
--versions-url) versionsUrl="$2"; shift 2;;
|
|
--) break;;
|
|
*) echo "Unknown option $1"; exit 1;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "${domain}" ]]; then
|
|
echo "--domain is required"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -z "${provider}" ]]; then
|
|
echo "--provider is required (generic, scaleway, ec2, digitalocean)"
|
|
exit 1
|
|
elif [[ \
|
|
"${provider}" != "generic" && \
|
|
"${provider}" != "scaleway" && \
|
|
"${provider}" != "ec2" && \
|
|
"${provider}" != "digitalocean" \
|
|
]]; then
|
|
echo "--provider must be one of: generic, scaleway, ec2, digitalocean"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -z "${encryptionKey}" ]]; then
|
|
echo "--encryption-key for backup encryption is required"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo "##############################################"
|
|
echo " Cloudron Setup (${version}) "
|
|
echo "##############################################"
|
|
echo ""
|
|
echo " Follow setup logs in a second terminal with:"
|
|
echo " $ tail -f ${LOG_FILE}"
|
|
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 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
|
|
|
|
data=$(cat <<EOF
|
|
{
|
|
"boxVersionsUrl": "${versionsUrl}",
|
|
"fqdn": "${domain}",
|
|
"provider": "${provider}",
|
|
"restore": {
|
|
"url": "${restoreUrl}",
|
|
"key": "${encryptionKey}"
|
|
},
|
|
"tlsConfig": {
|
|
"provider": "${tlsProvider}"
|
|
},
|
|
"backupConfig" : {
|
|
"provider": "filesystem",
|
|
"backupFolder": "/var/backups",
|
|
"key": "${encryptionKey}"
|
|
},
|
|
"version": "${version}"
|
|
}
|
|
EOF
|
|
)
|
|
|
|
echo "=> 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 ""
|