#!/usr/bin/bash
set -Eeuo pipefail

if (( $# != 1 )); then
    exit 2
fi

matrix_path=$1
case "$matrix_path" in
    /sys/devices/*/mount_matrix) ;;
    *) exit 2 ;;
esac

IFS= read -r matrix < "$matrix_path"
component='-?(0|1)'
if [[ ! $matrix =~ ^${component},\ ${component},\ ${component}\;\ ${component},\ ${component},\ ${component}\;\ ${component},\ ${component},\ ${component}$ ]]; then
    exit 3
fi

printf 'ACCEL_MOUNT_MATRIX=%s\n' "$matrix"
