FreeTAKTeam/FreeTAKHub-Installation

Update `--check` Option Logic

phreed opened this issue · 0 comments

The --check option is broken.
wget -qO - bit.ly/freetakhub2 | sudo bash -s -- --check
The --check option does not do anything useful.

Desired behavior.

  • The --check-error will enables checking (if check fails the script fails with an error).
  • A --check-warn option disables checking (if check fails the script produces a warning but proceeds).

There are three check functions present:

  • check_root : checks to see if the process is being run with root permissions
  • check_os : checks to see if the current OS is a supported OS version
  • check_architecture : checks to see if the current hardware-platform is supported

Default settings:

  • check_root : disabled
  • check_os : error-enabled
  • check_architecture : disabled

What should the command line option/arguments look like?

ref:

  • usage:
    function usage() {
    cat <<USAGE_TEXT
    Usage: $(basename "${BASH_SOURCE[0]}") [<optional-arguments>]
    Install Free TAK Server and components.
    Available options:
    -h, --help Print help
    -v, --verbose Print script debug info
    -c, --check Check for compatibility issues while installing
    --core Install FreeTAKServer, UI, and Web Map
    --latest [DEFAULT] Install latest version (v$LATEST_FTS_VERSION)
    -s, --stable Install latest stable version (v$STABLE_FTS_VERSION)
    -l, --legacy Install legacy version (v$LEGACY_FTS_VERSION)
    --repo Replaces with specified ZT Installer repository [DEFAULT ${DEFAULT_REPO}]
    --branch Use specified ZT Installer repository branch [DEFAULT main]
    --dev-test Sets TEST Envar to 1
    --dry-run Sets up dependencies but exits before running any playbooks
    --ip-addr Explicitly set IP address (when http://ifconfig.me/ip is wrong)
    USAGE_TEXT
    exit
    }
  • check_os
    # do_checks
  • do_checks :
    ###############################################################################
    # Do checks or skip unnecessary ones if non-interactive
    ###############################################################################
    function do_checks() {
    check_root
    if [[ -n "${CHECK-}" ]]; then
    check_os
    # check_architecture
    else
    WEBMAP_FORCE_INSTALL="webmap_force_install=true"
    fi
    if [[ -n "${TEST-}" ]]; then
    REPO="https://github.com/janseptaugust/FreeTAKHub-Installation.git"
    fi
    }
  • check_os :
    function check_os() {
    which apt-get >/dev/null
    if [[ $? -ne 0 ]]; then
    die "Could not locate apt... this installation method will not work"
    fi
    echo -e -n "${BLUE}Checking for supported OS...${NOFORMAT}"
    # freedesktop.org and systemd
    if [[ -f /etc/os-release ]]; then
    . /etc/os-release
    OS=${NAME:-unknown}
    VER=${VERSION_ID:-unknown}
    CODENAME=${VERSION_CODENAME}
    # linuxbase.org
    elif type lsb_release >/dev/null 2>&1; then
    OS=$(lsb_release -si)
    VER=$(lsb_release -sr)
    # for some Debian-based distros
    elif [[ -f /etc/lsb-release ]]; then
    . /etc/lsb-release
    OS=${DISTRIB_ID}
    VER=${DISTRIB_RELEASE}
    # older Debian-based distros
    elif [[ -f /etc/debian_version ]]; then
    OS=Debian
    VER=$(cat /etc/debian_version)
    # fallback
    else
    OS=$(uname -s)
    VER=$(uname -r)
    fi
    # check for supported OS and version and warn if not supported
    if [[ "${OS}" != "${OS_REQD}" ]] || [[ "${VER}" != "${OS_VER_REQD}" ]]; then
    echo -e "${YELLOW}WARNING${NOFORMAT}"
    echo "FreeTAKServer has only been tested on ${GREEN}${OS_REQD} ${OS_VER_REQD}${NOFORMAT}."
    echo -e "This machine is currently running: ${YELLOW}${OS} ${VER}${NOFORMAT}"
    echo "Errors may arise during installation or execution."
    read -r -e -p "Do you want to continue? [y/n]: " PROCEED
    # Default answer is "n" for NO.
    DEFAULT="n"
    # Set user-inputted value and apply default if user input is null.
    PROCEED="${PROCEED:-${DEFAULT}}"
    # Check user input to proceed or not.
    if [[ "${PROCEED}" != "y" ]]; then
    die "Answer was not y. Not proceeding."
    else
    echo -e "${GREEN}Proceeding...${NOFORMAT}"
    fi
    else
    echo -e "${GREEN}Success!${NOFORMAT}"
    echo -e "This machine is currently running: ${GREEN}${OS} ${VER}${NOFORMAT}"
    echo -e "Selected install type is: ${GREEN}${DEFAULT_INSTALL_TYPE}"
    fi
    }
  • check_root :
    function check_root() {
    echo -e -n "${BLUE}Checking if this script is running as root...${NOFORMAT}"
    # check Effective User ID (EUID) for root user, which has an EUID of 0.
    if [[ "$EUID" -ne 0 ]]; then
    echo -e "${RED}ERROR${NOFORMAT}"
    die "This script requires running as root. Use sudo before the command."
    else
    echo -e "${GREEN}Success!${NOFORMAT}"
    fi
    }
  • check_architecture :
    function check_architecture() {
    echo -e -n "${BLUE}Checking for supported architecture...${NOFORMAT}"
    # check for non-Intel-based architecture here
    arch=$(uname --hardware-platform) # uname is non-portable, but we only target Ubuntu 20.04/22.04
    if ! grep --ignore-case x86 <<<"${arch}" >/dev/null; then
    echo -e "${YELLOW}WARNING${NOFORMAT}"
    echo "Possible non-Intel architecture detected, ${name}"
    echo "Non-intel architectures may cause problems. The web map might not install."
    read -r -e -p "Do you want to force web map installation? [y/n]: " USER_INPUT
    # Default answer is "n" for NO.
    DEFAULT="n"
    # Set user-inputted value and apply default if user input is null.
    FORCE_WEBMAP_INSTALL_INPUT="${USER_INPUT:-${DEFAULT}}"
    # Check user input to force install web map or not
    if [[ "${FORCE_WEBMAP_INSTALL_INPUT}" != "y" ]]; then
    echo -e "${YELLOW}WARNING${NOFORMAT}: installer may skip web map installation."
    else
    WEBMAP_FORCE_INSTALL="webmap_force_install=true"
    echo -e "${YELLOW}WARNING${NOFORMAT}: forcing web map installation!"
    fi
    else # good architecture to install webmap
    echo -e "${GREEN}Success!${NOFORMAT}"
    echo "Intel architecture detected, ${name}"
    fi
    }