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