Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Adding cookie support to allow for oracle java download #69

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 217 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ Usage
Example:

archive { 'apache-tomcat-6.0.26':
"../README.md" 112L, 3378C 1,1 Top
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this?


archive { 'apache-tomcat-6.0.26':
ensure => present,
url => 'http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.26/bin/apache-tomcat-6.0.26.tar.gz',
target => '/opt',
Expand Down Expand Up @@ -57,6 +60,205 @@ You can specify a ```digest_url```, ```digest_string``` and ```digest_type``` to

For `.tar.gz` and `tar.bz2` archives, the extract step's `--strip-components=n` flag can be accessed. This can be used to [change the name of the extracted directory](http://unix.stackexchange.com/questions/11018/how-to-choose-directory-name-during-untarring).

```
strip_components => 1
49,0-1 37%
strip_components => 1
```

```
purge_target => false
```

By default the target directory is left intact, this option can be used to `rm -rf` the target directory prior to extraction.

This full example will download the [packer](packer.io) tool to ```/usr/local/bin```:

```
archive { '0.5.1_linux_amd64':
ensure => present,
url => 'https://dl.bintray.com/mitchellh/packer/0.5.1_linux_amd64.zip',
target => '/usr/local/bin',
follow_redirects => true,
extension => 'zip',
checksum => false,
src_target => '/tmp'
}
```

You can also specifiy a global user to be used for the whole download and extract operation. Note that the module doesn't handle the right of the specified user on the src_target directory.
```

archive { '0.5.1_linux_amd64':
ensure => present,
url => 'https://dl.bintray.com/mitchellh/packer/0.5.1_linux_amd64.zip',
target => '/usr/local/bin',
follow_redirects => true,
search hit BOTTOM, continuing at TOP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this?

Overview
--------

Puppet Module to download and extract tar and zip archives based on [camptocamp/puppet-archive](https://github.com/camptocamp/puppet-archive).

Supported archive types are:

- `tar.gz`, `tgz`
- `tar.bz2`, `tbz2`
- `tar.xz`, `txz`
- `zip`

Features:

- Ability to follow redirects
- Supports checksum matching

Usage
-----

Example:

archive { 'apache-tomcat-6.0.26':
ensure => present,
url => 'http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.26/bin/apache-tomcat-6.0.26.tar.gz',
target => '/opt',
}

You can have archive follow redirects by setting:

```
follow_redirects => true
/follow

```
purge_target => false
```

By default the target directory is left intact, this option can be used to `rm -rf` the target directory prior to extraction.

This full example will download the [packer](packer.io) tool to ```/usr/local/bin```:

```
archive { '0.5.1_linux_amd64':
ensure => present,
url => 'https://dl.bintray.com/mitchellh/packer/0.5.1_linux_amd64.zip',
target => '/usr/local/bin',
follow_redirects => true,
extension => 'zip',
checksum => false,
src_target => '/tmp'
}
```

You can also specifiy a global user to be used for the whole download and extract operation. Note that the module doesn't handle the right of the specified user on the src_target directory.
```

archive { '0.5.1_linux_amd64':
ensure => present,
url => 'https://dl.bintray.com/mitchellh/packer/0.5.1_linux_amd64.zip',
target => '/usr/local/bin',
follow_redirects => true,
extension => 'zip',
checksum => false,
search hit BOTTOM, continuing at TOP
true => '-k',
default => '',
}

$redirect_arg = $follow_redirects ? {
true => '-L',
default => '',
}

$cookie_arg = $allow_cookie ? {
true => "-H \"Cookie: $cookie_value\"",
default => '',
}

if !defined(Package['curl']) {
package{'curl':
ensure => present,
}
}

if $proxy_server {
$proxy_option = "--proxy ${proxy_server}"
} else {
$proxy_option = undef
}

vagrant@vagrantvlc:/etc/puppet/modules/archive/manifests$ ls
download.pp extract.pp init.pp tar_gz.pp zip.pp
vagrant@vagrantvlc:/etc/puppet/modules/archive/manifests$ vi tar_gz.pp
vagrant@vagrantvlc:/etc/puppet/modules/archive/manifests$ less ../README.md
vagrant@vagrantvlc:/etc/puppet/modules/archive/manifests$ vi ../README.md
vagrant@vagrantvlc:/etc/puppet/modules/archive/manifests$ sudo vi ../README.md
vagrant@vagrantvlc:/etc/puppet/modules/archive/manifests$ cat ../README.md
Archive Puppet Module
====================

[![Puppet Forge Version](http://img.shields.io/puppetforge/v/camptocamp/archive.svg)](https://forge.puppetlabs.com/camptocamp/archive)
[![Puppet Forge Downloads](http://img.shields.io/puppetforge/dt/camptocamp/archive.svg)](https://forge.puppetlabs.com/camptocamp/archive)
[![Build Status](https://img.shields.io/travis/camptocamp/puppet-archive/master.svg)](https://travis-ci.org/camptocamp/puppet-archive)
[![Gemnasium](https://img.shields.io/gemnasium/camptocamp/puppet-archive.svg)](https://gemnasium.com/camptocamp/puppet-archive)
[![By Camptocamp](https://img.shields.io/badge/by-camptocamp-fb7047.svg)](http://www.camptocamp.com)

Overview
--------

Puppet Module to download and extract tar and zip archives based on [camptocamp/puppet-archive](https://github.com/camptocamp/puppet-archive).

Supported archive types are:

- `tar.gz`, `tgz`
- `tar.bz2`, `tbz2`
- `tar.xz`, `txz`
- `zip`

Features:

- Ability to follow redirects
- Supports checksum matching

Usage
-----

Example:

archive { 'apache-tomcat-6.0.26':
ensure => present,
url => 'http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.26/bin/apache-tomcat-6.0.26.tar.gz',
target => '/opt',
}

You can have archive follow redirects by setting:

```
follow_redirects => true
````

You can set and use prepared cookies using the settings:

```
allow_cookie => true
cookie_value => 'some-licence=accept-cookie'
````

The default archive format is ```tar.gz```. To use another supported format you must specify the extenstion:

```
extension => "zip"
```

By default archive will try and find a matching checksum file to verify the download. To disable this behavior set the ```checksum``` option to ```false```:

```
checksum => false
```

You can specify a ```digest_url```, ```digest_string``` and ```digest_type``` to verify archive integrity.

For `.tar.gz` and `tar.bz2` archives, the extract step's `--strip-components=n` flag can be accessed. This can be used to [change the name of the extracted directory](http://unix.stackexchange.com/questions/11018/how-to-choose-directory-name-during-untarring).

```
strip_components => 1
```
Expand Down Expand Up @@ -96,6 +298,21 @@ archive { '0.5.1_linux_amd64':
}
```

To download oracle java with the approved cookie, you can use the following:
```

archive { 'jdk-8u91-linux-x64':
url => 'http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.tar.gz',
target => '/usr/java',
digest_string => '3f3d7d0cd70bfe0feab382ed4b0e45c0',
digest_type => 'md5',
cookie_value=>'oraclelicense=accept-securebackup-cookie',
allow_cookie=>true,
follow_redirects => true,
}

```

License
-------

Expand Down
16 changes: 13 additions & 3 deletions manifests/download.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# - *$verbose: Default value true.
# - *$proxy_server: Default value undef.
# - *$user: The user used to download the archive
# - *$cookie: The cookie used to download the archive: Default is none
# - *$allow_cookie: use custom cookie
# - *$cookie_value: cookie string
#
# Example usage:
#
Expand Down Expand Up @@ -44,6 +47,8 @@
$path=$::path,
$proxy_server=undef,
$user=undef,
$cookie_value=undef,
$allow_cookie=false,
) {

$insecure_arg = $allow_insecure ? {
Expand All @@ -56,6 +61,11 @@
default => '',
}

$cookie_arg = $allow_cookie ? {
true => "-H \"Cookie: $cookie_value\"",
default => '',
}

if !defined(Package['curl']) {
package{'curl':
ensure => present,
Expand Down Expand Up @@ -113,9 +123,8 @@
$digest_src = $digest_url
}


exec {"download digest of archive ${name}":
command => "curl ${proxy_option} -s -S ${insecure_arg} ${redirect_arg} -o ${src_target}/${name}.${digest_type} '${digest_src}'",
command => "curl ${proxy_option} -s -S ${cookie_arg} ${insecure_arg} ${redirect_arg} -o ${src_target}/${name}.${digest_type} '${digest_src}'",
creates => "${src_target}/${name}.${digest_type}",
timeout => $timeout,
path => $path,
Expand Down Expand Up @@ -158,8 +167,9 @@
true => true,
default => undef,
}

exec {"download archive ${name} and check sum":
command => "curl ${proxy_option} -s -S ${insecure_arg} ${redirect_arg} -o ${src_target}/${name} '${url}'",
command => "curl ${proxy_option} -s -S ${cookie_arg} ${insecure_arg} ${redirect_arg} -o ${src_target}/${name} '${url}'",
creates => "${src_target}/${name}",
logoutput => true,
timeout => $timeout,
Expand Down
6 changes: 6 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# - *$strip_components: Default value 0
# - *$proxy_server: Default value undef
# - *$user: User used to do the download and the extraction. The final directory will be used by him/her.
# - *$allow_cookie: use custom cookie
# - *$cookie_value: cookie string
#
# Example usage:
#
Expand Down Expand Up @@ -50,6 +52,8 @@
$purge_target=false,
$user=undef,
$tar_command=undef,
$cookie_value=undef,
$allow_cookie=false,
) {

archive::download {"${name}.${extension}":
Expand All @@ -66,6 +70,8 @@
verbose => $verbose,
proxy_server => $proxy_server,
user => $user,
cookie_value => $cookie_value,
allow_cookie => $allow_cookie,
}

archive::extract {$name:
Expand Down