#!/usr/bin/env bash if [[ "${EUID}" -ne 0 ]]; then echo "This script must be run as root." >&2; exit 1; fi ############################################################################### step_current="0"; step_max="1"; ############################################################################### ### # Load the lantern build engine ### # Make sure the current directory is the location of this script to simplify matters cd "$(dirname "$(readlink -f "$0")")" || { echo "Error: Failed to cd to script directory" >&2; exit 1; }; lantern_path="lib/lantern-build-engine/"; # Check out the lantern git submodule if needed if [ ! -f "${lantern_path}/lantern.sh" ]; then git submodule update --init "${lantern_path}"; fi #shellcheck disable=SC1090 source "${lantern_path}/lantern.sh"; #shellcheck disable=SC1090 source "/etc/os-release"; ############################################################################### ############################################################################### ask_yesno() { local question="$1"; whiptail --title "Step ${step_current} / ${step_max}" --yesno "${question}" 40 8; return "$?"; # Not actually needed, but best to be explicit } queue_postinstall_step() { local stepname="$1"; echo "${stepname}" >>"${temp_dir}/steps-postinstall.txt"; } queue_preinstall_step() { local stepname="$1"; echo "${stepname}" >>"${temp_dir}/steps-preinstall.txt"; } queue_apt_install() { for package_name in "$@"; do subtask_begin "[apt] Queueing install of ${package_name}"; echo "${package_name}" >>"${temp_dir}/apt-packages.txt"; subtask_end "$?"; done } queue_firewall_rule() { local rule="$*"; subtask_begin "[firewall] Queuing firewall rule ${rule}"; echo "${rule}" >>"${temp_dir}/ufw-rules.txt"; subtask_end "$?"; } ############################################################################### # ███████ ████████ ███████ ██████ ██████ # ██ ██ ██ ██ ██ ██ ████ # ███████ ██ █████ ██████ ██ ██ ██ # ██ ██ ██ ██ ████ ██ # ███████ ██ ███████ ██ ██████ stage_begin "Preparing to provision host"; task_begin "Creating temporary directory"; temp_dir="$(mktemp --tmpdir -d "sbrl-provisioning-XXXXXXX")"; on_exit() { task_begin "Cleaning up"; rm -rf "${temp_dir}"; } trap on_exit EXIT; task_end "$?"; task_begin "Setting initial state"; cat apt-packages.txt >"${temp_dir}/apt-packages.txt"; queue_preinstall_step "10-apt-update.sh"; queue_preinstall_step "15-ufw.sh"; queue_postinstall_step "100-ssh-cluster-config.sh"; task_end "$?"; stage_end "$?"; ############################################################################### # ███████ ████████ ███████ ██████ ██ # ██ ██ ██ ██ ██ ███ # ███████ ██ █████ ██████ ██ # ██ ██ ██ ██ ██ # ███████ ██ ███████ ██ ██ step_current="1"; stage_begin "Configuring software choices"; # TODO: hostname if ask_yesno "Use apt cache?"; then source ./steps-config/10-apt-cache.sh; fi if ask_yesno "Install Docker?"; then source ./steps-config/10-docker.sh; fi ### # Autonomous config tasks ### source ./steps-config/50-avahi-daemon.sh stage_end "$?"; ############################################################################### ### # Pre-install tasks ### stage_begin "Executing pre-install tasks"; while read -r preinstall_step; do #shellcheck disable=SC1090 source "steps-preinstall/${preinstall_step}"; done < <(cat "${temp_dir}/steps-preinstall.txt"); stage_end "$?" "1 or more pre-install tasks failed"; ############################################################################### ### # Install packages ### stage_begin "Installing apt packages"; apt-get install --no-install-recommends --yes "$(cat "${temp_dir}/apt-packages.txt")"; stage_end "$?" "Failed to install apt packages"; ############################################################################### ### # Post-install tasks ### stage_begin "Running post-install tasks"; while read -r postinstall_step; do #shellcheck disable=SC1090 source "steps-postinstall/${postinstall_step}"; done < <(cat "${temp_dir}/steps-postinstall.txt"); stage_begin "$?" "Failed to run 1 or more post-install tasks"; ############################################################################### ### # Final steps ### source "steps-last/15-ufw.sh"; echo " ██████ ██████ ██████ ██ ██ ██ ███████ ██ ██████ ███ ██ ██ ███ ██ ██████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ████ ██ ██ ██████ ██████ ██ ██ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██████ ████ ██ ███████ ██ ██████ ██ ████ ██ ██ ████ ██████ ██████ ██████ ███ ███ ██████ ██ ███████ ████████ ███████ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██████ ██ █████ ██ █████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██████ ██████ ██ ██ ██ ███████ ███████ ██ ███████ ██ This host is now ready for use. ";