6747036d1a057313c073fdaa7e8d46937726d4ed
[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 # char *browserplugindir(char *)
82 # returns plugin directory for browser
83 browserplugindir() {
84         local browser="$1"
85         local dir
86         dir=$(readlink "$browsersdir/$browser")
87         if [ ! -d "$dir" -o -z "$dir" ]; then
88                 echo >&2 "$0: ERROR: browser plugin dir pointing to nowhere for $browser!"
89                 exit 1
90         fi
91         echo "$dir"
92 }
93
94 # kill dead links to plugins from browser dirs.
95 # dead links appear if plugin is removed or if newer plugin version no longer
96 # includes previously packaged file
97 remove_plugins() {
98         for browser in $browsers; do
99                 find $(browserplugindir "$browser") -type l | while read link; do
100                         if [ ! -f "$link" ]; then
101                                 echo "Removing $link"
102                                 rm -f "$link"
103                         fi
104                 done
105         done
106 }
107
108 install_plugins() {
109         # link new plugins
110         for plugindir in $plugindirs; do
111                 echo >&3
112                 echo >&3 "check $plugindir"
113
114                 # skip non-existing plugindirs
115                 [ -d "$plugindir" ] || continue
116
117                 cd "$plugindir"
118                 find -type f -o -type l | while read line; do
119                         pluginfile="${line#./}"
120                         echo >&3 "pluginfile: $pluginfile"
121                         for browser in $browsers; do
122                                 echo >&3 " check $pluginfile for $browser"
123                                 browserplugindir=$(browserplugindir "$browser")
124                                 link="$browserplugindir/$pluginfile"
125
126                                 if ! arch_compatible "$browser" "$plugindir"; then
127                                         continue
128                                 fi
129
130                                 if blacklisted "$browser" "$pluginfile"; then
131                                         # just in case unlink it
132                                         if [ -f "$link" ]; then
133                                                 echo "Removing $pluginfile from $browserplugindir"
134                                                 rm -f "$link"
135                                         fi
136                                 else
137                                         # skip existing links
138                                         [ ! -L $link ] || continue
139                                         if [[ "$pluginfile" = */* ]]; then
140                                                 # FIXME: what's the proper handling for this?
141                                                 echo >&2 "$0: Warning: pluginfile $pluginfile includes subdir, file ignored"
142                                                 continue
143                                         fi
144                                         echo "Installing $pluginfile to $browserplugindir"
145                                         ln -s "$plugindir/$pluginfile" "$link"
146                                 fi
147                         done
148                 done
149         done
150 }
151
152 if [[ "$*" = *debug* ]]; then
153         exec 3>&2
154 else
155         exec 3>/dev/null
156 fi
157
158 get_browsers
159
160 remove_plugins
161 install_plugins
This page took 0.09527 seconds and 2 git commands to generate.