Permalink
Browse files

merge @nathenharvey's changes from origin/magic_shell_environment

  • Loading branch information...
Seth Vargo
Seth Vargo committed Nov 21, 2012
1 parent ec80782 commit 126db86f1a51852c07959847426ac0565ac0acbc
Showing with 72 additions and 17 deletions.
  1. +1 −0 .gitignore
  2. +4 −0 CHANGELOG.md
  3. +21 −3 README.md
  4. +1 −1 metadata.rb
  5. +10 −13 providers/alias.rb
  6. +29 −0 providers/environment.rb
  7. +6 −0 resources/environment.rb
View
@@ -0,0 +1 @@
+*.swp
View
@@ -1,5 +1,9 @@
magic_shell CHANGELOG
=====================
+0.2.0
+----
+
+* Add `magic_shell_environment`
0.1.5
----
View
@@ -14,10 +14,10 @@ None
Usage
-----
-Include the recipe to use the resource in your cookbook.
+Update the `metadata.rb` for your cookbook to depend on magic_shell
```ruby
-include_recipe 'magic_shell'
+depends 'magic_shell'
```
Use the `magic_shell_alias` resource to create a command alias.
@@ -28,6 +28,8 @@ magic_shell_alias 'myrailsapp' do
end
```
+This will alias `myrailsapp` to `cd /opt/myrailsapp/current`.
+
You can also remove aliases:
```ruby
@@ -36,7 +38,23 @@ magic_shell_alias 'myrailsapp' do
end
```
-This will alias `myrailsapp` to `cd /opt/myrailsapp/current`.
+Use the `magic_shell_environment` resource to create a shell environment variable.
+
+```ruby
+magic_shell_environment 'EDITOR' do
+ value 'vim'
+end
+```
+
+This will export an `EDITOR` environment variable with a value of `vim`.
+
+You can also remove environment variables:
+
+```ruby
+magic_shell_environment 'EDITOR' do
+ action :remove
+end
+```
Contributing
------------
View
@@ -3,4 +3,4 @@
license 'Apache 2.0'
description 'Installs/Configures command_alias'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
-version '0.1.5'
+version '0.2.0'
View
@@ -1,30 +1,27 @@
action :add do
- command_name = sanitize_to_command new_resource.alias_name
+ command_name = new_resource.alias_name.gsub(/ /,"_")
if !new_resource.command.nil?
Chef::Log.info("Adding #{command_name}.sh to /etc/profile.d/")
file_contents = "# This alias was generated by Chef for #{node["fqdn"]}\n"
file_contents += "alias #{command_name}='#{new_resource.command}'"
- file "/etc/profile.d/#{command_name}.sh" do
+ resource = file "/etc/profile.d/#{command_name}.sh" do
owner "root"
group "root"
mode "0755"
content file_contents
+ action :nothing
end
- new_resource.updated_by_last_action(true)
+ resource.run_action(:create)
+ new_resource.updated_by_last_action(true) if resource.updated_by_last_action?
end
end
action :remove do
- command_name = sanitize_to_command new_resource.alias_name
- if ::File.exists?("/etc/profile.d/#{command_name}.sh")
- Chef::Log.info("Removing #{command_name}.sh from /etc/profile.d/")
- file "/etc/profile.d/#{command_name}.sh" do
- action :delete
- end
- new_resource.updated_by_last_action(true)
+ command_name = new_resource.alias_name.gsub(/ /,"_")
+ resource = file "/etc/profile.d/#{command_name}.sh" do
+ action :nothing
end
-end
-def sanitize_to_command(name)
- name = name.gsub(/ /,"_")
+ resource.run_action(:delete)
+ new_resource.updated_by_last_action(true) if resource.updated_by_last_action?
end
View
@@ -0,0 +1,29 @@
+action :add do
+ environment_name = new_resource.environment_variable.gsub(/ /,"_")
+ if !new_resource.value.nil?
+ Chef::Log.info("Adding #{environment_name}.sh to /etc/profile.d/")
+ file_contents = "# This file was generated by Chef for #{node["fqdn"]}\n"
+ file_contents += "export #{environment_name}='#{new_resource.value}'"
+ resource = file "/etc/profile.d/#{environment_name}.sh" do
+ owner "root"
+ group "root"
+ mode "0755"
+ content file_contents
+ action :nothing
+ end
+
+ resource.run_action(:create)
+ new_resource.updated_by_last_action(true) if resource.updated_by_last_action?
+ end
+end
+
+action :remove do
+ environment_name = new_resource.environment_variable.gsub(/ /,"_")
+ Chef::Log.info("Removing #{environment_name}.sh from /etc/profile.d/")
+ resource = file "/etc/profile.d/#{environment_name}.sh" do
+ action :nothing
+ end
+
+ resource.run_action(:delete)
+ new_resource.updated_by_last_action(true) if resource.updated_by_last_action?
+end
View
@@ -0,0 +1,6 @@
+actions :add, :remove
+
+default_action :add
+
+attribute :environment_variable, :kind_of => String, :name_attribute => true
+attribute :value, :kind_of => String, :default => :add

0 comments on commit 126db86

Please sign in to comment.