~ubuntu-branches/debian/squeeze/flashplugin-nonfree/squeeze

« back to all changes in this revision

Viewing changes to update-flashplugin

  • Committer: Bazaar Package Importer
  • Author(s): Bart Martens
  • Date: 2008-09-01 18:53:07 UTC
  • mfrom: (1.1.9 edgy)
  • Revision ID: james.westby@ubuntu.com-20080901185307-l10hkik83hzl2hxc
Tags: 1:1.7.2
Edited update-flashplugin-nonfree to add the use of update-alternatives,
removed debian/links.amd64 and debian/links.i386, edited debian/rules to
remove the creation and deletion of debian/links, edited debian/dirs to
remove obsolete browser plugin directories.  Closes: #494266.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/ruby
2
 
#
3
 
# Download updated flashplugins from Macromedia website.
4
 
#
5
 
# (C) 2002 Takuo KITAME <kitame@debian.org>
6
 
# You may freely distribute this file under the terms of the GNU General
7
 
# Public License, version 2 or later.
8
 
#
9
 
# $Id: update-flashplugin,v 1.1 2003/03/07 07:45:25 takuo Exp $
10
 
 
11
 
require 'net/http'
12
 
require 'md5'
13
 
require 'ftools'
14
 
require 'uri'
15
 
require 'getoptlong'
16
 
require '/etc/update-flashplugin.conf'
17
 
 
18
 
module UpdateFlashPlugin
19
 
include UpdateFlashPluginConf
20
 
 
21
 
class FlashUpdater
22
 
  attr_accessor :del, :local, :dir, :force, :check_only, :need_update
23
 
  attr_accessor :proxy, :no_proxy, :quiet
24
 
  def initialize
25
 
    @version = "7.0.25"
26
 
    @check_only = false
27
 
    @force = false
28
 
    @need_update = false
29
 
    @tar_sum = "  3de1fafb338dd82f1de596e8a3b31344"
30
 
    @instdir = "/usr/lib/flashplugin-nonfree"
31
 
    @checks = {
32
 
      "libflashplayer.so" => "48b908ecac3b305d4eae6a66ae3fb4dd",
33
 
      "flashplayer.xpt" => "a81fd3b03b8c6d6e5a14298110718d3f"
34
 
    }
35
 
    @linkdir = [ "/usr/lib/mozilla/plugins",
36
 
      "/usr/lib/mozilla-snapshot/plugins",
37
 
      "/usr/lib/mozilla-firebird/plugins",
38
 
      "/usr/lib/mozilla-firefox/plugins"
39
 
    ]
40
 
    @quiet = false
41
 
    @del = false
42
 
    @local = false
43
 
    @dir = "/tmp"
44
 
        @cur_dir = Dir.pwd
45
 
        @proxy_user = nil
46
 
        @proxy_uri = nil
47
 
        @mirrors = UpdateFlashPlugin::SITES
48
 
  end
49
 
  
50
 
  def _print(*str)
51
 
    print *str unless @quiet
52
 
  end
53
 
  
54
 
  def check_sum()
55
 
    if File.exist?(@instdir) && ! File.directory?(@instdir)
56
 
      $stderr.print "E: File is not directory: #{@instdir}.\n"
57
 
      clean_tmp
58
 
      exit 1
59
 
    elsif ! File.exist?(@instdir) 
60
 
      Dir.mkdir(@instdir)
61
 
    end
62
 
    print "Checking md5sum...\n"
63
 
    @checks.each { |f,s|
64
 
      if ! File.exist?("#{@instdir}/#{f}")
65
 
        _print "#{@instdir}/#{f} doesn't exist. Update\n"
66
 
        return true 
67
 
      end
68
 
      if MD5.new(File.open("#{@instdir}/#{f}", 'r').binmode.read).hexdigest != s
69
 
        _print "#{@instdir}/#{f} is outdated (didn't match md5sum). Update.\n"
70
 
        return true
71
 
      end
72
 
    }
