diff --git a/functions b/functions index e4a2a06..13de446 100644 --- a/functions +++ b/functions @@ -185,9 +185,10 @@ function setup_docker() { ee_log_info1 "Installing Docker" # Check if docker exists. If not start docker installation. if ! command -v docker >/dev/null 2>&1; then - # Running standard docker installation. - wget --quiet get.docker.com -O docker-setup.sh - sh docker-setup.sh + # Download into TMP_WORK_DIR so setup.sh's EXIT trap cleans it up on any + # exit path, instead of leaving docker-setup.sh behind in the CWD. + wget --quiet get.docker.com -O "$TMP_WORK_DIR/docker-setup" + sh "$TMP_WORK_DIR/docker-setup" fi # Check if docker-compose exists. If not start docker-compose installation. diff --git a/setup.sh b/setup.sh index 805d19b..da79cad 100644 --- a/setup.sh +++ b/setup.sh @@ -18,6 +18,16 @@ TMP_WORK_DIR="$(mktemp -d /tmp/ee-installer.XXXXXX)" export TMP_WORK_DIR trap 'rm -rf "$TMP_WORK_DIR"' EXIT +# Remember this script's path so it can delete itself after a successful +# install (the `ee` from `wget -qO ee https://rt.cx/ee4 && bash ee`). Only when +# run directly: BASH_SOURCE[0] equals $0 when executed, differs when sourced +# (e.g. remote-migrate), and is empty when piped (`curl ... | bash`). Resolve +# to an absolute path so a later `cd` can't strand it. EE_KEEP_INSTALLER=1 opts out. +INSTALLER_SELF="" +if [ -z "${EE_KEEP_INSTALLER:-}" ] && [ "${BASH_SOURCE[0]:-}" = "$0" ] && [ -f "${BASH_SOURCE[0]}" ]; then + INSTALLER_SELF="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/$(basename -- "${BASH_SOURCE[0]}")" +fi + function bootstrap() { if ! command -v curl > /dev/null 2>&1; then packages="curl" @@ -80,3 +90,9 @@ function do_install() { # Invoking the main installation function. do_install + +# Reached only on success (set -e exits earlier on failure, leaving the file +# for a retry). Remove the downloaded installer so it doesn't linger. +if [ -n "$INSTALLER_SELF" ] && [ -f "$INSTALLER_SELF" ]; then + rm -f "$INSTALLER_SELF" || true +fi