-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the inital code to comply with puppet module standards
* split the main class to install, uninstall.pp * use private variables wherever possible * introduce unit tests * improve the latest install to fetch last version
- Loading branch information
Showing
9 changed files
with
291 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'net/http' | ||
|
||
# @summary Fetches the last released Rclone version from internet | ||
# | ||
# @api private | ||
Puppet::Functions.create_function(:'rclone::last_version') do | ||
# @return [String] last released Rclone version | ||
def last_version | ||
uri = URI('https://downloads.rclone.org/version.txt') | ||
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| | ||
response = http.request Net::HTTP::Get.new(uri) | ||
response.body.gsub(%r{.*rclone v(\d+\.\d+\.\d+).*}, '\1') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# @summary Ensures Rclone installed | ||
# | ||
# @api private | ||
class rclone::install { | ||
|
||
$_os = $facts['os']['family'] ? { | ||
/(Debian|Ubuntu)/ => 'linux', | ||
default => fail("Unsupported OS family ${facts['os']['family']}"), | ||
} | ||
|
||
$_architecture = $facts['os']['architecture'] ? { | ||
/arm.*/ => 'arm', | ||
/(amd64|x86_64)/ => 'amd64', | ||
} | ||
|
||
$_version = $rclone::ensure ? { | ||
/latest/ => rclone::last_version(), | ||
default => $rclone::ensure, | ||
} | ||
|
||
$_download_path = '/tmp/rclone.zip' | ||
$_instance = "rclone-v${_version}-${_os}-${_architecture}" | ||
$_instance_binary = "${rclone::install_dir}/${_instance}/rclone" | ||
$_instance_man_page = "${rclone::install_dir}/${_instance}/rclone.1" | ||
|
||
if !defined(File['/opt']) { | ||
file { '/opt': | ||
ensure => directory, | ||
before => File[$rclone::install_dir], | ||
} | ||
} | ||
|
||
file { $rclone::install_dir: | ||
ensure => directory, | ||
} | ||
|
||
if !defined(File[$rclone::man_page_dir]) { | ||
file { $rclone::man_page_dir: | ||
ensure => directory, | ||
before => File[$rclone::man_page], | ||
} | ||
} | ||
|
||
archive { 'download rclone': | ||
path => $_download_path, | ||
extract_path => $rclone::install_dir, | ||
source => "https://downloads.rclone.org/v${_version}/${_instance}.zip", | ||
extract => true, | ||
cleanup => true, | ||
creates => $_instance_binary, | ||
require => File[$rclone::install_dir] | ||
} | ||
|
||
file { $_instance_binary: | ||
owner => 'root', | ||
mode => '0755', | ||
subscribe => Archive['download rclone'], | ||
} | ||
|
||
file { $rclone::binary: | ||
ensure => link, | ||
target => $_instance_binary, | ||
subscribe => Archive['download rclone'], | ||
} | ||
|
||
file { $rclone::man_page: | ||
ensure => link, | ||
target => $_instance_man_page, | ||
subscribe => Archive['download rclone'], | ||
notify => Exec['rclone mandb'], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# @summary Removes rclone installed by this module | ||
# | ||
# @api private | ||
class rclone::uninstall { | ||
|
||
file { "remove ${rclone::man_page}": | ||
ensure => absent, | ||
path => $rclone::man_page, | ||
notify => Exec['rclone mandb'], | ||
} | ||
|
||
file { "remove ${rclone::binary}": | ||
ensure => absent, | ||
path => $rclone::binary, | ||
} | ||
|
||
file { "remove ${rclone::install_dir}": | ||
ensure => absent, | ||
path => $rclone::install_dir, | ||
purge => true, | ||
recurse => true, | ||
force => true, | ||
} | ||
} |
Oops, something went wrong.