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