#!/usr/bin/env bash # shellcheck disable=SC2162,SC2001,SC2139 FPREFIX="=====>" PREFIX="----->" INDENT=" " export SWARMLET_REPO=${SWARMLET_REPO:="https://github.com/swarmlet/swarmlet.git"} export SWARMLET_INSTALL_ROOT="/tmp/swarmlet" # Check if user is root if [[ $EUID -ne 0 ]]; then if [[ $(dpkg-query -s sudo) ]]; then echo "$PREFIX User is not root, using sudo" export SUDO="sudo" else echo "$PREFIX [ERROR] Please install sudo or run installer as root" && exit 1 fi fi # Check if Bash is up to date if [ "${BASH_VERSINFO:-0}" -lt 4 ]; then echo "$PREFIX [ERROR] Unmet requirements: Bash 4" echo "$INDENT Your Bash version is $BASH_VERSION" echo "$PREFIX Exiting with error code 1" 1>&2 exit 1 fi # Define package managers declare -A PKG_MANAGERS=( ["/etc/redhat-release"]=yum ["/etc/arch-release"]=pacman ["/etc/gentoo-release"]=emerge ["/etc/SuSE-release"]=zypp ["/etc/debian_version"]=apt-get ) # Select correct package manager for KEY in "${!PKG_MANAGERS[@]}"; do [[ -f $KEY ]] && export PKG_MANAGER="${PKG_MANAGERS[$KEY]}" done # Define default environment variables OPTS_CONFIRMED="true" declare -A DEFAULT_OPTS=( [INSTALLATION_TYPE]="interactive" # (default interactive, options: interactive|noninteractive) Use CLI wizard to setup Swarmlet [INSTALL_FROM]="git" # (default git, options: git|local) The install mode [SWARMLET_REPO]="$SWARMLET_REPO" # (default swarmlet github url) The default repo to install [SWARMLET_INSTALL_ROOT]="$SWARMLET_INSTALL_ROOT" # (default swarmlet install root) The default repo to install [INSTALL_BRANCH]="master" # (default master) The default branch to install [SWARMLET_USERNAME]="$USER" # (default $USER) Used for authentication with the registry and web services / dashboards [SWARMLET_PASSWORD]="swarmlet" # (default swarmlet) Used for authentication with the registry and web services / dashboards [SSH_AUTHORIZED_KEYS]="$HOME/.ssh/authorized_keys" # (default root) The authorized SSH keys for git deployments [NEW_HOSTNAME]="$HOSTNAME" # (default $HOSTNAME) Optional: set a new hostname [ROOT_DOMAIN]="" # (default undefined) The domain to use for deployment of included services [CREATE_SWAP]="false" # (default false) Allocate 1GB of swap space [INSTALL_ZSH]="true" # (default false) Install 'Oh My Zsh' [INSTALL_MODULES]="" # (default undefined, options: matomo|swarmpit|swarmprom|portainer) Seperate by space and wrap in quotes to install multiple modules [CA_SERVER]="production" # (default production, options: production|staging) The Let's Encrypt server to use [DEBUG]="" # (default undefined) TODO: Run installation in debug mode ) # Set default environment variables for KEY in "${!DEFAULT_OPTS[@]}"; do [[ -n "${DEFAULT_OPTS[$KEY]}" ]] && export "$KEY=${DEFAULT_OPTS[$KEY]}" done # Set environment variables from arguments if given shopt -s extglob while [[ "$#" -gt 0 ]]; do case "${1%=*}" in @($(echo "${!DEFAULT_OPTS[@]}" | sed 's/ /|/g'))) export "${1?}" shift ;; *) echo "Unknown argument: $1" OPTS_CONFIRMED="false" shift ;; esac done if [[ $OPTS_CONFIRMED == "false" ]]; then echo "$PREFIX Current environment:" for KEY in "${!DEFAULT_OPTS[@]}"; do printenv | grep "$KEY"; done [[ $INSTALLATION_TYPE == "noninteractive" ]] && echo "$PREFIX Exiting" && exit 1 read -p "$PREFIX Press enter to continue with this configuration"