#!/bin/bash
# Copyright (c) 2000-2018 Synology Inc. All rights reserved.


## Always install in each platform
echo 'Install basic configuration ...'
install -Dm644 synology/apparmor.service ${TmpInstDir}/lib/systemd/system/apparmor.service

if ! SupportAppArmorPlatform; then
	# NOT support apparmor
    exit 0
fi
echo 'Install remain configuration ...'
install -Dm755 utils/aa-status           ${TmpInstDir}/usr/sbin/aa-status
install -Dm644 parser/subdomain.conf     ${TmpInstDir}/etc/apparmor/subdomain.conf
install -Dm755 synology/apparmor.sh      ${TmpInstDir}/usr/syno/etc/rc.sysv/apparmor.sh
install -Dm644 synology/apparmor.service ${TmpInstDir}/lib/systemd/system/apparmor.service

[ -d ${TmpInstDir}/lib/systemd/system/sysinit.target.wants ] || install -d ${TmpInstDir}/lib/systemd/system/sysinit.target.wants
ln -s ../apparmor.service ${TmpInstDir}/lib/systemd/system/sysinit.target.wants

echo 'Install parser ...'
mkdir -p ${TmpInstDir}/usr/bin
make install -C parser								\
	DESTDIR=${TmpInstDir}/usr						\
	CC=${CC}										\
	CXX=${CXX}										\
	USE_SYSTEM=1									\
	CFLAGS="${CFLAGS} -DSYNO_APPARMOR_PATCH" 		\
	${MAKE_FLAGS}
rm -rf ${TmpInstDir}/usr/{include,share,usr,lib,var}


if [ "x$NOSTRIP" != "xNOSTRIP" ]; then
	find ${TmpInstDir}/usr/sbin -type f | while read file
	do
		if [ -n "`file "${file}" | grep -i elf`" ]; then
			${STRIP} "${file}";
		fi
	done
fi