73
 
    _print "flashplugins don't need updating.\n "
74
 
    return false
75
 
  end
76
 
  
77
 
  def tempdir(tmpdir = "/tmp", base = "", max = 100)
78
 
    n = 0
79
 
    while true
80
 
      begin
81
 
        tmpname = sprintf('%s/%s%d.%d', tmpdir, base, $$, n)
82
 
        unless File.exist?(tmpname)
83
 
          Dir.mkdir(tmpname)
84
 
          break
85
 
        end
86
 
      rescue
87
 
        raise "cannot generate tempdir `%s'" % tmpname if n >= max
88
 
        exit 1
89
 
      end
90
 
      n += 1
91
 
    end
92
 
    @tmpdir = tmpname
93
 
  end
94
 
 
95
 
  def check_proxy()
96
 
        return true if @proxy_uri
97
 
    if !@no_proxy && (@proxy || ENV["http_proxy"])
98
 
      proxy_str = @proxy || ENV["http_proxy"] || nil
99
 
      if proxy_str
100
 
                uri = URI::parse(ENV["http_proxy"])
101
 
                @proxy_user = ["#{uri.userinfo}"].pack('m').strip
102
 
                @proxy_uri = uri
103
 
                return true
104
 
      end
105
 
    end
106
 
        @proxy_uri = nil
107
 
        @proxy_user = nil
108
 
        return false
109
 
  end
110
 
 
111
 
  def get_file( host )
112
 
    # http://macromedia.mplug.org/tarball/debian/install_flash_player_7_linux.tar.gz
113
 
    dest = ""
114
 
    header = {}
115
 
    
116
 
    fp = open("#{@tmpdir}/install_flash_player_7_linux.tar.gz", "w+")
117
 
        failed = false
118
 
    path = @mirrors[host]
119
 
    if check_proxy
120
 
      header['Proxy-Authorization'] = "Basic " + @proxy_user if @proxy_user
121
 
      http = Net::HTTP::new(host, 80, 
122
 
                            @proxy_uri.host, @proxy_uri.port)
123
 
    else
124
 
      http = Net::HTTP::new(host)
125
 
    end
126
 
    begin
127
 
      r = http.head("#{path}install_flash_player_7_linux.tar.gz", header)
128
 
    rescue Errno::ECONNREFUSED
129
 
      $stderr.print "E: Connection was refused: #{host}\n"
130
 
      fp.close
131
 
      failed = true
132
 
    rescue Errno::EHOSTUNREACH
133
 
      $stderr.print "E: No route to host: #{host}\n"
134
 
      fp.close
135
 
      failed = true
136
 
    rescue TimeoutError
137
 
      $stderr.print "E: Connection has been timed out: #{host}\n"
138
 
      fp.close
139
 
      failed = true
140
 
    rescue
141
 
      $stderr.print "E: Unknown HTTP error: #{host}\n"
142
 
      fp.close
143
 
      failed = true
144
 
    end
145
 
        if failed
146
 
          clean_tmp(true)
147
 
          exit 1
148
 
        end
149
 
    t = r['content-length'].to_i
150
 
    c = 0
151
 
    http.get("#{path}install_flash_player_7_linux.tar.gz", header) { |d| 
152
 
      c = c + d.length
153
 
      p = sprintf("%.0f", c.to_f / t.to_f * 100)
154
 
      _print "getting install_flash_player_7_linux.tar.gz [", c, "/", t, " (", p, "%)]\r"
155
 
      fp.print d
156
 
    }
157
 
    _print "\n"
158
 
    fp.close
159
 
  end
160
 
  
161
 
  def extract()
162
 
    Dir.chdir(@tmpdir)
163
 
    if @local
164
 
      file = @dir + "/install_flash_player_7_linux.tar.gz"
165
 
      if !File.exist?(file)
166
 
                $stderr.print "E: File: #{file} does not exist.\n"
167
 
                Dir.chdir(@cur_dir)
