]> git.pld-linux.org Git - packages/browser-plugins.git/blob - browser-plugins-update.sh
- adjust dep compatible for ac; rel 3
[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, Initial revision
4 # Date: 2006-10-31, Added arch checking
5 #
6 # For more information see browser-plugins.README
7 #
8 # TODO
9 # - implement uninstall
10
11 sysconfdir='/etc/browser-plugins'
12 browsersdir="$sysconfdir/browsers.d"
13 blacklistdir="$sysconfdir/blacklist.d"
14 plugindirs='/usr/lib/browser-plugins /usr/lib64/browser-plugins'
15
16 # bool in_blacklist(char *blacklistfile, char *pluginfile)
17 # returns true if pluginfile is listed in blacklistfile 
18 in_blacklist() {
19         local blacklistfile="$1"
20         local pluginfile="$2"
21         while read glob; do
22                 if [[ "$glob" = \#* ]] || [[ "$glob" = "" ]]; then
23                         continue
24                 fi
25                 if [[ "$pluginfile" = $glob ]]; then
26                         echo >&3 "  $pluginfile blacklisted with $glob ($blacklistfile)"
27                         return 0
28                 fi
29         done < $blacklistfile
30
31         return 1
32 }
33
34 # bool arch_compatible(char *browser, char *plugindir)
35 # returns true if browser and plugindir are from same arch
36 arch_compatible() {
37         local browser="$1"
38         local plugindir="$2"
39
40         if ([[ "$browser" = *.x86_64 ]] && [[ "$plugindir" != */lib64/* ]]) || \
41                 ([[ "$browser" != *.x86_64 ]] && [[ "$plugindir" = */lib64/* ]]); then
42                 echo >&3 "  $browser not compatible with $plugindir"
43                 return 1
44         fi
45         return 0
46 }
47
48 # bool blacklisted(char *browser, char *pluginfile)
49 # returns true if pluginfile is blacklisted for browser
50 # returns also true if pluginfile is from incompatible arch
51 blacklisted() {
52         local browser="$1"
53         local pluginfile="$2"
54         # check browser blacklist file
55         if [ -f "$blacklistdir/$browser.blacklist" ]; then
56                 if in_blacklist "$blacklistdir/$browser.blacklist" "$pluginfile"; then
57                         return 0
58                 fi
59         fi
60         # retrun true for now
61         return 1
62 }
63
64 # char **get_browsers(void)
65 # returns list of installed browsers
66 get_browsers() {
67         for dir in "$browsersdir"/*.*; do
68                 if [ -L "$dir" ]; then
69                         if [ ! -d "$dir" ]; then
70                                 echo >&2 "$0: WARNING: plugindir $dir is not pointing to directory, browser ignored"
71                                 continue
72                         fi
73                         dir="${dir#$browsersdir/}"
74                         browsers="$browsers $dir"
75                 fi
76         done
77
78         echo >&3 "browsers: $browsers"
79 }
80
81 # void update_nspluginwrapper(void)
82 # update nspluginwrapper links
83 update_nspluginwrapper() {
84         [ -x /usr/bin/nspluginwrapper ] || return
85
86         umask 002
87         # call it always in install mode, as update mode does not update existing links
88         /usr/bin/nspluginwrapper -a -i
89
90         # this will remove oudated plugins
91         for a in /usr/lib64/browser-plugins/npwrapper.*.so; do
92                 [ -f $a ] || continue
93                 /usr/bin/nspluginwrapper -v -u $a
94         done
95
96         # run install again after nsplugin wrappers
97         install_plugins
98 }
99
100 # char *browserplugindir(char *)
101 # returns plugin directory for browser
102 browserplugindir() {
103         local browser="$1"
104         local dir
105         dir=$(readlink "$browsersdir/$browser")
106         if [ ! -d "$dir" -o -z "$dir" ]; then
107                 echo >&2 "$0: ERROR: could not resolve plugindir for $browser"
108                 exit 1
109         fi
110         echo "$dir"
111 }
112
113 # kill dead links to plugins from browser dirs.
114 # dead links appear if plugin is removed or if newer plugin version no longer
115 # includes previously packaged file
116 remove_plugins() {
117         for browser in $browsers; do
118                 find $(browserplugindir "$browser") -type l | while read link; do
119                         if [ ! -f "$link" ]; then
120                                 echo "Removing $link"
121                                 rm -f "$link"
122                         fi
123                 done
124         done
125 }
126
127 install_plugins() {
128         # link new plugins
129         for plugindir in $plugindirs; do
130                 echo >&3
131                 echo >&3 "check $plugindir"
132
133                 # skip non-existing plugindirs
134                 [ -d "$plugindir" ] || continue
135
136                 cd "$plugindir"
137                 find -type f -o -type l | while read line; do
138                         pluginfile="${line#./}"
139                         echo >&3 "pluginfile: $pluginfile"
140                         for browser in $browsers; do
141                                 echo >&3 " check $pluginfile for $browser"
142                                 browserplugindir=$(browserplugindir "$browser")
143                                 link="$browserplugindir/$pluginfile"
144
145                                 if ! arch_compatible "$browser" "$plugindir"; then
146                                         continue
147                                 fi
148
149                                 if blacklisted "$browser" "$pluginfile"; then
150                                         # just in case unlink it
151                                         if [ -f "$link" ]; then
152                                                 echo "Removing $pluginfile from $browserplugindir"
153                                                 rm -f "$link"
154                                         fi
155                                 else
156                                         # skip existing links
157                                         [ ! -L $link ] || continue
158                                         if [[ "$pluginfile" = */* ]]; then
159                                                 # FIXME: what's the proper handling for this?
160                                                 echo >&2 "$0: Warning: pluginfile $pluginfile includes subdir, file ignored"
161                                                 continue
162                                         fi
163                                         echo "Installing $pluginfile to $browserplugindir"
164                                         ln -s "$plugindir/$pluginfile" "$link"
165                                 fi
166                         done
167                 done
168         done
169 }
170
171 if [[ "$*" = *debug* ]]; then
172         exec 3>&2
173 else
174         exec 3>/dev/null
175 fi
176
177 get_browsers
178
179 remove_plugins
180 install_plugins
181 update_nspluginwrapper
This page took 0.263619 seconds and 4 git commands to generate.