├── .ruby-version ├── test └── cookbooks │ └── nvm_test │ ├── recipes │ ├── default.rb │ ├── nvm_install_global.rb │ ├── nvm_alias_default.rb │ ├── nvm_install_from_source.rb │ └── nvm_install_user.rb │ ├── files │ └── default │ │ └── tests │ │ └── minitest │ │ ├── support │ │ └── helpers.rb │ │ ├── default_test.rb │ │ ├── nvm_install_test.rb │ │ ├── nvm_alias_default_test.rb │ │ └── nvm_install_from_source_test.rb │ └── metadata.rb ├── Berksfile ├── .gitignore ├── .travis.yml ├── Strainerfile ├── Rakefile ├── Gemfile ├── templates └── default │ └── nvm.sh.erb ├── metadata.rb ├── Berksfile.lock ├── resources ├── alias_default.rb └── install.rb ├── attributes └── default.rb ├── .kitchen.yml ├── recipes └── default.rb ├── providers ├── alias_default.rb └── install.rb ├── README.md └── LICENCE /.ruby-version: -------------------------------------------------------------------------------- 1 | 1.9.3-p392 -------------------------------------------------------------------------------- /test/cookbooks/nvm_test/recipes/default.rb: -------------------------------------------------------------------------------- 1 | include_recipe 'nvm' -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | site :opscode 2 | 3 | metadata 4 | 5 | cookbook "apt" 6 | cookbook "minitest-handler", "~> 0.2.1" 7 | cookbook "nvm_test", :path => "test/cookbooks/nvm_test" -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle 2 | bin 3 | .chef/checksums 4 | cookbook_test 5 | metadata.json 6 | .vagrant 7 | vendor.kitchen/ 8 | .kitchen 9 | *.tar.gz 10 | Gemfile.lock 11 | npm-debug.lock 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | gemfile: 2 | - Gemfile 3 | language: ruby 4 | rvm: 5 | - 1.9.3 6 | bundler_args: --without integration 7 | before_script: bundle exec berks install 8 | script: bundle exec rake cookbook:test 9 | -------------------------------------------------------------------------------- /Strainerfile: -------------------------------------------------------------------------------- 1 | knife test: bundle exec knife cookbook test $COOKBOOK 2 | foodcritic: bundle exec foodcritic --epic-fail any -t ~FC021 -t ~FC034 $SANDBOX/$COOKBOOK 3 | chefspec: bundle exec rspec $SANDBOX/$COOKBOOK 4 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake' 2 | require 'cookbook-development/tasks' 3 | 4 | COOKBOOK_NAME = "nvm" 5 | PACKAGE_DIR = File.dirname(__FILE__) # where to put the compressed cookbook bundle 6 | 7 | task :default => 'cookbook:test' 8 | 9 | -------------------------------------------------------------------------------- /test/cookbooks/nvm_test/files/default/tests/minitest/support/helpers.rb: -------------------------------------------------------------------------------- 1 | module Helpers 2 | 3 | module CookbookTest 4 | include MiniTest::Chef::Assertions 5 | include MiniTest::Chef::Context 6 | include MiniTest::Chef::Resources 7 | end 8 | 9 | end -------------------------------------------------------------------------------- /test/cookbooks/nvm_test/recipes/nvm_install_global.rb: -------------------------------------------------------------------------------- 1 | include_recipe 'nvm' 2 | 3 | version = 'v0.10.5' 4 | node.set['nvm']['nvm_install_test']['version'] = version 5 | 6 | nvm_install version do 7 | from_source false 8 | alias_as_default true 9 | action :create 10 | end -------------------------------------------------------------------------------- /test/cookbooks/nvm_test/metadata.rb: -------------------------------------------------------------------------------- 1 | name "nvm_test" 2 | maintainer "HipSnip Limited" 3 | maintainer_email "remy@hipsnip.com" 4 | license "Apache 2.0" 5 | description "Installs nvm, the node version manager" 6 | version "0.1.0" 7 | 8 | depends "nvm" -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gem "rake", "~> 10.1.0" 4 | gem "berkshelf", "~> 2.0.9" 5 | gem "json" 6 | gem "minitest-chef-handler", "~> 1.0.1", :group => :integration 7 | gem "kitchen-vagrant", "~> 0.11.0", :group => :integration 8 | gem "cookbook-development", :github => "hipsnip-cookbooks/cookbook-development" 9 | -------------------------------------------------------------------------------- /test/cookbooks/nvm_test/recipes/nvm_alias_default.rb: -------------------------------------------------------------------------------- 1 | include_recipe 'nvm' 2 | 3 | version = 'v0.10.2' 4 | node.set['nvm']['nvm_alias_default_test']['version'] = version 5 | 6 | nvm_install version do 7 | from_source false 8 | alias_as_default false 9 | action :create 10 | end 11 | 12 | nvm_alias_default version do 13 | action :create 14 | end -------------------------------------------------------------------------------- /test/cookbooks/nvm_test/recipes/nvm_install_from_source.rb: -------------------------------------------------------------------------------- 1 | node.set['nvm']['install_deps_to_build_from_source'] = true 2 | 3 | include_recipe 'nvm' 4 | 5 | version = 'v0.10.0' 6 | node.set['nvm']['nvm_install_from_source_test']['version'] = version 7 | 8 | nvm_install version do 9 | from_source true 10 | alias_as_default true 11 | action :create 12 | end -------------------------------------------------------------------------------- /templates/default/nvm.sh.erb: -------------------------------------------------------------------------------- 1 | # Generated by Chef for <%= node['fqdn'] %> 2 | # Local modifications will be overridden 3 | 4 | <% if @user_install %> 5 | if [ -f "${HOME}/.nvm/nvm.sh" ]; then 6 | . "${HOME}/.nvm/nvm.sh" 7 | fi 8 | <% else %> 9 | if [ -f "<%= node['nvm']['directory'] %>/nvm.sh" ]; then 10 | . "<%= node['nvm']['directory'] %>/nvm.sh" 11 | fi 12 | <% end %> 13 | -------------------------------------------------------------------------------- /test/cookbooks/nvm_test/files/default/tests/minitest/default_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../support/helpers', __FILE__) 2 | 3 | describe_recipe "nvm_test::default" do 4 | include Helpers::CookbookTest 5 | 6 | it "should install libcurl3" do 7 | assert_sh "dpkg -s libcurl3 2>&1" 8 | end 9 | 10 | it "should install curl" do 11 | assert_sh "dpkg -s curl 2>&1" 12 | end 13 | 14 | end 15 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name "nvm" 2 | version "0.1.7" 3 | maintainer "Philip Hutchins" 4 | maintainer_email "flipture@gmail.com" 5 | license "Apache 2.0" 6 | description "Installs nvm, the node version manager" 7 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 8 | supports 'ubuntu', ">= 12.04" 9 | supports 'centos', ">= 6.5" 10 | 11 | depends "build-essential" 12 | depends "git" 13 | -------------------------------------------------------------------------------- /test/cookbooks/nvm_test/recipes/nvm_install_user.rb: -------------------------------------------------------------------------------- 1 | version = 'v0.10.5' 2 | node.set['nvm']['nvm_install_test']['version'] = version 3 | 4 | user 'testuser' do 5 | shell '/bin/bash' 6 | supports :manage_home => true 7 | home '/home/testuser' 8 | action :create 9 | end 10 | 11 | include_recipe 'nvm' 12 | 13 | nvm_install version do 14 | from_source false 15 | user 'testuser' 16 | alias_as_default true 17 | action :create 18 | end 19 | -------------------------------------------------------------------------------- /test/cookbooks/nvm_test/files/default/tests/minitest/nvm_install_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../support/helpers', __FILE__) 2 | 3 | describe_recipe "nvm_test::nvm_install" do 4 | include Helpers::CookbookTest 5 | 6 | it "should have correctly installed nvm" do 7 | assert_sh "/bin/bash --login -c 'nvm help' 2>&1" 8 | end 9 | 10 | it "should have installed node" do 11 | assert_sh "/bin/bash --login -c 'node -v' 2>&1" 12 | end 13 | 14 | it "should have installed the given node.js version" do 15 | stdout = `/bin/bash --login -c 'node -v'` 16 | stdout = stdout.sub(/\n/,'') 17 | assert_equal(node['nvm']['nvm_install_test']['version'],stdout) 18 | end 19 | 20 | end -------------------------------------------------------------------------------- /test/cookbooks/nvm_test/files/default/tests/minitest/nvm_alias_default_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../support/helpers', __FILE__) 2 | 3 | describe_recipe "nvm_test::nvm_install" do 4 | include Helpers::CookbookTest 5 | 6 | it "should have correctly installed nvm" do 7 | assert_sh "/bin/bash --login -c 'nvm help' 2>&1" 8 | end 9 | 10 | it "should have installed node" do 11 | assert_sh "/bin/bash --login -c 'node -v' 2>&1" 12 | end 13 | 14 | it "should have installed the given node.js version" do 15 | stdout = `/bin/bash --login -c 'node -v'` 16 | stdout = stdout.sub(/\n/,'') 17 | assert_equal(node['nvm']['nvm_alias_default_test']['version'],stdout) 18 | end 19 | 20 | end -------------------------------------------------------------------------------- /test/cookbooks/nvm_test/files/default/tests/minitest/nvm_install_from_source_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../support/helpers', __FILE__) 2 | 3 | describe_recipe "nvm_test::nvm_install" do 4 | include Helpers::CookbookTest 5 | 6 | it "should have correctly installed nvm" do 7 | assert_sh "/bin/bash --login -c 'nvm help' 2>&1" 8 | end 9 | 10 | it "should have installed node" do 11 | assert_sh "/bin/bash --login -c 'node -v' 2>&1" 12 | end 13 | 14 | it "should have installed the given node.js version" do 15 | stdout = `/bin/bash --login -c 'node -v'` 16 | stdout = stdout.sub(/\n/,'') 17 | assert_equal(node['nvm']['nvm_install_from_source_test']['version'],stdout) 18 | end 19 | 20 | end -------------------------------------------------------------------------------- /Berksfile.lock: -------------------------------------------------------------------------------- 1 | { 2 | "sources": { 3 | "nvm": { 4 | "path": "." 5 | }, 6 | "apt": { 7 | "locked_version": "2.9.2" 8 | }, 9 | "minitest-handler": { 10 | "locked_version": "0.2.1" 11 | }, 12 | "nvm_test": { 13 | "path": "./test/cookbooks/nvm_test" 14 | }, 15 | "build-essential": { 16 | "locked_version": "2.2.4" 17 | }, 18 | "git": { 19 | "locked_version": "4.3.4" 20 | }, 21 | "dmg": { 22 | "locked_version": "2.3.0" 23 | }, 24 | "windows": { 25 | "locked_version": "1.38.2" 26 | }, 27 | "chef_handler": { 28 | "locked_version": "1.2.0" 29 | }, 30 | "yum-epel": { 31 | "locked_version": "0.6.4" 32 | }, 33 | "yum": { 34 | "locked_version": "3.8.2" 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /resources/alias_default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: nvm 3 | # Provider:: nvm_alias_default 4 | # 5 | # Copyright 2013, HipSnip Limited 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | actions :create 21 | default_action :create 22 | 23 | attribute :version, :kind_of => String, :name_attribute => true 24 | attribute :user, :kind_of => String 25 | attribute :user_home, :kind_of => String 26 | attribute :nvm_directory, :kind_of => String, :default => node['nvm']['directory'] 27 | attribute :group, :kind_of => String 28 | -------------------------------------------------------------------------------- /resources/install.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: nvm 3 | # Resource:: nvm_install 4 | # 5 | # Copyright 2013, HipSnip Limited 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | actions :create 21 | default_action :create 22 | 23 | attribute :from_source, :kind_of => [TrueClass, FalseClass], :default => false 24 | attribute :alias_as_default, :kind_of => [TrueClass, FalseClass], :default => false 25 | attribute :user, :kind_of => String 26 | attribute :group, :kind_of => String 27 | attribute :user_install, :kind_of => [TrueClass, FalseClass], :default => false 28 | attribute :version, :kind_of => String, :name_attribute => true 29 | attribute :nvm_directory, :kind_of => String, :default => node['nvm']['directory'] 30 | attribute :user_home, :kind_of => String 31 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: nvm 3 | # Recipe:: default 4 | # 5 | # Copyright 2013, HipSnip Limited 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | # If user install is true, nvm will be installed in the home directory of 21 | # the user configured in node['nvm']['user']. If false, the directory 22 | # attribute will be used. 23 | default['nvm']['user_install'] = false 24 | default['nvm']['user_home_dir'] = nil 25 | # Only used if user_install is false 26 | default['nvm']['directory'] = '/usr/local/src/nvm' 27 | default['nvm']['repository'] = 'git://github.com/creationix/nvm.git' 28 | default['nvm']['reference'] = 'master' 29 | default['nvm']['source'] = 'source /etc/profile.d/nvm.sh' 30 | default['nvm']['install_deps_to_build_from_source'] = true 31 | default['nvm']['user'] = 'root' 32 | default['nvm']['group'] = 'root' 33 | -------------------------------------------------------------------------------- /.kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver_plugin: vagrant 3 | driver_config: 4 | require_chef_omnibus: 11.6.0 5 | customize: 6 | memory: 1024 7 | 8 | platforms: 9 | - name: ubuntu-12.04 10 | driver_config: 11 | box: opscode-ubuntu-12.04-nochef 12 | box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box 13 | network: 14 | - ["private_network", {ip: "11.12.14.11"}] 15 | run_list: 16 | - recipe[apt] 17 | - name: centos-6.5 18 | driver_config: 19 | box: opscode_centos-6.5_chef 20 | box_url: http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box 21 | network: 22 | - ["private_network", {ip: "11.12.14.12"}] 23 | 24 | suites: 25 | - name: default 26 | run_list: 27 | - recipe[nvm_test::default] 28 | - recipe[minitest-handler] 29 | excludes: 30 | - centos-6.5 31 | 32 | - name: nvm-install-global 33 | run_list: 34 | - recipe[nvm_test::nvm_install_global] 35 | - recipe[minitest-handler] 36 | 37 | - name: nvm-alias-default 38 | run_list: 39 | - recipe[nvm_test::nvm_alias_default] 40 | - recipe[minitest-handler] 41 | 42 | - name: nvm-install-from-source 43 | run_list: 44 | - recipe[nvm_test::nvm_install_from_source] 45 | - recipe[minitest-handler] 46 | 47 | - name: nvm-install-user 48 | run_list: 49 | - recipe[nvm_test::nvm_install_user] 50 | - recipe[minitest-handler] 51 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: nvm 3 | # Recipe:: default 4 | # 5 | # Copyright 2013, HipSnip Limited 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | include_recipe 'git' 21 | 22 | ############################################################################ 23 | 24 | # Install dependencies 25 | case node['platform_family'] 26 | when 'debian' 27 | package 'libcurl3' do 28 | action :install 29 | end 30 | 31 | package 'curl' do 32 | action :install 33 | end 34 | 35 | if node['nvm']['install_deps_to_build_from_source'] 36 | package 'build-essential' do 37 | action :install 38 | end 39 | 40 | package 'libssl-dev' do 41 | action :install 42 | end 43 | end 44 | 45 | when 'rhel' 46 | if node['nvm']['install_deps_to_build_from_source'] 47 | include_recipe 'build-essential' 48 | end 49 | 50 | else 51 | Chef::Log.warn "Platform not supported." 52 | end 53 | -------------------------------------------------------------------------------- /providers/alias_default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: nvm 3 | # Provider:: nvm_alias_default 4 | # 5 | # Copyright 2013, HipSnip Limited 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | action :create do 21 | global_install = false 22 | user = new_resource.user 23 | group = new_resource.group 24 | user_home = new_resource.user_home 25 | if !new_resource.user 26 | global_install = true 27 | user = 'root' 28 | end 29 | 30 | if !new_resource.group 31 | group = 'root' 32 | end 33 | 34 | if !new_resource.user_home 35 | user_home = '/root' 36 | end 37 | 38 | script "Alias default node.js version to #{new_resource.version}..." do 39 | interpreter 'bash' 40 | user user 41 | group group 42 | environment Hash[ 'HOME' => user_home ] 43 | code <<-EOH 44 | export NVM_DIR=#{new_resource.nvm_directory} 45 | #{node['nvm']['source']} 46 | nvm alias default #{new_resource.version} 47 | EOH 48 | end 49 | new_resource.updated_by_last_action(true) 50 | end 51 | -------------------------------------------------------------------------------- /providers/install.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: nvm 3 | # Provider:: nvm_install 4 | # 5 | # Copyright 2013, HipSnip Limited 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | action :create do 21 | from_source_message = new_resource.from_source ? ' from source' : '' 22 | from_source_arg = new_resource.from_source ? '-s' : '' 23 | user_home = new_resource.user_home 24 | user_install = new_resource.user_install 25 | chef_nvm_user = 'root' 26 | chef_nvm_group = 'root' 27 | nvm_dir = new_resource.nvm_directory 28 | 29 | # If this is a user install... 30 | if new_resource.user 31 | user_install = true 32 | 33 | chef_nvm_user = new_resource.user 34 | chef_nvm_group = new_resource.group || new_resource.user 35 | 36 | # If the user is root, the home dir is non standard 37 | if chef_nvm_user == 'root' 38 | # If a user_home is defined for the root user, use that instead of the default root home location 39 | if user_home 40 | nvm_dir_base = user_home 41 | else 42 | # Otherwise use the standard 43 | nvm_dir_base = '/root' 44 | user_home = nvm_dir_base 45 | end 46 | else 47 | # If the user is not root 48 | nvm_dir_base = user_home || "/home/" + chef_nvm_user 49 | user_home = nvm_dir_base 50 | end 51 | nvm_dir = nvm_dir_base + "/.nvm" 52 | end 53 | 54 | directory nvm_dir do 55 | user chef_nvm_user 56 | group chef_nvm_group 57 | action :create 58 | end 59 | 60 | git nvm_dir do 61 | user chef_nvm_user 62 | group chef_nvm_group 63 | repository node['nvm']['repository'] 64 | reference node['nvm']['reference'] 65 | retries 5 66 | retry_delay 5 67 | action :sync 68 | not_if { ::File.exists?(nvm_dir + "/.git") } 69 | end 70 | 71 | template '/etc/profile.d/nvm.sh' do 72 | source 'nvm.sh.erb' 73 | mode 0755 74 | cookbook 'nvm' 75 | variables ({ 76 | :nvm_dir => nvm_dir, 77 | :user_install => user_install 78 | }) 79 | end 80 | 81 | script "Installing node.js #{new_resource.version}#{from_source_message}, as #{chef_nvm_user}:#{chef_nvm_group} from #{nvm_dir}" do 82 | interpreter 'bash' 83 | user chef_nvm_user 84 | group chef_nvm_group 85 | environment Hash['HOME' => user_home] 86 | code <<-EOH 87 | export NVM_DIR=#{nvm_dir} 88 | source /etc/profile.d/nvm.sh 89 | nvm install #{from_source_arg} #{new_resource.version} 90 | EOH 91 | end 92 | 93 | # break FC021: Resource condition in provider may not behave as expected 94 | # silly thing because new_resource.version is dynamic not fixed 95 | nvm_alias_default new_resource.version do 96 | user chef_nvm_user 97 | group chef_nvm_group 98 | user_home user_home 99 | nvm_directory nvm_dir 100 | action :create 101 | only_if { new_resource.alias_as_default } 102 | end 103 | new_resource.updated_by_last_action(true) 104 | end 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nvm 2 | 3 | Chef cookbook for setting up NVM from [creationix's github repository](https://github.com/creationix/nvm). 4 | 5 | ## Requirements 6 | 7 | Built to run on Linux distributions. Tested on Ubuntu 12.04. 8 | Depends on the `git` cookbook. 9 | 10 | ## Usage 11 | 12 | Install nvm and node.js version 0.10.5. 13 | 14 | ```ruby 15 | # install nvm 16 | include_recipe 'nvm' 17 | 18 | # install node.js v0.10.5 19 | nvm_install 'v0.10.5' do 20 | from_source false 21 | alias_as_default true 22 | action :create 23 | end 24 | ``` 25 | 26 | For more usage examples, have a look to the recipes in `test/cookbooks/nvm_test/recipes/`. 27 | 28 | ## Attributes 29 | 30 | * `node['nvm']['directory']` - directory where nvm is cloned, default '/usr/local/src/nvm' 31 | * `node['nvm']['repository']` - url of the git repository, default 'git://github.com/creationix/nvm.git' 32 | * `node['nvm']['reference']` - reference in the repository, default 'master' 33 | * `node['nvm']['source']` - command to source nvm script file, default 'source /etc/profile.d/nvm.sh' 34 | * `node['nvm']['install_deps_to_build_from_source']` - if true install the dependencies to compile node, otherwise not, default true 35 | 36 | ## LWRPs 37 | 38 | ### nvm_install 39 | 40 | Install a node.js version from source or binaries 41 | 42 | #### Actions 43 | 44 | - `create` (default) 45 | 46 | #### Attributes 47 | 48 | - `version` - node.js version, default to the name attribute 49 | - `from_source` - install from source if true, default to false 50 | - `alias_as_default` - alias the current version as the default version, default true 51 | 52 | ##### Only used for user install 53 | - `user_install` - install nvm for a particular user, default false 54 | - `user` - user to install nvm as, no default 55 | - `group` - group to install nvm as, defaults to user 56 | - `user_nome` - home directory of user for user install if it is a non standard home directory, default /home/$user 57 | - `nvm_directory` - 58 | 59 | #### Examples 60 | 61 | Install from binary 62 | 63 | ```ruby 64 | nvm_install '0.10.5' do 65 | from_source false 66 | alias_as_default true 67 | action :create 68 | end 69 | ``` 70 | 71 | Install from source 72 | 73 | ```ruby 74 | nvm_install '0.10.5' do 75 | from_source true 76 | alias_as_default true 77 | action :create 78 | end 79 | ``` 80 | 81 | Install as user 82 | 83 | ```ruby 84 | nvm_install '0.10.5' do 85 | user 'myuser' 86 | group 'mygroup' 87 | from_source false 88 | alias_as_default true 89 | action :create 90 | end 91 | ``` 92 | 93 | Multiple user installs 94 | 95 | ```ruby 96 | nvm_install 'nvm for userone' do 97 | version '0.10.5' 98 | user 'userone' 99 | group 'userone' 100 | from_source false 101 | alias_as_default true 102 | action :create 103 | end 104 | ``` 105 | 106 | ```ruby 107 | nvm_install 'nvm for usertwo' do 108 | version '0.10.5' 109 | user 'usertwo' 110 | group 'usertwo' 111 | from_source false 112 | alias_as_default true 113 | action :create 114 | end 115 | ``` 116 | 117 | Nonstandard user home user install 118 | 119 | ```ruby 120 | nvm_install '0.10.5' do 121 | user 'usertwo' 122 | group 'usertwo' 123 | user_home '/opt/usertwo' 124 | from_source false 125 | alias_as_default true 126 | action :create 127 | end 128 | ``` 129 | 130 | 131 | ### nvm_alias_default 132 | 133 | Use by default the given node.js version 134 | 135 | #### Actions 136 | 137 | - `create` (default) 138 | 139 | #### Attributes 140 | 141 | - `version` - node.js version, default to the name attribute 142 | 143 | #### Example 144 | 145 | Use by default node.js version 0.10.0 146 | 147 | ```ruby 148 | nvm_alias_default '0.10.0' do 149 | action :create 150 | end 151 | ``` 152 | 153 | ## Cookbook development 154 | 155 | You will need to do a couple of things to be up to speed to hack on this cookbook. 156 | Everything is explained [here](https://github.com/hipsnip-cookbooks/cookbook-development) have a look. 157 | 158 | ## Test 159 | 160 | ```bash 161 | bundle exec rake cookbook:full_test 162 | ``` 163 | 164 | ## Licence 165 | 166 | Author: Rémy Loubradou 167 | 168 | Copyright 2013 HipSnip Limited 169 | 170 | Licensed under the Apache License, Version 2.0 (the "License"); 171 | you may not use this file except in compliance with the License. 172 | You may obtain a copy of the License at 173 | 174 | http://www.apache.org/licenses/LICENSE-2.0 175 | 176 | Unless required by applicable law or agreed to in writing, software 177 | distributed under the License is distributed on an "AS IS" BASIS, 178 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 179 | See the License for the specific language governing permissions and 180 | limitations under the License. 181 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------