File: migratepins

package info (click to toggle)
apt-listbugs 0.1.16
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,088 kB
  • ctags: 108
  • sloc: ruby: 2,280; sh: 210; makefile: 49
file content (67 lines) | stat: -rwxr-xr-x 2,252 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/ruby
#
# migratepins: migrates all apt-listbugs-managed pins from
#              /etc/apt/preferences to <tmpdir>/apt-listbugs
#              and everything else to <tmpdir>/preferences
#
# Copyright (C) 2009       Ryan Niebur <ryan@debian.org>
# Copyright (C) 2014       Francesco Poli <invernomuto@paranoici.org>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License with
#  the Debian GNU/Linux distribution in file /usr/share/common-licenses/GPL-2;
#  if not, write to the Free Software Foundation, Inc., 51 Franklin St,
#  Fifth Floor, Boston, MA 02110-1301, USA.
#
#

if File.expand_path(__FILE__).match(/^\/usr\/share\/apt-listbugs\//)
  $LOAD_PATH.unshift("/usr/share/apt-listbugs")
else
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib"))
end

require 'gettext'
include GetText

GetText::bindtextdomain("apt-listbugs")

require 'debian/apt_preferences'
require 'tmpdir'

# create a temporary directory to split APT preferences
# and print its name to stdout
dest_dir = Dir.mktmpdir('pin_migration_')
puts dest_dir

# read APT preferences from /etc/apt/preferences
pref_file = "/etc/apt/preferences"
begin
  p = Debian::AptPreferences.new(pref_file)
rescue Errno::ENOENT
  $stderr.puts sprintf("Cannot find %s: exiting!", pref_file) if $DEBUG
  exit 0
rescue Errno::EACCES
  $stderr.puts _("E: ") + sprintf(_("Cannot read from %s"), pref_file)
  exit 1
rescue
  $stderr.puts _("E: ") + "#{$!}"
  exit 1
end

# split APT preferences:
# all apt-listbugs-managed pins go to dest_dir/apt-listbugs
# everything else goes to dest_dir/preferences
new_pref_file = File.open(dest_dir + "/preferences", "w")
new_aptl_file = File.open(dest_dir + "/apt-listbugs", "w")
p.filter( [], new_pref_file, new_aptl_file )