168
 
                exit 1
169
 
      end
170
 
      if MD5.new(File.open("#{file}", 'r').binmode.read).hexdigest != @tar_sum
171
 
                $stderr.print "E: md5sum of #{file} does not match with #{@tar_sum}.\n"
172
 
                Dir.chdir(@cur_dir)
173
 
                exit
174
 
      end
175
 
      _print "use existing file: #{file}\n"
176
 
    else
177
 
      file = "install_flash_player_7_linux.tar.gz"
178
 
    end
179
 
    system("tar -xzf #{file} install_flash_player_7_linux/libflashplayer.so")
180
 
    system("tar -xzf #{file} install_flash_player_7_linux/flashplayer.xpt")
181
 
        Dir.chdir(@cur_dir)
182
 
  end
183
 
  
184
 
  def links()
185
 
    _print "Removing old plugin files, and creating symlinks to new.\n"
186
 
    @linkdir.each { |d|
187
 
      File.makedirs(d)
188
 
      @checks.each { |f,s|
189
 
        File.delete("#{d}/#{f}") if File.exist?("#{d}/#{f}")
190
 
        File.symlink("#{@instdir}/#{f}", "#{d}/#{f}")
191
 
      }
192
 
    }
193
 
  end
194
 
  
195
 
  def uninstall
196
 
    _print "Removing plugin files and symlinks...\n"
197
 
    @checks.each { |f,s|
198
 
      @linkdir.each { |d|
199
 
                File.delete("#{d}/#{f}") if File.exist?("#{d}/#{f}")
200
 
      }
201
 
      File.delete("#{@instdir}/#{f}") if File.exist?("#{@instdir}/#{f}")
202
 
    }
203
 
        File.delete("#{@instdir}/version") if File.exist?("#{@instdir}/version")
204
 
    Dir.delete(@instdir) if File.exist?(@instdir)
205
 
  end
206
 
  
207
 
  def install
208
 
    Dir.chdir("#{@tmpdir}/install_flash_player_7_linux")
209
 
    File.makedirs(@instdir)
210
 
    File.install("libflashplayer.so", "#{@instdir}/libflashplayer.so")
211
 
    File.install("flashplayer.xpt", "#{@instdir}/flashplayer.xpt")
212
 
    Dir.chdir(@cur_dir)
213
 
  end
214
 
  
215
 
  def update( host )
216
 
    _print "Updating flashplugin...\n"
217
 
        tempdir("/tmp","flashupdater",100)
218
 
    get_file( host ) unless @local
219
 
    extract()
220
 
    install()
221
 
    links()
222
 
    
223
 
    _print "done.\n"
224
 
    clean_tmp(false)
225
 
    done_update
226
 
  end
227
 
 
228
 
  def done_update
229
 
        file = @instdir + "/version"
230
 
        fp = File.open(file, "w+")
231
 
        fp.print @version, "\n"
232
 
        fp.print @tar_sum, "\n"
233
 
        fp.close
234
 
  end
235
 
 
236
 
  def check_installed
237
 
        file = @instdir + "/version"
238
 
        if File.exist?(file)
239
 
          fp = File.open(file, "r")
240
 
          @version = fp.gets.chomp
241
 
          @tar_sum = fp.gets.chomp
242
 
          fp.close
243
 
        else
244
 
          @version = "not installed"
245
 
        end
246
 
  end
247
 
 
248
 
  def check_update()
249
 
        # check http://macromedia.mplug.org/tarball/debian/gpg-md5sums.txt
250
 
        _print "Checking new upstream release...\n"
251
 
        header = {}
252
 
        version = nil
253
 
        tar_sum = nil
254
 
        failed = true
255
 
    find = nil
