#!/bin/bash # # Purpose : Run one smoketest scenario inside the container (smoketest/run # starts this). 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. A desktop session's D-Bus and an unlocked keyring are # started first, as COSMIC starts them at login. CONNECTOR="$HOME/connector" CONF_DIR="$HOME/.config/federated-connector" export CONNECTOR CONF_DIR RED=$'\033[31m' GREEN=$'\033[32m' YELLOW=$'\033[33m' RESET=$'\033[0m' FAILURES=0 # configure's questions, answered yes confirm() { echo "$1 [y/N] y"; return 0; } confirm_yes() { echo "$1 [Y/n] y"; return 0; } # 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" } step() { echo "-- $*" } # The session D-Bus and keyring export XDG_RUNTIME_DIR="/tmp/runtime-$UID" mkdir -p -m 700 "$XDG_RUNTIME_DIR" eval "$(dbus-launch --sh-syntax)" echo -n smoketest | gnome-keyring-daemon --unlock --components=secrets > /dev/null export PATH="$HOME/.local/bin:$PATH" cd "$HOME" || exit 1 source "$CONNECTOR/configure.d/lib/packages.sh" source "$CONNECTOR/configure.d/lib/agents.sh" # shellcheck disable=SC1090 source "$1" || { echo "Couldn't read $1"; exit 1; } echo "$DESCRIPTION" echo "($(. /etc/os-release && echo "$PRETTY_NAME"), $(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