]> git.pld-linux.org Git - packages/browser-plugins.git/blob - browser-plugins-update.sh
fad24a01eaeb6e17cc158f7addd09c14245aea07
[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                 # skip non-existing plugindirs
108                 [ -d "$plugindir" ] || continue
109
110                 cd "$plugindir"
111                 find -type f | while read line; do
112                         pluginfile="${line#./}"
113                         echo >&3 "pluginfile: $pluginfile"
114                         for browser in $browsers; do
115                                 echo >&3 " check $pluginfile for $browser"
116                                 browserplugindir=$(browserplugindir "$browser")
117                                 link="$browserplugindir/$pluginfile"
118
119                                 if ! arch_compatible "$browser" "$plugindir"; then
120                                         continue
121                                 fi
122
123                                 if blacklisted "$browser" "$pluginfile"; then
124                                         # just in case unlink it
125                                         if [ -f "$link" ]; then
126                                                 echo "Removing $pluginfile from $browserplugindir"
127                                                 rm -f "$link"
128                                         fi
129                                 else
130                                         # skip existing links
131                                         [ ! -L $link ] || continue
132                                         if [[ "$pluginfile" = */* ]]; then
133                                                 # FIXME: what's the proper handling for this?
134                                                 echo >&2 "$0: Warning: pluginfile $pluginfile includes subdir, file ignored"
135                                                 continue
136                                         fi
137                                         echo "Installing $pluginfile to $browserplugindir"
138                                         ln -s "$plugindir/$pluginfile" "$link"
139                                 fi
140                         done
141                 done
142         done
143 }
144
145 if [[ "$*" = *debug* ]]; then
146         exec 3>&2
147 else
148         exec 3>/dev/null
149 fi
150
151 get_browsers
152
153 remove_plugins
154 install_plugins
This page took 0.058797 seconds and 2 git commands to generate.