1#!/usr/bin/env bash
2# SPDX-License-Identifier: LGPL-2.1-or-later
3set -e
4
5TEST_DESCRIPTION="shutdown testing"
6IMAGE_NAME="shutdown"
7TEST_NO_QEMU=1
8
9# shellcheck source=test/test-functions
10. "${TEST_BASE_DIR:?}/test-functions"
11
12_ORIG_NSPAWN="${SYSTEMD_NSPAWN:?}"
13SYSTEMD_NSPAWN="${STATEDIR:?}/run-nspawn"
14
15setup_nspawn_root_hook() {
16    cat >"${STATEDIR:?}/run-nspawn" <<EOF
17#!/bin/bash
18exec "${TEST_BASE_DIR:?}/test-shutdown.py" -v -- "$_ORIG_NSPAWN" "\$@"
19exit 1
20EOF
21    chmod 755 "${STATEDIR:?}"/run-nspawn
22}
23
24test_append_files() {
25    local workspace="${1:?}"
26    # prevent shutdown in test suite, the expect script does that manually.
27    mkdir -p "${workspace:?}/etc/systemd/system/end.service.d"
28    cat >"$workspace/etc/systemd/system/end.service.d/99-override.conf" <<EOF
29[Service]
30ExecStart=
31ExecStart=/bin/true
32EOF
33    inst /usr/bin/screen
34    echo "PS1='screen\$WINDOW # '" >>"$workspace/root/.bashrc"
35    echo 'startup_message off' >"$workspace/etc/screenrc"
36    echo 'bell_msg ""' >>"$workspace/etc/screenrc"
37}
38
39do_test "$@"
40