Defined Type: tp::install::release
- Defined in:
- manifests/install/release.pp
Overview
This define installs the application (app) set in the given title downloading the relevant file or tarball. The define takes care of:
-
Downloading the app file from the Internet (if a specific source is not given, tinydata is used)
-
Extracting the file (if the file is an archive)
-
Eventually building sources
-
Eventually installing the app’s binary to destination path
-
Eventually create and manage the relevant service
This define is declared from the tp::install define when $install_method is set to ‘file’. You the tp::install argument ‘params’ to pass parameters to this define.
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 159 160 161 162 163 164 165 166 167 168 |
# File 'manifests/install/release.pp', line 42
define tp::install::release (
Variant[Boolean,String] $ensure = present,
Tp::Fail $on_missing_data = pick(getvar('tp::on_missing_data'),'notify'),
Hash $tp_params = pick($tp::tp_params, {}),
Hash $settings = {},
Boolean $auto_prereq = pick($tp::auto_prereq, false),
Optional[String] $version = undef,
Optional[String] $source = undef,
Optional[Stdlib::Absolutepath] $destination = undef,
String[1] $owner = pick(getvar('identity.user'),'root'),
String[1] $group = pick(getvar('identity.group'),'root'),
) {
$app = $title
$sane_app = regsubst($app, '/', '_', 'G')
$tp_dir = $tp::real_tp_params['conf']['path']
$destination_dir = $tp::real_tp_params['destination']['path']
$download_dir = "${tp::real_tp_params['data']['path']}/download/${app}"
$extract_dir = pick(getvar('settings.release.extract_dir'),"${tp::real_tp_params['data']['path']}/extract/${app}")
$real_destination = pick($destination, "${destination_dir}/${app}")
$retrieve_command = getvar('tp_params.settings.retrieve_command')
$retrieve_args = getvar('tp_params.settings.retrieve_args')
tp::create_dir { "tp::install::release - create_dir ${download_dir}":
path => $download_dir,
}
tp::create_dir { "tp::install::release - extract_dir ${extract_dir}":
path => $extract_dir,
}
# Automatic dependencies management, if data defined
if $auto_prereq and getvar('settings.release.prerequisites') and $ensure != 'absent' {
tp::create_everything ( getvar('settings.release.prerequisites'), {})
}
# Download and unpack source
$real_version = tp::get_version($ensure,$version,$settings)
$real_majversion = tp::get_version($ensure,$version,$settings,'major')
$real_filename = pick(tp::url_replace(pick(getvar('settings.release.file_name'),$app), $real_version, $real_majversion), $app) # lint:ignore:140chars
#$real_filename = tp::url_replace(pick(getvar('settings.release.file_name'), $app), $real_version, $real_majversion) # lint:ignore:140chars
if getvar('settings.release.base_url') {
$real_base_url = tp::url_replace(pick(getvar('settings.release.base_url'), $app), $real_version, $real_majversion)
$real_url = "${real_base_url}/${real_filename}"
} else {
tp::fail($on_missing_data, "tp::install::release - ${app} - Missing tinydata: settings.release.base_url") # lint:ignore:140chars
}
$real_source = $ensure ? {
'absent' => false,
default => pick_default($source, $real_url),
}
$extracted_dir = getvar('settings.release.extracted_dir') ? {
String => tp::url_replace(getvar('settings.release.extracted_dir'), $real_version, $real_majversion), # lint:ignore:140chars
default => tp::url_replace(basename($real_filename), $real_version, $real_majversion),
}
$extracted_file = getvar('settings.release.extracted_file')
if $real_source {
$source_filetype = pick(getvar('settings.release.file_format'),'zip')
$extract_command = getvar('tp_params.settings.extract_command') ? {
'' => $source_filetype ? {
'tgz' => 'tar -zxf',
'gz' => 'tar -zxf',
'tar.gz' => 'tar -zxf',
'xz' => 'tar -xvf',
'tar.xz' => 'tar -xvf',
'bz2' => 'tar -jxf',
'tar' => 'tar -xf',
'zip' => 'unzip',
'binary' => 'cp',
default => 'tar -zxf',
},
default => getvar('tp_params.settings.extract_command'),
}
$extract_command_second_arg = $extract_command ? {
/^cp.*/ => '.',
/^rsync.*/ => '.',
default => '',
}
$real_postextract_cwd = "${extract_dir}/${extracted_dir}"
Exec {
path => $facts['path'],
environment => pick(getvar('release.exec_environment'), []),
timeout => pick(getvar('release.exec_timout'),'600'),
}
exec { "Downloading ${title} from ${real_source} to ${download_dir}":
cwd => $download_dir,
command => "${retrieve_command} ${retrieve_args} ${real_source}",
creates => "${download_dir}/${real_filename}",
require => Tp::Create_dir["tp::install::release - create_dir ${download_dir}"],
}
if $extract_command {
$extract_creates = $extracted_dir ? {
'' => "${extract_dir}/${extracted_file}",
default => "${extract_dir}/${extracted_dir}",
}
exec { "Extract ${real_filename} from ${download_dir} - ${title}":
command => "mkdir -p ${extract_dir} && cd ${extract_dir} && ${extract_command} ${download_dir}/${real_filename} ${extract_command_second_arg}", # lint:ignore:140chars
creates => $extract_creates,
require => [Exec["Downloading ${title} from ${real_source} to ${download_dir}"], Tp::Create_dir["tp::install::release - extract_dir ${extract_dir}"]], # lint:ignore:140chars
notify => Exec["Chown ${real_filename} in ${extract_dir} - ${title}"],
before => Tp::Setup["tp::install::release ${app}"],
}
exec { "Chown ${real_filename} in ${extract_dir} - ${title}":
command => "chown -R ${owner}:${group} ${extract_dir}/${extracted_dir}",
refreshonly => true,
require => Exec["Extract ${real_filename} from ${download_dir} - ${title}"],
before => Tp::Setup["tp::install::release ${app}"],
}
}
} else {
tp::fail($on_missing_data, "tp::install::release ${app} - Missing parameter source or tinydata: settings.release.base_url, settings.release.[version].filename}") # lint:ignore:140chars
}
}
|