build: include partial install script inside a function.
This commit is contained in:
parent
0c239e788a
commit
e047da9000
1 changed files with 49 additions and 44 deletions
|
|
@ -1,44 +1,49 @@
|
|||
BUILD=.build
|
||||
DESTDIR=/
|
||||
|
||||
for profile in "$@"
|
||||
do
|
||||
if [ ! -f "${BUILD}/apparmor.d/${profile}" ]; then
|
||||
continue
|
||||
fi
|
||||
echo "Installing profile $profile"
|
||||
cp $BUILD/apparmor.d/$profile $DESTDIR/etc/apparmor.d/
|
||||
grep "rPx," "${BUILD}/apparmor.d/${profile}" | while read line
|
||||
do
|
||||
if [[ -z "$line" ]]; then
|
||||
continue
|
||||
fi
|
||||
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 line
|
||||
do
|
||||
if [[ -z "$line" ]]; then
|
||||
continue
|
||||
fi
|
||||
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
|
||||
#!/usr/bin/env bash
|
||||
# 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
|
||||
|
||||
# Usage:
|
||||
# make
|
||||
# sudo make profile-names...
|
||||
|
||||
set -eu #-o pipefail
|
||||
|
||||
readonly BUILD=.build
|
||||
readonly DESTDIR="$1"
|
||||
shift
|
||||
|
||||
_install() {
|
||||
local profile="$1"
|
||||
if [[ ! -f "$BUILD/apparmor.d/$profile" ]]; then
|
||||
return
|
||||
fi
|
||||
if [[ -f "$DESTDIR/etc/apparmor.d/$profile" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
echo "Installing profile $profile"
|
||||
install -Dvm0644 "$BUILD/apparmor.d/$profile" "$DESTDIR/etc/apparmor.d/$profile"
|
||||
|
||||
grep "rPx," "$BUILD/apparmor.d/$profile" | while read -r line; do
|
||||
[[ -z "$line" ]] && continue
|
||||
name="$(echo "$line" | awk '{print $1}')" # | awk -F"/" '{print $NF}')"
|
||||
_install "$name"
|
||||
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
|
||||
}
|
||||
|
||||
main() {
|
||||
for profile in "$@"; do
|
||||
_install "$profile"
|
||||
done
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue