| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | set -eu -o pipefail |
| 7 | |
| 8 | scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 9 | |
| 10 | source "${scriptdir}/common.inc.sh" |
| 11 | |
| 12 | if [ "$#" -ne 1 ]; then |
| 13 | ERROR "Usage: $0 NAME" |
| 14 | exit 1 |
| 15 | fi |
| 16 | |
| 17 | NAME="$1" |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | INFO "Testing secontext is set for rosetta" |
| 33 | expected="context=system_u:object_r:bin_t:s0" |
| 34 | |
| 35 | if [[ "$(uname)" == "Darwin" && "$(arch)" == "arm64" ]]; then |
| 36 | INFO "Testing secontext is set for rosetta mounts" |
| 37 | got=$(limactl shell "$NAME" mount | grep "rosetta" | awk '{print $6}') |
| 38 | INFO "secontext rosetta: expected=${expected}, got=${got}" |
| 39 | if [[ $got != *$expected* ]]; then |
| 40 | ERROR "secontext for rosetta mount is not set or Invalid" |
| 41 | exit 1 |
| 42 | fi |
| 43 | fi |
| 44 | INFO "Testing secontext is set for bind mounts" |
| 45 | expected="context=system_u:object_r:nfs_t:s0" |
| 46 | INFO "Checking in mounts" |
| 47 | got=$(limactl shell "$NAME" mount | grep "$HOME" | awk '{print $6}') |
| 48 | INFO "secontext ${HOME}: expected=${expected}, got=${got}" |
| 49 | if [[ $got != *$expected* ]]; then |
| 50 | ERROR "secontext for \"$HOME\" dir is not set or Invalid" |
| 51 | exit 1 |
| 52 | fi |
| 53 | got=$(limactl shell "$NAME" mount | grep "/tmp/lima" | awk '{print $6}') |
| 54 | INFO "secontext /tmp/lima: expected=${expected}, got=${got}" |
| 55 | if [[ $got != *$expected* ]]; then |
| 56 | ERROR 'secontext for "/tmp/lima" dir is not set or Invalid' |
| 57 | exit 1 |
| 58 | fi |
| 59 | INFO "Checking in fstab file" |
| 60 | expected='context="system_u:object_r:nfs_t:s0"' |
| 61 | got=$(limactl shell "$NAME" cat /etc/fstab | grep "$HOME" | awk '{print $4}') |
| 62 | INFO "secontext ${HOME}: expected=${expected}, got=${got}" |
| 63 | if [[ $got != *$expected* ]]; then |
| 64 | ERROR "secontext for \"$HOME\" dir is not set or Invalid" |
| 65 | exit 1 |
| 66 | fi |
| 67 | got=$(limactl shell "$NAME" cat /etc/fstab | grep "/tmp/lima" | awk '{print $4}') |
| 68 | INFO "secontext /tmp/lima: expected=${expected}, got=${got}" |
| 69 | if [[ $got != *$expected* ]]; then |
| 70 | ERROR 'secontext for "/tmp/lima" dir is not set or Invalid' |
| 71 | exit 1 |
| 72 | fi |