This repository has been archived by the owner on Feb 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathrepo.pp
158 lines (141 loc) · 5.95 KB
/
repo.pp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#
# Author: Joe Damato
# Module Name: packagecloud
#
# Copyright 2014-2015, Computology, LLC
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
define packagecloud::repo(
$type = undef,
$fq_name = undef,
$master_token = undef,
$priority = undef,
$metadata_expire = 300,
$server_address = 'https://packagecloud.io',
) {
validate_string($type)
validate_string($master_token)
include ::packagecloud
if $fq_name != undef {
$repo_name = $fq_name
} else {
$repo_name = $name
}
$normalized_name = regsubst($repo_name, '\/', '_')
if $master_token != undef {
$read_token = get_read_token($repo_name, $master_token, $server_address)
$base_url = build_base_url($read_token, $server_address)
} else {
$read_token = false
$base_url = $server_address
}
case $type {
'gem': {
packagecloud::gem_repo {"Gem Repo ${repo_name}":
base_url => $base_url,
repo_name => $repo_name,
}
}
'deb': {
$osname = downcase($::operatingsystem)
case $osname {
'debian', 'ubuntu': {
$component = 'main'
$repo_url = "${base_url}/${repo_name}/${osname}"
$distribution = $::lsbdistcodename
file { $normalized_name:
ensure => file,
path => "/etc/apt/sources.list.d/${normalized_name}.list",
mode => '0644',
content => template('packagecloud/apt.erb'),
}
exec { "apt_key_add_${normalized_name}":
command => "wget --auth-no-challenge -qO - ${base_url}/${repo_name}/gpgkey | apt-key add -",
path => '/usr/bin/:/bin/',
require => File[$normalized_name],
}
exec { "apt_get_update_${normalized_name}":
command => "apt-get update -o Dir::Etc::sourcelist=\"sources.list.d/${normalized_name}.list\" -o Dir::Etc::sourceparts=\"-\" -o APT::Get::List-Cleanup=\"0\"",
path => '/usr/bin/:/bin/',
require => Exec["apt_key_add_${normalized_name}"],
}
}
default: {
fail("Sorry, ${::operatingsystem} isn't supported for apt repos at this time. Email support@packagecloud.io")
}
}
}
'rpm': {
case $::operatingsystem {
'RedHat', 'redhat', 'CentOS', 'centos', 'Amazon', 'Fedora', 'Scientific', 'OracleLinux', 'OEL': {
$majrel = $::osreleasemaj
if $::pygpgme_installed == 'false' {
warning('The pygpgme package could not be installed. This means GPG verification is not possible for any RPM installed on your system. To fix this, add a repository with pygpgme. Usualy, the EPEL repository for your system will have this. More information: https://fedoraproject.org/wiki/EPEL#How_can_I_use_these_extra_packages.3F and https://github.com/stahnma/puppet-module-epel')
$repo_gpgcheck = 0
} else {
$repo_gpgcheck = 1
}
if $read_token {
if $majrel == '5' {
$yum_repo_url = $::operatingsystem ? {
/(RedHat|redhat|CentOS|centos)/ => "${server_address}/priv/${read_token}/${repo_name}/el/5/${::architecture}/",
/(OracleLinux|OEL)/ => "${server_address}/priv/${read_token}/${repo_name}/ol/5/${::architecture}/",
'Scientific' => "${server_address}/priv/${read_token}/${repo_name}/scientific/5/${::architecture}/",
}
$gpg_url = "${server_address}/priv/${read_token}/${repo_name}/gpgkey"
} else {
$yum_repo_url = $::operatingsystem ? {
/(RedHat|redhat|CentOS|centos)/ => "${base_url}/${repo_name}/el/${majrel}/${::architecture}/",
/(OracleLinux|OEL)/ => "${base_url}/${repo_name}/ol/${majrel}/${::architecture}/",
'Scientific' => "${base_url}/${repo_name}/scientific/${majrel}/${::architecture}/",
}
$gpg_url = "${base_url}/${repo_name}/gpgkey"
}
} else {
$yum_repo_url = $::operatingsystem ? {
/(RedHat|redhat|CentOS|centos)/ => "${base_url}/${repo_name}/el/${majrel}/${::architecture}/",
/(OracleLinux|OEL)/ => "${base_url}/${repo_name}/ol/${majrel}/${::architecture}/",
'Scientific' => "${base_url}/${repo_name}/scientific/${majrel}/${::architecture}/",
}
$gpg_url = "${base_url}/${repo_name}/gpgkey"
}
$description = $normalized_name
$repo_url = $::operatingsystem ? {
/(RedHat|redhat|CentOS|centos|Scientific|OracleLinux|OEL)/ => $yum_repo_url,
'Fedora' => "${base_url}/${repo_name}/fedora/${majrel}/${::architecture}/",
'Amazon' => "${base_url}/${repo_name}/el/6/${::architecture}",
}
file { $normalized_name:
ensure => file,
path => "/etc/yum.repos.d/${normalized_name}.repo",
mode => '0644',
content => template('packagecloud/yum.erb'),
}
exec { "yum_make_cache_${repo_name}":
command => "yum -q makecache -y --disablerepo='*' --enablerepo='${normalized_name}'",
path => '/usr/bin',
require => File[$normalized_name],
}
}
default: {
fail("Sorry, ${::operatingsystem} isn't supported for yum repos at this time. Email support@packagecloud.io")
}
}
}
default: {
fail("Sorry, ${type} isn't a supported repository type in this module right now. Email support@packagecloud.io")
}
}
}