256
 
        @mirrors.each { | host, path |
257
 
          if failed
258
 
                failed = false
259
 
          else
260
 
                break
261
 
          end
262
 
          if check_proxy
263
 
                header['Proxy-Authorization'] = "Basic " + @proxy_user if @proxy_user
264
 
                http = Net::HTTP::new(host, 80, 
265
 
                                                          @proxy_uri.host, @proxy_uri.port)
266
 
          else
267
 
                http = Net::HTTP::new(host)       
268
 
          end
269
 
          _print "I: checking http://#{host}#{path}...\n"
270
 
          begin
271
 
                r , body = http.get("#{path}gpg-md5sums.txt", header)
272
 
                body.each { |l|
273
 
                  if /^flash-plugin ([\d\.]*)$/ =~ l
274
 
                        version = $1
275
 
                        next
276
 
                  elsif /^([0-9a-z]{32})\s+install_flash_player_7_linux.tar.gz$/ =~ l
277
 
                        tar_sum = $1
278
 
                        next
279
 
                  end
280
 
                }
281
 
        find = host
282
 
          rescue Errno::ECONNREFUSED
283
 
                $stderr.print "E: Connection was refused: #{host}\n"
284
 
                failed = true
285
 
                next
286
 
          rescue Errno::EHOSTUNREACH
287
 
                $stderr.print "E: No route to host: #{host}\n"
288
 
                failed = true
289
 
                next
290
 
          rescue TimeoutError
291
 
                $stderr.print "E: Connection has been timed out: #{host}\n"
292
 
                failed = true
293
 
                next
294
 
          rescue
295
 
                $stderr.print "E: Unknown HTTP error: #{host}\n"
296
 
                failed = true
297
 
                next
298
 
          end
299
 
        }
300
 
        if failed 
301
 
          $stderr.print "E: All failed.\n"
302
 
          clean_tmp(true)
303
 
          exit 1
304
 
        end
305
 
    if version && @version != version
306
 
      print "New version #{version} is detected (current: #{@version})\n"
307
 
      @version = version
308
 
      @tar_sum = tar_sum
309
 
      if @check_only
310
 
                _print "Do without \"-c\" option to upgrade.\n"
311
 
      else
312
 
                @need_update = true
313
 
      end
314
 
        else
315
 
          _print "No new version is detected. (#{version} = #{@version})\n"
316
 
    end
317
 
    return find
318
 
  end  
319
 
  
320
 
  def clean_tmp(error = false)
321
 
    @checks.each {|f,s|
322
 
      File.delete("#{@tmpdir}/install_flash_player_7_linux/#{f}") if File.exist?("#{@tmpdir}/install_flash_player_7_linux/#{f}")
323
 
    }
324
 
    
325
 
    if error and File.exist?("#{@tmpdir}/install_flash_player_7_linux.tar.gz")
326
 
      File.delete("#{@tmpdir}/install_flash_player_7_linux.tar.gz")
327
 
    end
328
 
 
329
 
    if @del
330
 
      if @local
331
 
        File.delete("#{@dir}/install_flash_player_7_linux.tar.gz") if
332
 
          File.exist?("#{@dir}/install_flash_player_7_linux.tar.gz")
333
 
      else
334
 
        File.delete("#{@tmpdir}/install_flash_player_7_linux.tar.gz") if
335
 
          File.exist?("#{@tmpdir}/install_flash_player_7_linux.tar.gz")
336
 
      end
337
 
    else
338
 
      if ! @local and ! error
339
 
        _print "install_flash_player_7_linux.tar.gz was saved into #{@tmpdir}\n"
340
 
      end
341
 
    end
342
 
    if ! error
343
 
      Dir.delete("#{@tmpdir}/install_flash_player_7_linux") if
344
 
                File.exist?("#{@tmpdir}/install_flash_player_7_linux") &&
345
 
                File.directory?("#{@tmpdir}/install_flash_player_7_linux")
346
 
      Dir.delete(@tmpdir) if
347
 
                File.exist?(@tmpdir) &&
348
 
                File.directory?(@tmpdir) && (@del || @local)
349
 
    end
350
 
  end
351
 
end
352
 
end # module
353
 
##
354
 
