#!/usr/bin/env bash # Configure the apparmor.d package # Copyright (C) 2021 Alexandre Pujol # SPDX-License-Identifier: GPL-2.0-only readonly ROOT=.build _die() { printf '%s\n' "$*" >&2 && exit 1; } _warning() { printf ' Warning: %s\n' "$*" >&2; } has_option() { local item option="$1"; for item in "${OPTIONS[@]}"; do [[ "$item" == "$option" ]] && return 0 done return 1 } # Displace files in the package sources # $@ List of files to displace _displace_files() { for path in "$@"; do mv "${ROOT:?}/$path" "${ROOT:?}/$path.apparmor.d" done } # Initialise a new clean apparmor.d build directory initialise() { rm -rf "${ROOT:?}" && rsync -a --exclude=.git . "$ROOT" } # Set the distribution specificities configure() { echo "Set the configuration for $DISTRIBUTION." echo " Ignore profiles in profiles.ignore." while read -r profile; do [[ "$profile" =~ ^\# ]] && continue if [[ "$profile" == */ ]]; then find "$ROOT/apparmor.d" -iname "${profile////}" -type d -exec rm -r {} \; else find "$ROOT/apparmor.d" -iname "$profile" -type f -exec rm {} \; fi done