2 # This file is part of the LibreOffice project.
3 # ------------------------------------------------------------------
5 # Copyright (C) 2016 Canonical Ltd.
7 # This Source Code Form is subject to the terms of the Mozilla Public
8 # License, v. 2.0. If a copy of the MPL was not distributed with this
9 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 # Author: Bryan Quigley <bryan.quigley@canonical.com>
13 # ------------------------------------------------------------------
15 # This is a simple script to help get AppArmor working on different distros
16 # Generally these apparmor profiles target the latest LibreOffice
18 INST_ROOT
=$1 #Where libreoffice program folder can be found
19 PROFILESFROM
=$2 #Where the profile files are
20 INSTALLTO
=$3 #Where should the apparmor profiles (For manual use should be /etc/apparmor.d)
21 RESTART
=$4 #Should we restart apparmor using service?
22 CHECK
=$5 #Check parsing of the new profile?
25 #Ubuntu 16.04 with stock LibreOffice:
26 # sudo ./sysui/desktop/share/apparmor.sh /usr/lib/libreoffice/ sysui/desktop/apparmor/ /etc/apparmor.d/ true true
28 #Ubuntu 16.04, with built debs from LibreOffice git
29 # sudo ./sysui/desktop/share/apparmor.sh /opt/libreofficedev5.2/ sysui/desktop/apparmor/ /etc/apparmor.d/ true true
31 #Ubuntu 16.04, running from git!
32 # sudo ./sysui/desktop/share/apparmor.sh /mnt/store/git/libo/instdir/ sysui/desktop/apparmor/ /etc/apparmor.d/ true true
34 #Need to convert / to . for profile names
35 INST_ROOT_FORMAT
=${INST_ROOT/\//}
36 INST_ROOT_FORMAT
=${INST_ROOT_FORMAT////.}
38 #Need to escape / for sed
39 INST_ROOT_SED
=${INST_ROOT////\\/}
41 for filename
in $PROFILESFROM/*
43 [[ -e $filename ]] ||
{ echo "No profile files found in ""$PROFILESFROM"; exit 1; }
44 tourl
=$INSTALLTO$INST_ROOT_FORMAT${filename##*/}
45 sed "s/INSTDIR-/$INST_ROOT_SED/g" "$filename" > "$tourl"
47 if [ "$CHECK" = "true" ]; then
48 # check profile parsing
49 echo "Checking $tourl profile."
50 /sbin
/apparmor_parser
--add --skip-cache --skip-kernel-load $tourl
54 if [ "$RESTART" = true
] ; then
55 echo "Restarting AppArmor"
56 service apparmor restart