- more errorchecking
[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         local dir
66         dir=$(readlink "$browsersdir/$browser")
67         if [ -z "$dir" ]; then
68                 echo >&2 "$0: browser plugin dir empty for $browser; exiting!"
69                 exit 1
70         fi
71         echo "$dir"
72 }
73
74 remove_plugins() {
75         # kill dead links
76         for browser in $browsers; do
77                 find $(browserplugindir "$browser") -type l | while read link; do
78                         [ -f "$link" ] || rm -f "$link"
79                 done
80         done
81 }
82
83 install_plugins() {
84         # link new plugins
85         for plugindir in $plugindirs; do
86                 # skip non-existing plugindirs
87                 [ -d "$plugindir" ] || continue
88
89                 cd "$plugindir"
90                 find -type f | while read line; do
91                         pluginfile="${line#./}"
92                         echo >&3 "pluginfile: $pluginfile"
93                         for browser in $browsers; do
94                                 echo >&3 " check $pluginfile for $browser"
95                                 browserplugindir=$(browserplugindir "$browser")
96                                 link="$browserplugindir/$pluginfile"
97                                 if blacklisted "$browser" "$pluginfile"; then
98                                         # just in case unlink it
99                                         if [ -f "$link" ]; then
100                                                 echo "Removing $pluginfile from $browserplugindir"
101                                                 rm -f "$link"
102                                         fi
103                                 else
104                                         # skip existing links
105                                         [ ! -L $link ] || continue
106                                         echo "Installing $pluginfile to $browserplugindir"
107                                         ln -s "$plugindir/$pluginfile" "$link"
108                                 fi
109                         done
110                 done
111         done
112 }
113
114 if [[ "$*" = *debug* ]]; then
115         exec 3>&2
116 else
117         exec 3>/dev/null
118 fi
119
120 get_browsers
121
122 remove_plugins
123 install_plugins
This page took 0.048907 seconds and 4 git commands to generate.