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