#!/bin/bash # # Purpose : Run one smoketest scenario inside the VM (smoketest/run starts # this in the desktop session). Prints ok, FAIL or skip for each # check, and exits 1 if any failed. # # Usage: runner.sh # # A scenario sets DESCRIPTION and TIER and defines `scenario`, which calls the # checks below. It runs with what configure gives items (CONNECTOR, CONF_DIR, # confirm...), answering yes to every question, so it can source items and # call their functions. CONNECTOR="$HOME/connector" CONF_DIR="$HOME/Library/Application Support/Federated Connector" COMPUTER="$(scutil --get ComputerName 2> /dev/null || hostname -s)" RED=$'\033[31m' GREEN=$'\033[32m' YELLOW=$'\033[33m' BOLD=$'\033[1m' RESET=$'\033[0m' export PATH="/usr/bin:/bin:/usr/sbin:/sbin" export TMPDIR="${TMPDIR:-$(getconf DARWIN_USER_TEMP_DIR)}" FAILURES=0 # configure's questions, answered yes; ask takes the default confirm() { echo "$1 [y/N] y"; return 0; } confirm_yes() { echo "$1 [Y/n] y"; return 0; } ask() { printf -v "$1" '%s' "$3"; } # wait_until without reading stdin: try every 2 seconds for up to $1 wait_until() { local seconds="$1" waited=0 shift while [ "$waited" -lt "$seconds" ]; do "$@" && return 0 sleep 2 waited=$((waited + 2)) done "$@" } # check : ok if the command succeeds check() { local description="$1" output shift if output="$("$@" 2>&1)"; then echo "${GREEN}ok$RESET $description" else echo "${RED}FAIL$RESET $description" [ -n "$output" ] && printf '%s\n' "$output" | tail -n 15 | sed 's/^/ /' FAILURES=$((FAILURES + 1)) fi } # check_not : ok if the command fails check_not() { local description="$1" shift if "$@" > /dev/null 2>&1; then echo "${RED}FAIL$RESET $description (it succeeded)" FAILURES=$((FAILURES + 1)) else echo "${GREEN}ok$RESET $description" fi } # check_eq check_eq() { if [ "$2" = "$3" ]; then echo "${GREEN}ok$RESET $1" else echo "${RED}FAIL$RESET $1" echo " expected: $2" echo " got: $3" FAILURES=$((FAILURES + 1)) fi } skip() { echo "${YELLOW}skip$RESET $1" } # A step whose output is worth seeing, run as it is step() { echo "-- $*" } # The VM's login keychain is open in the desktop session; ssh's wouldn't be security unlock-keychain -p admin "$HOME/Library/Keychains/login.keychain-db" 2> /dev/null cd "$HOME" || exit 1 # shellcheck disable=SC1090 source "$1" || { echo "Couldn't read $1"; exit 1; } echo "$DESCRIPTION" echo "(macOS $(sw_vers -productVersion), $(uname -m))" scenario echo if [ $FAILURES -eq 0 ]; then echo "${GREEN}All checks passed.$RESET" else echo "${RED}$FAILURES check(s) failed.$RESET" exit 1 fi