## __MAIN__
355
 
##
356
 
if Process.uid != 0 
357
 
  print "You are not root.\n"
358
 
  exit 1
359
 
end
360
 
 
361
 
opt = GetoptLong.new
362
 
opt.set_options(
363
 
                ['--uninstall', '-u', GetoptLong::NO_ARGUMENT],
364
 
                ['--local-file', '-l', GetoptLong::REQUIRED_ARGUMENT],
365
 
                ['--proxy', '-p', GetoptLong::REQUIRED_ARGUMENT],
366
 
                ['--no-proxy', '-P', GetoptLong::NO_ARGUMENT],
367
 
                ['--delete-after', '-d', GetoptLong::NO_ARGUMENT],
368
 
                ['--force-update', '-f', GetoptLong::NO_ARGUMENT],
369
 
                ['--check-update', '-c', GetoptLong::NO_ARGUMENT],
370
 
                ['--quiet', '-q', GetoptLong::NO_ARGUMENT],
371
 
                ['--help', '-h', GetoptLong::NO_ARGUMENT]
372
 
# not implemented yet
373
 
                #                               ['--create-symlink', '-c', GetoptLong::NO_ARGUMENT],
374
 
                #                               ['--remove-symlink', '-r', GetoptLong::NO_ARGUMENT],
375
 
                )
376
 
 
377
 
uninstall = false
378
 
help = false
379
 
f = UpdateFlashPlugin::FlashUpdater.new()
380
 
 
381
 
begin
382
 
  opt.each_option { |name, arg|
383
 
    f.del = true if name == "--delete-after"
384
 
    if name == "--local-file"
385
 
      f.local = true
386
 
      f.dir = arg
387
 
    end
388
 
    f.force = true if name == "--force-update"
389
 
    f.quiet = true if name == "--quiet"
390
 
    f.proxy = arg if name == "--proxy"
391
 
    f.no_proxy = true if name == "--no-proxy"
392
 
    uninstall = true if name == "--uninstall"
393
 
    help = true  if name == "--help"
394
 
    f.check_only = true if name == "--check-update"
395
 
  }
396
 
rescue
397
 
  exit
398
 
end
399
 
 
400
 
if help
401
 
  print <<EOF
402
 
usage: update-flashplugin [options]
403
 
options:
404
 
        --uninstall, -u                 --  uninstall
405
 
        --local-file, -l <directory>    --  use local file 
406
 
        --proxy, -p <http_proxy>        --  use specified proxy
407
 
        --no-proxy, -P                  --  don't use proxy
408
 
        --delete-after, -d              --  delete archive after install
409
 
        --force-update, -f              --  force update
410
 
        --check-update, -c              --  only check new version
411
 
        --quiet, -q                     --  be quiet
412
 
        --help, -h                      --  print this
413
 
 
414
 
see also update-flashplugin(8)
415
 
EOF
416
 
  exit
417
 
end
418
 
 
419
 
if uninstall
420
 
  f.uninstall
421
 
  exit
422
 
end
423
 
 
424
 
f.check_installed
425
 
host = f.check_update
426
 
 
427
 
if ( f.force || f.need_update ) && ! f.check_only
428
 
  f.update( host )
429
 
  if File.exist?("/usr/sbin/update-mozilla-chrome")
430
 
    system("/usr/sbin/update-mozilla-chrome")
431
 
  end
432
 
  if File.exist?("/usr/sbin/update-mozilla-snapshot-chrome")
433
 
    system("/usr/sbin/update-mozilla-snapshot-chrome")
434
 
  end
435
 
  if File.exist?("/usr/sbin/update-mozilla-firebird-chrome")
436
 
    system("/usr/sbin/update-mozilla-firebird-chrome")
437
 
  end
438
 
  if File.exist?("/usr/sbin/update-mozilla-firefox-chrome")
439
 
    system("/usr/sbin/update-mozilla-firefox-chrome")
440
 
  end
441
 
end