#!/usr/bin/env bash # Copyright © 2025 Wandelbots GmbH, Dresden # All rights reserved. # shellcheck disable=SC2317 set -e # Variables (base information) WB_BASE_URL="https://get.wandelbots.io" WB_INSTALLER_MANIFEST_TARGET="/etc/wandelbots/manifest.yaml" # Variables (Customization installer) WB_INSTALLER_PATH="${WB_BASE_URL}" WB_INSTALLER_EXECUTABLE_PATH="/usr/local/bin/wb-install" WB_INSTALLER_COLLECTION_PATH="${WB_INSTALLER_COLLECTION_PATH:-${WB_BASE_URL}/wandelbots-core-latest.tar.gz}" # Variables (colors) COL_BOLD='\033[1;0m' COL_INFO='\033[0;32m' COL_WARN='\033[0;33m' COL_CRIT='\033[0;31m' COL_NULL='\033[0;0m' # Functions (helpers) show_banner() { echo -e "${COL_BOLD}###############################################################################${COL_NULL}" echo -e "${COL_BOLD}# ${*} ${COL_NULL}" echo -e "${COL_BOLD}###############################################################################${COL_NULL}" } show_info() { echo -e "${COL_INFO}### INFO: ${*}${COL_NULL}" } # shellcheck disable=SC2329 show_warn() { echo -e "${COL_WARN}### WARN: ${*}${COL_NULL}" 1>&2; } show_crit() { echo -e "${COL_CRIT}### ERROR: ${*}${COL_NULL}" 1>&2; exit 1 } show_help() { cat << EOHELP ######################### Wandelbots Nova Installer ############################ Usage (local): [ENV=value] wb-install [OPTION]... Usage (web): curl URL | [ENV=value] bash - Installs the wandelbots software suite. Options: -h Show help -p Persist the installer script -v Run in verbose mode Environment Variables: This help provides only some common environement variables. Please consult the documentation to get an overview about all of them. Variable Default Description -------------------------- --------- ------------------------------------ WB_INSTALLER_MANIFEST_PATH UNDEFINED Provide a custom installer manifest. WB_INSTALL_ENV prod Define the desired environment. WB_SYSTEM_UPDATE_ENABLED false Wether updates should be done. WB_SYSTEM_FIREWALL_ENABLED true Wether firewalld should be enabled. WB_COCKPIT_ENABLED true Enable Cockpit Web interface. WB_PCP_ENABLED true Enable Performance Co-Pilot. WB_KIOSK_MODE_ENABLED true Enable Kiosk Mode. WB_TOUCHSCREEN_ENABLED false Enable touchscreen support, including an on-screen keyboard. WB_NETBIRD_ENABLED false Install netbird VPN client. WB_HOTSPOT_ENABLED false Configure a WiFi access point. WB_WIREGUARD_ENABLED false Install wireguard VPN client. WB_KUBERNETES_ENABLED true Install Kubernetes (k3s). Further help: Documentation: https://wandelos.pages.code.wabo.run/installer/ EOHELP } # Functions (main) check_os() { show_info "Checking operating system:" release_file=/etc/redhat-release if [ ! -r "${release_file}" ] then show_crit "Could not determine operating system." fi if ! grep -E 'AlmaLinux release [89]\.' "${release_file}" > /dev/null then show_crit "Operating system not supported." fi return 0 } check_root() { show_info "Checking user" unset SUDO if [ "$EUID" -ne 0 ] then SUDO="sudo" show_info "Running as user - will use sudo for all commands." fi return 0 } install_dependencies() { show_info "Installing required dependencies." ${SUDO} dnf install -y ansible-core curl return 0 } install_collection() { show_info "Installing wandelbots.core." ${SUDO} ansible-galaxy collection install --force "${WB_INSTALLER_COLLECTION_PATH}" return 0 } fail_on_wb_env() { if [ "$(env | grep -v WB_INSTALLER_ | grep -c WB_)" -gt 0 ] then show_crit "Mixing environment variables and custom manifest." \ "Edit the manifest and use it exclusively!" fi } prepare_manifest() { if [ ! -d /etc/wandelbots ] ; then ${SUDO} mkdir -p /etc/wandelbots/ fi if [ -n "${WB_INSTALLER_MANIFEST_PATH}" ] then show_info "Using custom manifest ${WB_INSTALLER_MANIFEST_PATH}" if [[ "${WB_INSTALLER_MANIFEST_PATH}" == https://* ]] then ${SUDO} curl -fL \ "${WB_INSTALLER_MANIFEST_PATH}" \ -o "${WB_INSTALLER_MANIFEST_TARGET}" else ${SUDO} cp -f \ "${WB_INSTALLER_MANIFEST_PATH}" \ "${WB_INSTALLER_MANIFEST_TARGET}" fi fail_on_wb_env elif [ -f "${WB_INSTALLER_MANIFEST_TARGET}" ] then show_info "Using manifest ${WB_INSTALLER_MANIFEST_TARGET}" fail_on_wb_env elif [ "$(env | grep -v WB_INSTALLER_ | grep -c WB_)" -gt 0 ] then show_info "Using ENV variables. Custom manifest will be overwritten!" # Reading all env and writing a manifest rm -f "${WB_INSTALLER_MANIFEST_TARGET}" while IFS='=' read -r key value; do if [[ "$key" == WB_* ]] && [[ ! "$key" == WB_INSTALLER_* ]]; then printf '%s: %s\n' "${key,,}" "$value" \ | ${SUDO} tee -a ${WB_INSTALLER_MANIFEST_TARGET} >/dev/null fi done < <(env) show_info "Wrote $(wc -l <"${WB_INSTALLER_MANIFEST_TARGET}") configuration" \ "entries to ${WB_INSTALLER_MANIFEST_TARGET}." else show_info "Using defaults from wandelbots.core." fi playbook_options=( -i "localhost," -c "local" ) if [ -f "${WB_INSTALLER_MANIFEST_TARGET}" ]; then playbook_options+=(-e "manifest=${WB_INSTALLER_MANIFEST_TARGET}") fi } execute_playbook() { ${SUDO} ansible-playbook "${playbook_options[@]}" wandelbots.core.install } start_device_registration() { ${SUDO} ansible-playbook "${playbook_options[@]}" wandelbots.core.registration_code } persist_installer() { show_info "Persisting installer from remote" ${SUDO} curl -sfL "${WB_INSTALLER_PATH}" -o "${WB_INSTALLER_EXECUTABLE_PATH}" ${SUDO} chmod 755 "${WB_INSTALLER_EXECUTABLE_PATH}" } reboot_required() { if hash needs-restarting 2>/dev/null; then if needs-restarting -r >/dev/null; then # success means no reboot is required return 1 fi else show_warn "Could not determine if a reboot is necessary." \ "Maybe reboot just to be safe?!" fi } # Main while getopts "hpv" OPT; do case "${OPT}" in h) show_help exit 0 ;; p) persist_installer ;; v) set -x ;; *) show_help show_crit "Option not supported!" ;; esac done show_banner "Wandelbots Nova Installer" check_root check_os install_dependencies install_collection prepare_manifest show_info "Executing wandelbots.core.registration_code" set -o pipefail if start_device_registration | ${SUDO} tee /var/log/nova-registration.log >/dev/null ; then if [ -f "/tmp/wb-device-registration.txt" ]; then cat "/tmp/wb-device-registration.txt" echo # read from /dev/tty instead of stdin to allow piping read -r -p "Press any key to continue..." -s -t 900 -n 1