Skip to content

Commit

Permalink
build: include partial install script inside a function.
Browse files Browse the repository at this point in the history
  • Loading branch information
roddhjav committed Nov 29, 2023
1 parent 0c239e7 commit e047da9
Showing 1 changed file with 49 additions and 44 deletions.
93 changes: 49 additions & 44 deletions dists/partial.sh
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 "$@"

0 comments on commit e047da9

Please sign in to comment.