#!/bin/bash set -eu -o pipefail echo "" echo "======== Cloudron Installer ========" echo "" if [ $# -lt 4 ]; then echo "Usage: ./installer.sh " exit 1 fi # commandline arguments readonly fqdn="${1}" readonly aws_access_key_id="${2}" readonly aws_access_key_secret="${3}" readonly aws_backup_bucket="${4}" readonly provider="${5}" readonly revision="${6}" # environment specific urls readonly api_server_origin="https://api.dev.cloudron.io" readonly web_server_origin="https://dev.cloudron.io" readonly release_bucket_url="https://s3.amazonaws.com/dev-cloudron-releases" readonly versions_url="https://s3.amazonaws.com/dev-cloudron-releases/versions.json" readonly installer_code_url="${release_bucket_url}/box-${revision}.tar.gz" # runtime consts readonly installer_code_file="/tmp/box.tar.gz" readonly installer_tmp_dir="/tmp/box" readonly cert_folder="/tmp/certificates" # check for fqdn in /ets/hosts echo "[INFO] checking for hostname entry" readonly hostentry_found=$(grep "${fqdn}" /etc/hosts || true) if [[ -z $hostentry_found ]]; then echo "[WARNING] No entry for ${fqdn} found in /etc/hosts" echo "Adding an entry ..." cat >> /etc/hosts < "${cert_folder}/CONFIG" < "${cert_folder}/host.key" openssl req -new -out "${cert_folder}/host.csr" -key "${cert_folder}/host.key" -config "${cert_folder}/CONFIG" openssl x509 -req -days 3650 -in "${cert_folder}/host.csr" -signkey "${cert_folder}/host.key" -out "${cert_folder}/host.cert" -extensions v3_req -extfile "${cert_folder}/CONFIG" # make them json compatible, by collapsing to one line tls_cert=$(sed ':a;N;$!ba;s/\n/\\n/g' "${cert_folder}/host.cert") tls_key=$(sed ':a;N;$!ba;s/\n/\\n/g' "${cert_folder}/host.key") echo "" echo "[INFO] Fetching installer code ..." curl "${installer_code_url}" -o "${installer_code_file}" echo "" echo "[INFO] Extracting installer code to ${installer_tmp_dir} ..." rm -rf "${installer_tmp_dir}" && mkdir -p "${installer_tmp_dir}" tar xvf "${installer_code_file}" -C "${installer_tmp_dir}" echo "" echo "Creating initial provisioning config ..." cat > /root/provision.json <