Skip to content

Commit

Permalink
Merge branch 'COOK-457'
Browse files Browse the repository at this point in the history
  • Loading branch information
schisamo committed Feb 11, 2011
2 parents 3c8ce88 + a71a955 commit 311f416
Show file tree
Hide file tree
Showing 14 changed files with 894 additions and 0 deletions.
120 changes: 120 additions & 0 deletions transmission/README.md
@@ -0,0 +1,120 @@
Description
===========

Installs the [Transmission BitTorrent Client](http://transmissionbt.org) and includes a `transmission_torrent_file` LWRP.

Requirements
============

Platform
--------

Known to work on Debian, Ubuntu, Red Hat and CentOS

Cookbooks
---------

* build-essential - for compiling the source.
* openssl - for generating a secure password.

Attributes
==========

* `node["transmission"]["rpc_bind_address"]` - Where to listen for RPC connections, default `0.0.0.0`.
* `node["transmission"]["rpc_port"]` - The port Transmission listens on for remote services, default `9091`.
* `node["transmission"]["rpc_username"]` - The username required to access remote services, default `transmission`.
* `node["transmission"]["rpc_password"]` - The ssha1 encrypted password, default generated by `secure_password`.
* `node["transmission"]["home"]` - Transmission's home directory, default `/var/lib/transmission-daemon`.
* `node["transmission"]["config_dir"]` - Transmission's config directory, default `/var/lib/transmission-daemon/info`.
* `node["transmission"]["download_dir"]` - Directory to move complete files to, default `/var/lib/transmission-daemon/downloads`.
* `node["transmission"]["incomplete_dir"]` - Directory to keep incomplete files in, default `/var/lib/transmission-daemon/incomplete`.

The file also contains the following attribute types:

* platform specific locations and settings.
* source installation settings

Resource/Provider
=================

`transmission_torrent_file`
---------------------------

Download a file via the [BitTorrent protocol](http://en.wikipedia.org/wiki/BitTorrent). The usage semantics are like that of the existing [file](http://wiki.opscode.com/display/chef/Resources#Resources-File) and [remote_file](http://wiki.opscode.com/display/chef/Resources#Resources-RemoteFile) resources. This allows very fast downloads for files that are part of large BitTorrent swarms. The Ubuntu 10.04 LTS ISO (around 700MB) downloads in about 50 seconds.

# Actions

- :create: Download a file via the BitTorrent protocol

# Attribute Parameters

- path: name attribute. the path to the file
- torrent: torrent file of the swarm to join. can either be a url or local file path
- blocking: should the file be downloaded in a blocking way? If `true` Chef will download the file in a single Chef run, if `false` Chef will check for a completed download during each Chef run until the download is complete. default is `true`.
- continue_seeding: should the file continue to be seeded to the swarm after download? default is `false`.
- owner: The owner for the file
- group: The group owner of the file (string or id)
- rpc_host: the address of the Transmission RPC host to connect to. default is `9091`.
- rpc_port: the port of the Transmission RPC host to connect to. default is `localhost`.
- rpc_username: the username of the Transmission RPC account. default is `transmission`.
- rpc_password: the password of the Transmission RPC account . should probably be `node['transmission']['rpc_password']` which by default is a secure password generated for this node.

# Example

# download the lucid iso
transmission_torrent_file "/home/ubuntu/ubuntu.iso" do
torrent "http://releases.ubuntu.com/lucid/ubuntu-10.04.1-server-i386.iso.torrent"
owner 'ubuntu'
group 'ubuntu'
rpc_username node['transmission']['rpc_username']
rpc_password node['transmission']['rpc_password']
action :create
end

# do the same thing but continue seeding after download
transmission_torrent_file "/home/ubuntu/ubuntu.iso" do
torrent "http://releases.ubuntu.com/lucid/ubuntu-10.04.1-server-i386.iso.torrent"
owner 'ubuntu'
group 'ubuntu'
continue_seeding true
rpc_username node['transmission']['rpc_username']
rpc_password node['transmission']['rpc_password']
action :create
end

Usage
=====

default
-------

Include default recipe in a run list, to get some Transmission installed. Installs Transmission by package or source depending on the platform.

package
-------

Installs Transmission from packages. This should only be loaded by the default recipe.

source
------

Installs Transmission from source. This should only be loaded by the default recipe.

License and Author
==================

Author: Seth Chisamore (<schisamo@opscode.com>)

Copyright 2011, Opscode, Inc.

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.
45 changes: 45 additions & 0 deletions transmission/attributes/default.rb
@@ -0,0 +1,45 @@
#
# Author:: Seth Chisamore (<schisamo@opscode.com>)
# Cookbook Name:: transmission
# Attribute:: default
#
# Copyright 2011, Opscode, Inc.
#
# 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.

::Chef::Node.send(:include, Opscode::OpenSSL::Password)

case node['platform']
when "ubuntu","debian"
default['transmission']['install_method'] = 'package'
default['transmission']['user'] = 'debian-transmission'
default['transmission']['group'] = 'debian-transmission'
else
default['transmission']['install_method'] = 'source'
default['transmission']['user'] = 'transmission'
default['transmission']['group'] = 'transmission'
end

default['transmission']['url'] = 'http://download.transmissionbt.com/files'
default['transmission']['version'] = '2.03'
default['transmission']['checksum'] = '06802c6f4ba517341eb287b273145ccd5e7b0fba2a270da82f0eb0a683cf4046'

default['transmission']['rpc_bind_address'] = '0.0.0.0'
default['transmission']['rpc_username'] = 'transmission'
set_unless['transmission']['rpc_password'] = secure_password
default['transmission']['rpc_port'] = 9091

default['transmission']['home'] = '/var/lib/transmission-daemon'
default['transmission']['config_dir'] = '/var/lib/transmission-daemon/info'
default['transmission']['download_dir'] = '/var/lib/transmission-daemon/downloads'
default['transmission']['incomplete_dir'] = '/var/lib/transmission-daemon/incomplete'
93 changes: 93 additions & 0 deletions transmission/libraries/torrent.rb
@@ -0,0 +1,93 @@
#
# Author:: Seth Chisamore (<schisamo@opscode.com>)
# Cookbook Name:: transmission
# Library:: torrent
#
# Copyright:: 2011, Opscode, Inc <legal@opscode.com>
#
# 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.
#

begin
require 'ostruct'
require 'transmission-simple'
rescue LoadError
end

# all your monkey patches are belong to us
module TransmissionSimple
class Torrent < OpenStruct

STATUS_CODES = {
1 => 'CHECK_WAIT',
2 => 'CHECK',
4 => 'DOWNLOAD',
8 => 'SEED',
16 => 'STOPPED'
}

def downloading?
self.status == STATUS_CODES.index('DOWNLOAD')
end

def stopped?
self.status == STATUS_CODES.index('STOPPED')
end

def checking?
self.status == STATUS_CODES.index('CHECK') || self.status == STATUS_CODES.index('CHECK_WAIT')
end

def seeding?
self.status == STATUS_CODES.index('SEED')
end

def status_message
STATUS_CODES[self.status]
end
end
end

module Opscode
module Transmission
class Client
DEFAULT_RESPONSE_FIELDS = %w{id name status totalSize percentDone startDate hashString downloadDir files}

def initialize(endpoint)
@transmission = TransmissionSimple::Api.new(endpoint)
end

def get_torrent(torrent_hash)
@transmission.send_request('torrent-get', {:ids => [torrent_hash], :fields => DEFAULT_RESPONSE_FIELDS}).first
end

def add_torrent(torrent_file)
t = @transmission.send_request('torrent-add', {:filename => torrent_file})["torrent-added"]
TransmissionSimple::Torrent.new(t)
end

def remove_torrent(torrent_hash, delete_data=false)
#@transmission.send_request('torrent-remove', {'ids' => [torrent_hash], 'delete-local-data' => delete_data})
@transmission.send_request('torrent-remove', {'ids' => [torrent_hash]})
end
end
end
end

# Ruby 1.8.6 doesn't have tap...thx CentOS
class Object
def tap
yield self
self
end
end
35 changes: 35 additions & 0 deletions transmission/metadata.json
@@ -0,0 +1,35 @@
{
"name": "transmission",
"description": "Installs/Configures transmission",
"long_description": "Description\n===========\n\nInstalls the [Transmission BitTorrent Client](http://transmissionbt.org) and includes a `transmission_torrent_file` LWRP.\n\nRequirements\n============\n\nPlatform\n--------\n\nKnown to work on Debian, Ubuntu, Red Hat and CentOS\n\nCookbooks\n---------\n\n* build-essential - for compiling the source.\n* openssl - for generating a secure password.\n\nAttributes\n==========\n\n* `node[\"transmission\"][\"rpc_bind_address\"]` - Where to listen for RPC connections, default `0.0.0.0`.\n* `node[\"transmission\"][\"rpc_port\"]` - The port Transmission listens on for remote services, default `9091`.\n* `node[\"transmission\"][\"rpc_username\"]` - The username required to access remote services, default `transmission`.\n* `node[\"transmission\"][\"rpc_password\"]` - The ssha1 encrypted password, default generated by `secure_password`.\n* `node[\"transmission\"][\"home\"]` - Transmission's home directory, default `/var/lib/transmission-daemon`.\n* `node[\"transmission\"][\"config_dir\"]` - Transmission's config directory, default `/var/lib/transmission-daemon/info`.\n* `node[\"transmission\"][\"download_dir\"]` - Directory to move complete files to, default `/var/lib/transmission-daemon/downloads`.\n* `node[\"transmission\"][\"incomplete_dir\"]` - Directory to keep incomplete files in, default `/var/lib/transmission-daemon/incomplete`.\n\nThe file also contains the following attribute types:\n\n* platform specific locations and settings.\n* source installation settings\n\nResource/Provider\n=================\n\n`transmission_torrent_file`\n---------------------------\n\nDownload a file via the [BitTorrent protocol](http://en.wikipedia.org/wiki/BitTorrent). The usage semantics are like that of the existing [file](http://wiki.opscode.com/display/chef/Resources#Resources-File) and [remote_file](http://wiki.opscode.com/display/chef/Resources#Resources-RemoteFile) resources. This allows very fast downloads for files that are part of large BitTorrent swarms. The Ubuntu 10.04 LTS ISO (around 700MB) downloads in about 50 seconds.\n\n# Actions\n\n- :create: Download a file via the BitTorrent protocol\n\n# Attribute Parameters\n\n- path: name attribute. the path to the file\n- torrent: torrent file of the swarm to join. can either be a url or local file path\n- blocking: should the file be downloaded in a blocking way? If `true` Chef will download the file in a single Chef run, if `false` Chef will check for a completed download during each Chef run until the download is complete. default is `true`.\n- continue_seeding: should the file continue to be seeded to the swarm after download? default is `false`.\n- owner: The owner for the file\n- group: The group owner of the file (string or id)\n- rpc_host: the address of the Transmission RPC host to connect to. default is `9091`.\n- rpc_port: the port of the Transmission RPC host to connect to. default is `localhost`.\n- rpc_username: the username of the Transmission RPC account. default is `transmission`.\n- rpc_password: the password of the Transmission RPC account . should probably be `node['transmission']['rpc_password']` which by default is a secure password generated for this node.\n\n# Example\n\n # download the lucid iso\n transmission_torrent_file \"/home/ubuntu/ubuntu.iso\" do\n torrent \"http://releases.ubuntu.com/lucid/ubuntu-10.04.1-server-i386.iso.torrent\"\n owner 'ubuntu'\n group 'ubuntu'\n rpc_username node['transmission']['rpc_username']\n rpc_password node['transmission']['rpc_password']\n action :create\n end\n \n # do the same thing but continue seeding after download\n transmission_torrent_file \"/home/ubuntu/ubuntu.iso\" do\n torrent \"http://releases.ubuntu.com/lucid/ubuntu-10.04.1-server-i386.iso.torrent\"\n owner 'ubuntu'\n group 'ubuntu'\n continue_seeding true\n rpc_username node['transmission']['rpc_username']\n rpc_password node['transmission']['rpc_password']\n action :create\n end\n\nUsage\n=====\n\ndefault\n-------\n\nInclude default recipe in a run list, to get some Transmission installed. Installs Transmission by package or source depending on the platform.\n\npackage\n-------\n\nInstalls Transmission from packages. This should only be loaded by the default recipe.\n\nsource\n------\n\nInstalls Transmission from source. This should only be loaded by the default recipe.\n\nLicense and Author\n==================\n\nAuthor: Seth Chisamore (<schisamo@opscode.com>)\n\nCopyright 2011, Opscode, Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
"maintainer": "Opscode, Inc.",
"maintainer_email": "cookbooks@opscode.com",
"license": "Apache 2.0",
"platforms": {
},
"dependencies": {
"openssl": [

],
"build-essential": [

]
},
"recommendations": {
},
"suggestions": {
},
"conflicting": {
},
"providing": {
},
"replacing": {
},
"attributes": {
},
"groupings": {
},
"recipes": {
},
"version": "0.99.0"
}
10 changes: 10 additions & 0 deletions transmission/metadata.rb
@@ -0,0 +1,10 @@
maintainer "Opscode, Inc."
maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
description "Installs/Configures transmission"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.99"

%w{ openssl build-essential }.each do |cb|
depends cb
end

0 comments on commit 311f416

Please sign in to comment.