grub-editenv-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grub-editenv-ruby.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 MOZGIII
2
+
3
+ MIT 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,31 @@
1
+ # grub-editenv-ruby
2
+
3
+ Ruby version of `grub-editenv` command line utility. Allows you to edit `grubenv` without having `grub-editenv` installed.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'grub-editenv-ruby'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install grub-editenv-ruby
18
+
19
+ ## Usage
20
+
21
+ Use it just as usual `grub-editenv`!
22
+
23
+ See `grub-editenv-ruby --help` for usage info.
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'grub-editenv-ruby/cli'
4
+
5
+ GrubEditEnv::Cli.start
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grub-editenv-ruby/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "grub-editenv-ruby"
8
+ gem.version = GrubEditEnv::VERSION
9
+ gem.authors = ["MOZGIII"]
10
+ gem.email = ["mike-n@narod.ru"]
11
+ gem.description = %q{Ruby version of grub-editenv command line utility.}
12
+ gem.summary = %q{Allows you to edit grubenv without having grub-editenv installed.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'bundler', '~> 1.0'
21
+ end
@@ -0,0 +1,2 @@
1
+ require "grub-editenv-ruby/version"
2
+ require "grub-editenv-ruby/grubenv"
@@ -0,0 +1,113 @@
1
+ require 'optparse'
2
+ require 'grub-editenv-ruby'
3
+
4
+ module GrubEditEnv
5
+ class Cli
6
+ DEFAULT_PATH = "/boot/grub/grubenv"
7
+
8
+ def self.start
9
+ options = {}
10
+ opts = OptionParser.new do |opts|
11
+ opts.banner = <<BANNER
12
+ SYNOPSIS
13
+ grub-editenv-ruby [OPTIONS] [FILENAME] COMMAND
14
+
15
+ DESCRIPTION
16
+ Tool to edit environment block.
17
+
18
+ Commands:
19
+ create create a blank environment block file
20
+
21
+ list list the current variables
22
+
23
+ set [name=value ...]
24
+ set variables
25
+
26
+ unset [name ....]
27
+ delete variables
28
+
29
+ OPTIONS
30
+ -h, --help
31
+ display this message and exit
32
+
33
+ -V, --version
34
+ print version information and exit
35
+
36
+ -v, --verbose
37
+ print verbose messages
38
+
39
+ If not given explicitly, FILENAME defaults to #{DEFAULT_PATH}.
40
+ BANNER
41
+
42
+ end.parse!
43
+
44
+ cli = self.new
45
+
46
+ if ARGV.empty?
47
+ puts "You must specify a command! Pass --help for more details."
48
+ exit 1
49
+ end
50
+
51
+ cli.filename = ARGV.size == 1 || ARGV[1] =~ /=/ ? nil : ARGV.shift
52
+ cli.command = ARGV.shift.to_sym
53
+ cli.arguments = ARGV
54
+ cli.options = options
55
+
56
+ method = cli.public_method(cli.command) rescue nil
57
+ unless method
58
+ puts "Not implemeted!"
59
+ exit 1
60
+ end
61
+
62
+ method.call
63
+ end
64
+
65
+ attr_accessor :command, :arguments, :filename, :options
66
+
67
+ def create
68
+ grubenv_build.dump
69
+ end
70
+
71
+ def list
72
+ grubenv_build.entries.each do |key, value|
73
+ puts "#{key}=#{value}"
74
+ end
75
+ end
76
+
77
+ def set
78
+ grubenv = grubenv_build
79
+
80
+ arguments.each do |argument|
81
+ key, value = argument.split("=")
82
+ grubenv.entries[key] = value
83
+ end
84
+
85
+ grubenv.dump
86
+ end
87
+
88
+ def unset
89
+ grubenv = grubenv_build
90
+
91
+ arguments.each do |argument|
92
+ grubenv.entries.delete(argument)
93
+ end
94
+
95
+ grubenv.dump
96
+ end
97
+
98
+ private
99
+
100
+ def grubenv_build
101
+ begin
102
+ grubenv_build!
103
+ rescue GrubEnv::FileNotFound => e
104
+ puts e
105
+ exit 1
106
+ end
107
+ end
108
+
109
+ def grubenv_build!
110
+ GrubEnv.new(:grubenv_path => filename || DEFAULT_PATH)
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,61 @@
1
+ module GrubEditEnv
2
+ class GrubEnv
3
+ class FileNotFound < Exception; end
4
+
5
+ ENVBLK_SIGNATURE = "# GRUB Environment Block\n"
6
+ ENVBLK_SIZE = 1024
7
+
8
+ def self.default_options
9
+ {
10
+ :envblk_signature => ENVBLK_SIGNATURE,
11
+ :envblk_size => ENVBLK_SIZE,
12
+ :grubenv_path => nil
13
+ }
14
+ end
15
+
16
+ attr_reader :options
17
+ attr_reader :entries
18
+
19
+ def initialize(options = {})
20
+ @options = self.class.default_options.merge(options)
21
+
22
+ raise "Misconfigured" unless grubenv_path
23
+ raise FileNotFound, "File #{grubenv_path} was not found!" unless File.file?(grubenv_path)
24
+
25
+ reload
26
+ end
27
+
28
+ def grubenv_path
29
+ options[:grubenv_path]
30
+ end
31
+
32
+ def reload
33
+ @entries = nil
34
+ data = File.read(grubenv_path)
35
+ raise "Wrong grubenv format on reload!" unless data.start_with?(options[:envblk_signature])
36
+ data[0, options[:envblk_signature].size] = ''
37
+ data.sub!(/#*\z/, "")
38
+
39
+ @entries = {}
40
+ data.split("\n").each do |line|
41
+ key, value = line.split("=")
42
+ @entries[key] = value
43
+ end
44
+ end
45
+
46
+ def dump
47
+ contents = options[:envblk_signature]
48
+
49
+ @entries.each do |key, value|
50
+ data = "#{key}=#{value}\n"
51
+ contents << data
52
+ end
53
+
54
+ contents << "#" while contents.size < options[:envblk_size]
55
+
56
+ File.open grubenv_path, "wb" do |f|
57
+ f << contents
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module GrubEditEnv
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grub-editenv-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - MOZGIII
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ description: Ruby version of grub-editenv command line utility.
31
+ email:
32
+ - mike-n@narod.ru
33
+ executables:
34
+ - grub-editenv-ruby
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/grub-editenv-ruby
44
+ - grub-editenv-ruby.gemspec
45
+ - lib/grub-editenv-ruby.rb
46
+ - lib/grub-editenv-ruby/cli.rb
47
+ - lib/grub-editenv-ruby/grubenv.rb
48
+ - lib/grub-editenv-ruby/version.rb
49
+ homepage: ''
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.24
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Allows you to edit grubenv without having grub-editenv installed.
73
+ test_files: []