diff --git a/baseimage/createDOImage b/baseimage/createDOImage index dbf219120..5dfe47b24 100755 --- a/baseimage/createDOImage +++ b/baseimage/createDOImage @@ -143,6 +143,10 @@ if ! $ssh22 "root@${server_ip}" "/bin/bash /root/initializeBaseUbuntuImage.sh ${ exit 1 fi +echo "Copying installer.sh" +$scp22 "${SCRIPT_DIR}/../scripts/installer.sh" root@${server_ip}:/etc/installer.sh +$ssh22 "root@${server_ip}" "chmod +x /etc/installer.sh" + echo "Shutting down server with id : ${server_id}" $ssh22 "root@${server_ip}" "shutdown -f now" || true # shutdown sometimes terminates ssh connection immediately making this command fail diff --git a/baseimage/initializeBaseUbuntuImage.sh b/baseimage/initializeBaseUbuntuImage.sh index b494de4cd..4a210a8d3 100644 --- a/baseimage/initializeBaseUbuntuImage.sh +++ b/baseimage/initializeBaseUbuntuImage.sh @@ -5,8 +5,7 @@ set -euv -o pipefail readonly USER=yellowtent readonly USER_HOME="/home/${USER}" readonly INSTALLER_SOURCE_DIR="${USER_HOME}/installer" -readonly INSTALLER_REVISION="${1:-master}" -readonly PROVIDER="${2:-generic}" +readonly PROVIDER="${1:-generic}" readonly SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" @@ -94,14 +93,6 @@ echo "==== Install logrotate ===" apt-get install -y cron logrotate systemctl enable cron -echo "=== Prepare installer revision - ${INSTALLER_REVISION}) ===" -rm -rf /tmp/box && mkdir -p /tmp/box -curl "https://git.cloudron.io/cloudron/box/repository/archive.tar.gz?ref=${INSTALLER_REVISION}" | tar zxvf - --strip-components=1 -C /tmp/box -mkdir -p "${INSTALLER_SOURCE_DIR}" -cp -rf /tmp/box/installer/* "${INSTALLER_SOURCE_DIR}" && rm -rf /tmp/box -chown "${USER}:${USER}" -R "${INSTALLER_SOURCE_DIR}" -echo "${INSTALLER_REVISION}" > "${INSTALLER_SOURCE_DIR}/REVISION" - apt-get -y install acl # DO uses Google nameservers by default. This causes RBL queries to fail (host 2.0.0.127.zen.spamhaus.org) diff --git a/installer/README.md b/installer/README.md deleted file mode 100644 index 6d4774fa0..000000000 --- a/installer/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# Installer - -This subfolder contains all resources, which persist across a Cloudron update. -Only code and assets, which are part of the updater belong here. - -Installer is the name which got inherited from times, where this folder contained -much more infrastructure components, like a local webserver to facilitate updates. - - -## installer.sh - -The main entry point for initial provisioning and also updates (not upgrades). - -It is called from: - * cloudron-setup (during initial provisioning, restoring or upgrade) - * cloudron.js in the box code (during an update) - -Two arguments need to be supplied in this order: - 1. The public url to download the box release tarball `--sourcetarballurl` - 2. JSON object which contains the user-data `--data` - - -## cloudron-system-setup.sh - -This is the systemd unit file script hook, which persists Cloudron updates. -Mostly it revolves around setting up various parts of the filesystem, like btrfs -volumes and swap files diff --git a/scripts/cloudron-setup b/scripts/cloudron-setup index 284ae3c45..d27416780 100755 --- a/scripts/cloudron-setup +++ b/scripts/cloudron-setup @@ -8,9 +8,9 @@ if [[ ${EUID} -ne 0 ]]; then fi # change this to a hash when we make a upgrade release -readonly INSTALLER_REVISION="v0.92.1" +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 INSTALLER_URL="https://git.cloudron.io/cloudron/box/raw/${INSTALLER_REVISION}/scripts/installer.sh" readonly LOG_FILE="/var/log/cloudron-setup.log" domain="" @@ -101,12 +101,22 @@ if ! curl -s "${INIT_BASESYSTEM_SCRIPT_URL}" > /tmp/initializeBaseUbuntuImage.sh fi echo "=> Installing base dependencies ... (this takes some time)" -if ! /bin/bash /tmp/initializeBaseUbuntuImage.sh "${INSTALLER_REVISION}" "${provider}" &>> "${LOG_FILE}"; then +if ! /bin/bash /tmp/initializeBaseUbuntuImage.sh "${provider}" &>> "${LOG_FILE}"; then echo "Init script failed. See ${LOG_FILE} for details" exit 1 fi rm /tmp/initializeBaseUbuntuImage.sh +echo "=> Downloading and running installer for version ${INSTALLER_REVISION}" +if ! curl -s "${INSTALLER_URL}" > /etc/installer.sh; then + echo "Could not download initialization script" + exit 1 +fi +if ! /bin/bash /etc/installer.sh "${provider}" &>> "${LOG_FILE}"; then + echo "Installer failed. See ${LOG_FILE} for details" + exit 1 +fi + echo "=> Checking version" if ! npm install -g cloudron-version@0.1.1 &>> "${LOG_FILE}"; then echo "Failed to install cloudron-version npm package" diff --git a/installer/scripts/installer.sh b/scripts/installer.sh similarity index 100% rename from installer/scripts/installer.sh rename to scripts/installer.sh diff --git a/src/scripts/update.sh b/src/scripts/update.sh index 4e2a0f562..a500b264e 100755 --- a/src/scripts/update.sh +++ b/src/scripts/update.sh @@ -7,7 +7,7 @@ if [[ ${EUID} -ne 0 ]]; then exit 1 fi -readonly INSTALLER_SOURCE_DIR="/home/yellowtent/installer" +readonly INSTALLER_PATH="/etc/installer.sh" readonly UPDATER_SERVICE="cloudron-updater" readonly DATA_FILE="/tmp/cloudron-update-data.json" @@ -36,7 +36,7 @@ fi echo "${data}" > "${DATA_FILE}" echo "=> Run installer.sh as cloudron-updater.service" -if ! systemd-run --unit "${UPDATER_SERVICE}" ${INSTALLER_SOURCE_DIR}/scripts/installer.sh --sourcetarballurl "${sourceTarballUrl}" --data-file "${DATA_FILE}"; then +if ! systemd-run --unit "${UPDATER_SERVICE}" ${INSTALLER_PATH} --sourcetarballurl "${sourceTarballUrl}" --data-file "${DATA_FILE}"; then echo "Failed to install cloudron. See ${LOG_FILE} for details" exit 1 fi