4b7fa1e4bac4be6b6761ab89fd18199503c02811
[packages/browser-plugins.git] / browser-plugins-update.sh
1 #!/bin/sh
2 # Author: Elan Ruusam√§e <glen@pld-linux.org>
3 # Date: 2006-09-13
4 # See more browser-plugins.README
5
6 # TODO
7 # - implement blacklist.d/anyfile-browser.arch.blacklist support
8 # - check not to link amd64 plugins to opera.i386 dir
9
10 sysconfdir='/etc/browser-plugins'
11 browsersdir="$sysconfdir/browsers.d"
12 blacklistdir="$sysconfdir/blacklist.d"
13 plugindirs='/usr/lib/browser-plugins /usr/lib64/browser-plugins'
14
15 # bool in_blacklist(char *blacklistfile, char *pluginfile)
16 # returns true if pluginfile is listed in blacklistfile 
17 in_blacklist() {
18         local blacklistfile="$1"
19         local pluginfile="$2"
20         while read glob; do
21                 if [[ "$glob" = \#* ]] || [[ "$glob" = "" ]]; then
22                         continue
23                 fi
24                 if [[ "$pluginfile" = $glob ]]; then
25                         echo >&3 "  $pluginfile blacklisted with $glob ($blacklistfile)"
26                         return 0
27                 fi
28         done < $blacklistfile
29
30         return 1
31 }
32
33 # bool blacklisted(char *browser, char *pluginfile)
34 # returns true if pluginfile is blacklisted for browser
35 blacklisted() {
36         local browser="$1"
37         local pluginfile="$2"
38         # check browser blacklist file
39         if [ -f "$blacklistdir/$browser.blacklist" ]; then
40                 if in_blacklist "$blacklistdir/$browser.blacklist" "$pluginfile"; then
41                         return 0
42                 fi
43         fi
44         # retrun true for now
45         return 1
46 }
47
48 # char **get_browsers(void)
49 # returns list of installed browsers
50 get_browsers() {
51         for dir in "$browsersdir"/*.*; do
52                 if [ -L "$dir" ]; then
53                         dir="${dir#$browsersdir/}"
54                         browsers="$browsers $dir"
55                 fi
56         done
57
58         echo >&3 "browsers: $browsers"
59 }
60
61 # char *browserplugindir(char *)
62 # returns plugin directory for browser
63 browserplugindir() {
64         local browser="$1"
65         readlink "$browsersdir/$browser"
66 }
67
68 remove_plugins() {
69         # kill dead links
70         for browser in $browsers; do
71                 find $(browserplugindir "$browser") -type l | while read link; do
72                         [ -f "$link" ] || rm -f "$link"
73                 done
74         done
75 }
76
77 install_plugins() {
78         # link new plugins
79         for plugindir in $plugindirs; do
80                 # skip non-existing plugindirs
81                 [ -d "$plugindir" ] || continue
82
83                 cd "$plugindir"
84                 find -type f | while read line; do
85                         pluginfile="${line#./}"
86                         echo >&3 "pluginfile: $pluginfile"
87                         for browser in $browsers; do
88                                 echo >&3 " check $pluginfile for $browser"
89                                 browserplugindir=$(browserplugindir "$browser")
90                                 link="$browserplugindir/$pluginfile"
91                                 if blacklisted "$browser" "$pluginfile"; then
92                                         # just in case unlink it
93                                         if [ -f "$link" ]; then
94                                                 echo "Removing $pluginfile from $browserplugindir"
95                                                 rm -f "$link"
96                                         fi
97                                 else
98                                         # skip existing links
99                                         [ ! -L $link ] || continue
100                                         echo "Installing $pluginfile to $browserplugindir"
101                                         ln -s "$plugindir/$pluginfile" "$link"
102                                 fi
103                         done
104                 done
105         done
106 }
107
108 if [[ "$*" = *debug* ]]; then
109         exec 3>&2
110 else
111         exec 3>/dev/null
112 fi
113
114 get_browsers
115
116 remove_plugins
117 install_plugins
This page took 0.035308 seconds and 2 git commands to generate.