-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: include partial install script inside a function.
- Loading branch information
Showing
1 changed file
with
49 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
# 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 "$@" |