madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

also allow use of apt-get via sudo
[puppet/modules/apt.git] / manifests / init.pp
1 # apt/manifests/init.pp - manage APT
2 # Copyright (C) 2009–2010 martin f. krafft <madduck@madduck.net>
3 #
4
5 class apt::install {
6
7     package { "apt":
8         ensure => present
9     }
10
11     package { [ "debian-archive-keyring", "gnupg", "wget", "debconf-utils" ]:
12         ensure => latest
13     }
14 }
15
16 class apt::files {
17
18     if !defined(File[$_apt_module_parent_dir]) {
19         file { $_apt_module_parent_dir:
20             ensure  => directory,
21             owner   => root,
22             group   => root,
23             mode    => 755,
24         }
25     }
26
27     file { [ "/etc/apt/apt.conf.d", $_apt_module_dir ]:
28         ensure  => directory,
29         owner   => root,
30         group   => root,
31         mode    => 644,
32         recurse => true
33     }
34
35     file { "/etc/apt/sources.list.d":
36         ensure  => directory,
37         owner   => root,
38         group   => root,
39         mode    => 644,
40         recurse => true,
41         purge   => $apt_enforce_sourceslist_set
42     }
43
44     if $apt_enforce_sourceslist_set {
45         file { "/etc/apt/sources.list":
46             ensure => absent
47         }
48     }
49 }
50
51 class apt::update {
52     exec { apt-update:
53         command     => "sh -c 'aptitude update || :'",
54         refreshonly => true,
55         subscribe   => [Class["apt::files"], Class["apt::repositories"]],
56         logoutput   => on_failure
57     }
58 }
59
60 class apt::sudo {
61
62     if defined(Class["sudo"]) {
63         @sudo::permission { "aptitude-safe-upgrades":
64             who      => "%$apt_upgrader_group",
65             runas    => "root",
66             command  => [ "/usr/bin/aptitude update"
67                         , "/usr/bin/aptitude safe-upgrade"
68                         , "/usr/bin/apt-get update"
69                         , "/usr/bin/apt-get upgrade"
70                         ],
71             nopasswd => true
72         }
73
74         @sudo::permission { "aptitude":
75             who      => "%$apt_upgrader_group",
76             runas    => "root",
77             command  => "/usr/bin/aptitude"
78         }
79
80         @sudo::permission { ["apt-dist-upgrades","apt-safe-upgrades"]:
81             ensure   => absent,
82             who      => "%$apt_upgrader_group",
83             runas    => "root",
84             command  => [ "/usr/bin/aptitude dist-upgrade"
85                         , "/usr/bin/apt-get dist-upgrade"
86                         ]
87         }
88     }
89 }
90
91 class apt {
92
93     $_apt_stable_suite = "lenny"
94
95     $apt_include_sources = $apt_include_sources ?
96         { "" => false, default => $apt_include_sources }
97
98     $apt_suite = $apt_suite ? {
99         ""      => $_apt_stable_suite,
100         default => $apt_suite
101     }
102
103     $apt_include_experimental = $apt_include_experimental ? {
104         ""      => false,
105         default => $apt_include_experimental
106     }
107
108     $apt_components = $apt_components ? {
109         ""      => [ "main" ],
110         default => $apt_components
111     }
112
113     $apt_mirror_base = $apt_mirror_base ? {
114         ""      => "http://cdn.debian.net",
115         default => $apt_mirror_base
116     }
117
118     $apt_mirror = $apt_mirror ? {
119         ""      => "${apt_mirror_base}/debian",
120         default => $apt_mirror
121     }
122
123     $apt_security_mirror = $apt_security_mirror ? {
124         ""      => "http://security.debian.org",
125         default => $apt_security_mirror
126     }
127
128     $_apt_is_stable = $apt_suite ? { $_apt_stable_suite => true, default => false }
129
130     $apt_include_volatile = $apt_include_volatile ?
131         { "" => $_apt_is_stable, default => $apt_include_volatile }
132     $apt_include_volatile_sloppy = $apt_include_volatile_sloppy ?
133         { "" => $apt_include_volatile, default => $apt_include_volatile_sloppy }
134     $apt_volatile_mirror = $apt_volatile_mirror ? {
135         ""      => "${apt_mirror_base}/debian-volatile",
136         default => $apt_volatile_mirror
137     }
138
139     $apt_include_backports = $apt_include_backports ?
140         { "" => $_apt_is_stable, default => $apt_include_backports }
141     $apt_backports_mirror = $apt_backports_mirror ? {
142         ""      => "${apt_mirror_base}/backports.org",
143         default => $apt_backports_mirror
144     }
145
146     $apt_include_multimedia = $apt_include_multimedia ?
147         { "" => false, default => $apt_include_multimedia }
148     $apt_multimedia_mirror = $apt_multimedia_mirror ? {
149         ""      => "http://www.debian-multimedia.org",
150         default => $apt_multimedia_mirror
151     }
152
153     $apt_pgp_keyserver = $apt_pgp_keyserver ? {
154         ""      => "hkp://pool.sks-keyservers.net",
155         default => $apt_pgp_keyserver
156     }
157
158     $apt_enforce_sourceslist_set = $apt_enforce_sourceslist_set ?
159         { "" => false, default => $apt_enforce_sourceslist_set }
160
161     $apt_enforce_preferences_set = $apt_enforce_preferences_set ?
162         { "" => false, default => $apt_enforce_preferences_set }
163
164     $_apt_default_apt_cache_limit = 16777216
165     $apt_cache_limit = $apt_cache_limit ? {
166         ""      => $_apt_default_apt_cache_limit,
167         default => $apt_cache_limit
168     }
169
170     $apt_acquire_pdiffs = $apt_acquire_pdiffs ? {
171         ""      => true,
172         default => $apt_acquire_pdiffs
173     }
174
175     $apt_install_recommends = $apt_install_recommends ? {
176         ""      => true,
177         default => $apt_install_recommends
178     }
179
180     $apt_upgrader_group = $apt_upgrader_group ? {
181         ""      => "staff",
182         default => $apt_upgrader_group
183     }
184
185     $_apt_module_parent_dir = "/var/lib/puppet/modules"
186     $_apt_module_dir = "${_apt_module_parent_dir}/apt"
187
188     include apt::install, apt::files, apt::repositories, apt::update
189     include apt::config
190     include apt::preferences
191     include apt::sudo
192 }
193
194 # vim:ft=puppet