summaryrefslogtreecommitdiff
path: root/sysui/desktop/share/apparmor.sh
blob: 848c113f61f8de54571aa6fc1e65d0148671c8b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# This file is part of the LibreOffice project.
# ------------------------------------------------------------------
#
#    Copyright (C) 2015 Canonical Ltd.
#
#    This Source Code Form is subject to the terms of the Mozilla Public
#    License, v. 2.0. If a copy of the MPL was not distributed with this
#    file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#    Author: Bryan Quigley <bryan.quigley@canonical.com>
#
# ------------------------------------------------------------------

# This is a simple script to help get AppArmor working on different distros

INST_ROOT=$1  #Where libreoffice program folder can be found
PROFILESFROM=$2  #Where the profile files are
INSTALLTO=$3  #Where should the apparmor profiles live (to be be linked to)
INSTALL=$4  #True means try to run sudo to link (doesn't reload profiles)

#For example to get this to work on Ubuntu 15.04 with stock LibreOffice:
# ./sysui/desktop/share/apparmor.sh /usr/lib/libreoffice/ sysui/desktop/apparmor/ /mnt/store/git/libo/instdir/apparmor-testing/ true

mkdir -p $INSTALLTO

#Need to convert / to . for profile names
INST_ROOT_FORMAT=${INST_ROOT/\//}
INST_ROOT_FORMAT=${INST_ROOT_FORMAT////.}

#Need to escale / for sed
INST_ROOT_SED=${INST_ROOT////\\/}

for filename in `ls $PROFILESFROM`
do
    tourl=$INSTALLTO$INST_ROOT_FORMAT$filename
    cat $PROFILESFROM$filename | sed "s/INSTDIR-/$INST_ROOT_SED/g" > $tourl

    if [ "$INSTALL" = true ] ; then
        sudo rm /etc/apparmor.d/$INST_ROOT_FORMAT$filename
        sudo ln -s $tourl /etc/apparmor.d/$INST_ROOT_FORMAT$filename
    fi

done