itamae-plugin-resource-alternatives 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 983a9f3e914c0ee94d9d124df21903361be0805e
4
+ data.tar.gz: 52a7b395b8b3b6f07033735e12dab0dc28fbc15a
5
+ SHA512:
6
+ metadata.gz: 9603b9e128879cb88974fcecf047951c8f03d2e7c7ab30547c8ad5f6e43a8e1904bd9c4b7739b4232f37106eb8683df352363339d7e5ace38a2e00b1a9ce52c1
7
+ data.tar.gz: eefc74ce56905cd5f3f02173b96f3e0fb421c174cdb66c75a95f5c8425a9a423d25d5d37e169f3c58ed8f228be8bdb39da4bfef797d55706a1bf0572e0a09065
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.vagrant
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,23 @@
1
+ sudo: required
2
+
3
+ language: ruby
4
+
5
+ rvm:
6
+ - ruby-head
7
+ - 2.3.1
8
+ - 2.2
9
+ - 2.1
10
+
11
+ services:
12
+ - docker
13
+
14
+ env:
15
+ - VAGRANT_VERSION=1.8.4
16
+
17
+ before_install:
18
+ - gem update bundler
19
+ - wget https://releases.hashicorp.com/vagrant/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.deb
20
+ - sudo dpkg -i vagrant_${VAGRANT_VERSION}_x86_64.deb
21
+
22
+ script:
23
+ - bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in itamae-plugin-resource-alternatives.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Yuya.Nishida.
2
+
3
+ X11 License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # Itamae::Plugin::Resource::Alternatives
2
+
3
+ Itamae resource plugin to manage "update-alternatives".
4
+
5
+ [![License X11](https://img.shields.io/badge/license-X11-brightgreen.svg)](https://raw.githubusercontent.com/nishidayuya/itamae-plugin-resource-alternatives/master/LICENSE.txt)
6
+ [![Build Status](https://img.shields.io/travis/nishidayuya/itamae-plugin-resource-alternatives.svg)](https://travis-ci.org/nishidayuya/itamae-plugin-resource-alternatives)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem "itamae-plugin-resource-alternatives"
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install itamae-plugin-resource-alternatives
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ # set "editor" to "/usr/bin/vim.tiny"
28
+ alternatives "editor" do
29
+ path "/usr/bin/vim.tiny"
30
+ end
31
+
32
+ # set "pager" to automatic mode
33
+ alternatives "pager" do
34
+ auto true
35
+ end
36
+ ```
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nishidayuya/itamae-plugin-resource-alternatives
@@ -0,0 +1,34 @@
1
+ require "rake"
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ task spec: %i[spec:provision spec:serverspec]
6
+ task default: %i[spec build]
7
+
8
+ def run(*args)
9
+ if !system(*args)
10
+ raise "failure: #{args.inspect}"
11
+ end
12
+ end
13
+
14
+ namespace :spec do
15
+ desc "Run Itamae to test server"
16
+ task :provision do
17
+ Bundler.with_clean_env do
18
+ run("vagrant up")
19
+ end
20
+ run("itamae ssh --vagrant --host default spec/recipe.rb")
21
+ end
22
+
23
+ desc "Run Serverspec to test server"
24
+ RSpec::Core::RakeTask.new(:serverspec) do |t|
25
+ ENV["TARGET_HOST"] = "default"
26
+ t.pattern = "spec/*_spec.rb"
27
+ end
28
+ end
29
+
30
+ task :clean do
31
+ Bundler.with_clean_env do
32
+ run("vagrant destroy -f")
33
+ end
34
+ end
@@ -0,0 +1,12 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ ENV["VAGRANT_DEFAULT_PROVIDER"] ||= "docker"
5
+ Vagrant.configure(2) do |config|
6
+ config.vm.provider(:docker) do |d|
7
+ d.image = "nishidayuya/docker-vagrant-debian:jessie"
8
+ d.has_ssh = true
9
+ end
10
+
11
+ config.vm.provision(:shell, inline: "sudo apt-get update")
12
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "itamae/plugin/resource/alternatives"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "itamae-plugin-resource-alternatives"
7
+ spec.version = "0.0.0"
8
+ spec.authors = ["Yuya.Nishida."]
9
+ spec.email = ["yuya@j96.org"]
10
+
11
+ spec.summary = %q{Itamae resource plugin to manage "update-alternatives".}
12
+ spec.homepage = "https://github.com/nishidayuya/itamae-plugin-resource-alternatives/"
13
+ spec.license = "X11"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "itamae"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "serverspec"
25
+ end
@@ -0,0 +1,74 @@
1
+ require "itamae"
2
+
3
+ module Itamae::Plugin
4
+ end
5
+
6
+ module Itamae::Plugin::Resource
7
+ end
8
+
9
+ class Itamae::Plugin::Resource::Alternatives < Itamae::Resource::Base
10
+ class Error < StandardError
11
+ end
12
+
13
+ define_attribute :action, default: :create
14
+ define_attribute :name, type: String, default_name: true
15
+ define_attribute :path, type: String, default: nil
16
+ define_attribute :auto, type: [TrueClass, FalseClass], default: false
17
+
18
+ def set_current_attributes
19
+ q = run_command(["update-alternatives", "--query", attributes.name])
20
+ parse_query(q)
21
+ end
22
+
23
+ def action_create(options)
24
+ if attributes.auto
25
+ if !current.auto
26
+ run_command(["update-alternatives", "--auto", attributes.name])
27
+ end
28
+ else
29
+ if current.auto || attributes.path != current.path
30
+ run_command([
31
+ "update-alternatives", "--set", attributes.name,
32
+ attributes.path,
33
+ ])
34
+ end
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def parse_query(q)
41
+ generic_name_entry = parse_entry(q.stdout[/.*?(?=\n\n)/m])
42
+ case generic_name_entry[:status]
43
+ when "manual"
44
+ current.auto = false
45
+ when "auto"
46
+ current.auto = true
47
+ else
48
+ raise Error, "malformed status: #{generic_name_entry[:status].inspect}"
49
+ end
50
+ if !current.auto
51
+ current.path = generic_name_entry[:value]
52
+ end
53
+ end
54
+
55
+ def parse_entry(entry)
56
+ last_key = nil
57
+ return entry.each_line.each_with_object({}) do |l, h|
58
+ case l.chomp
59
+ when /: /
60
+ key = $`.downcase.to_sym
61
+ value = $'
62
+ h[key] = value
63
+ last_key = key
64
+ when /:\z/
65
+ last_key = $`.downcase.to_sym
66
+ when /\A /
67
+ h[last_key] ||= []
68
+ h[last_key] << $'
69
+ else
70
+ raise Error, "malformed line: '#{l.inspect}'"
71
+ end
72
+ end
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itamae-plugin-resource-alternatives
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuya.Nishida.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: itamae
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: serverspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - yuya@j96.org
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - Vagrantfile
84
+ - bin/console
85
+ - bin/setup
86
+ - itamae-plugin-resource-alternatives.gemspec
87
+ - lib/itamae/plugin/resource/alternatives.rb
88
+ homepage: https://github.com/nishidayuya/itamae-plugin-resource-alternatives/
89
+ licenses:
90
+ - X11
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.5.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Itamae resource plugin to manage "update-alternatives".
112
+ test_files: []