3
# Copyright (C) 2010 Canonical, Ltd.
4
# Author: Jamie Strandboge <jamie@canonical.com>
7
# Program for updating browser abstractions in Ubuntu. The program will
8
# search the specified profile for an include directive for a file in
9
# abstractions/ubuntu-browsers.d and update this file with the specified
10
# browsers abstractions.
14
topdir="/etc/apparmor.d"
15
reldir="abstractions/ubuntu-browsers.d"
18
if [ ! -d "$dir" ]; then
19
echo "'$dir' is not a directory" >&2
27
Usage: `basename $0` [OPTIONS] <profile>
28
-u comma separated list of abstractions for profile to use
29
-d dry-run. Only show what would be done.
30
-l list available abstractions
34
$ aa-update-browser -l
35
# aa-update-browser -u multimedia,productivity /etc/apparmor.d/usr.bin.firefox
39
find_browser_include() {
41
r=`egrep " *#include <$reldir/.*> *(|#.*)" "$fn" | cut -f 2 -d '<' | cut -f 1 -d '>'`
43
echo "Could not find '#include <$reldir/...>' in" >&2
50
existing_abstractions=""
52
if [ ! -s "$i" ]; then
56
if head -1 "$i" | grep -q '^# This file is updated' ; then
60
# This has a leading space, which we use below.
61
existing_abstractions="$existing_abstractions `basename $i`"
66
while getopts "dhlu:" opt
70
u) updated="$OPTARG";;
72
echo "$existing_abstractions"
85
shift $(($OPTIND - 1))
93
if [ ! -s "$p" ]; then
94
echo "Could not find '$p'" >&2
98
include=`find_browser_include $p`
99
if [ -z "$include" ]; then
103
if echo "$existing_abstractions" | grep -q " $include" ; then
104
echo "'$reldir/$include' is an existing abstraction" >&2
109
plugins_common_path="$dir/plugins-common"
111
# This file is updated by '`basename $0`' and may be overwritten on
114
# For site-specific adjustments, please see /etc/apparmor.d/local/<binary>
117
for a in `echo "$updated" | tr [,] ' '`; do
118
echo "$existing_abstractions" | egrep -q " $a( |$)" || {
119
echo "'$a' is not an existing abstraction. Skipping." >&2
122
if [ -f "$dir/$a" ]; then
123
# TODO: add $plugins_common_path only for those browser abstractions
124
# that actually need it.
125
if [ -n "$plugins_common_path" ] && [ -e "$plugins_common_path" ]; then
126
echo "#include <$reldir/`basename $plugins_common_path`>" >> "$tmp"
127
plugins_common_path=""
129
echo "#include <$reldir/$a>" >> "$tmp"
131
echo "Skipping '$a' (not found in '$dir')" >&2
136
if [ "$dryrun" = "yes" ]; then
137
echo "Skipping commit to '$dir/$include' (dry run)" >&2
142
mv -f "$tmp" "$dir/$include" || {
146
chmod 644 "$dir/$include"