build: include partial install script inside a function.

This commit is contained in:
Alexandre Pujol 2023-11-29 22:34:18 +00:00
parent 0c239e788a
commit e047da9000
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC

View file

@ -1,44 +1,49 @@
BUILD=.build #!/usr/bin/env bash
DESTDIR=/ # Partial install of apparmor profiles
# Copyright (C) 2023 monsieuremre <https://github.com/monsieuremre>
for profile in "$@" # Copyright (C) 2023 Alexandre Pujol <alexandre@pujol.io>
do # SPDX-License-Identifier: GPL-2.0-only
if [ ! -f "${BUILD}/apparmor.d/${profile}" ]; then
continue # Usage:
fi # make
echo "Installing profile $profile" # sudo make profile-names...
cp $BUILD/apparmor.d/$profile $DESTDIR/etc/apparmor.d/
grep "rPx," "${BUILD}/apparmor.d/${profile}" | while read line set -eu #-o pipefail
do
if [[ -z "$line" ]]; then readonly BUILD=.build
continue readonly DESTDIR="$1"
fi shift
dep=$(echo "$line" | awk '{print $1}')
dep=$(echo $dep | awk -F"/" '{print $NF}') _install() {
dep=$(eval "ls ${BUILD}/apparmor.d/${dep} 2>/dev/null") local profile="$1"
for i in $dep if [[ ! -f "$BUILD/apparmor.d/$profile" ]]; then
do return
i=$(echo $i | awk -F"/" '{print $NF}') fi
if [ ! -f "$DESTDIR/etc/apparmor.d/$i" ]; then if [[ -f "$DESTDIR/etc/apparmor.d/$profile" ]]; then
bash "$0" "$i" return
fi fi
done
done echo "Installing profile $profile"
grep "rPx -> " "${BUILD}/apparmor.d/${profile}" | while read line install -Dvm0644 "$BUILD/apparmor.d/$profile" "$DESTDIR/etc/apparmor.d/$profile"
do
if [[ -z "$line" ]]; then grep "rPx," "$BUILD/apparmor.d/$profile" | while read -r line; do
continue [[ -z "$line" ]] && continue
fi name="$(echo "$line" | awk '{print $1}')" # | awk -F"/" '{print $NF}')"
dep=${line%%#*} _install "$name"
dep=$(echo $dep | awk '{print $NF}') done
dep=${dep::-1} grep "rPx -> " "$BUILD/apparmor.d/$profile" | while read -r line; do
dep=$(eval "ls ${BUILD}/apparmor.d/${dep} 2>/dev/null") [[ -z "$line" ]] && continue
for i in $dep name=${line%%#*}
do name=$(echo "$name" | awk '{print $NF}')
i=$(echo $i | awk -F"/" '{print $NF}') name=${name::-1}
if [ ! -f "$DESTDIR/etc/apparmor.d/$i" ]; then _install "$name"
bash "$0" "$i" done
fi }
done
done main() {
done for profile in "$@"; do
_install "$profile"
done
}
main "$@"