shellutils 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- # encoding: UTF-8
1
+ # encoding: UTF-8
2
2
 
3
3
  require 'thor'
4
4
  require 'timeout'
@@ -45,26 +45,26 @@ module ShellUtils
45
45
  return true if `uname` =~ /Linux/
46
46
  false
47
47
  end
48
-
48
+
49
49
  def is_mac?
50
50
  return true if `uname` =~ /Darwin/
51
51
  false
52
52
  end
53
-
53
+
54
54
  def get_platform
55
55
  if is_linux?
56
56
  'linux'
57
57
  elsif is_mac?
58
58
  'macos'
59
- else
59
+ else
60
60
  'unknown'
61
61
  end
62
62
  end
63
-
63
+
64
64
  def is_installed?(program)
65
65
  `which #{program}`.chomp != ""
66
66
  end
67
-
67
+
68
68
  def get_sudo_pwd
69
69
  if File.exist?(SUDO_PWD_PATH) == false || file_read(SUDO_PWD_PATH) == ""
70
70
  pw = user_input("please input sudo password")
@@ -72,11 +72,11 @@ module ShellUtils
72
72
  end
73
73
  file_read(SUDO_PWD_PATH)
74
74
  end
75
-
75
+
76
76
  def set_sudo_pwd(pw)
77
77
  file_write(SUDO_PWD_PATH, pw)
78
78
  end
79
-
79
+
80
80
  def user_input(desc, example = nil, choices = nil)
81
81
  if example
82
82
  puts "#{desc}: ex) #{example}"
@@ -94,7 +94,7 @@ module ShellUtils
94
94
  end
95
95
  input
96
96
  end
97
-
97
+
98
98
  def make_file_from_template(template_path, dest_path, hash)
99
99
  puts "create #{dest_path}"
100
100
  template = ERB.new File.read(template_path)
@@ -108,24 +108,24 @@ module ShellUtils
108
108
  STDERR.puts @@color.set_color("### ERROR:#{msg}", :red)
109
109
  raise
110
110
  end
111
-
111
+
112
112
  def current_method(index=0)
113
113
  caller[index].scan(/`(.*)'/).flatten.to_s
114
114
  end
115
-
115
+
116
116
  def exec_cmd_and_clear_password(cmd)
117
117
  puts cmd
118
118
  PTY.spawn(cmd) do |r, w|
119
119
  w.flush
120
120
  w.sync = true
121
121
  w.flush
122
- if r.expect(/[Pp]assword.*:.*$/)
122
+ if r.expect(/[Pp]assword.*:.*$/, 1)
123
123
  w.flush
124
124
  w.puts(get_sudo_pwd)
125
125
  w.flush
126
126
  begin
127
127
  w.flush
128
- if r.expect(/[Pp]assword.*:.*$/)
128
+ if r.expect(/[Pp]assword.*:.*$/, 1)
129
129
  error("the sudo password is incorrect. password=#{get_sudo_pwd}\nPlease change the password ex) set_sudo_pwd PASSWORD")
130
130
  end
131
131
  rescue
@@ -139,11 +139,11 @@ module ShellUtils
139
139
  end
140
140
  end
141
141
  end
142
-
142
+
143
143
  def sudo(cmd)
144
144
  exec_cmd_and_clear_password("sudo #{cmd}")
145
145
  end
146
-
146
+
147
147
  def rvmsudo(cmd)
148
148
  exec_cmd_and_clear_password("rvmsudo #{cmd}")
149
149
  end
@@ -165,7 +165,7 @@ module ShellUtils
165
165
  `whoami`.chomp
166
166
  end
167
167
 
168
- private
168
+ private
169
169
 
170
170
  def get_config_header(config_title, comment_char)
171
171
  "#{comment_char * 2} #{config_title}\n"
@@ -179,4 +179,3 @@ module ShellUtils
179
179
 
180
180
 
181
181
  end # ShellUtils
182
-
@@ -1,3 +1,3 @@
1
1
  module Shellutils
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shellutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-15 00:00:00.000000000 Z
12
+ date: 2013-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  version: '0'
83
83
  requirements: []
84
84
  rubyforge_project:
85
- rubygems_version: 1.8.24
85
+ rubygems_version: 1.8.23
86
86
  signing_key:
87
87
  specification_version: 3
88
88
  summary: Shell utils