toolrack 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b1faebd0b9013273d3b9943462bcd01efacde8a688e2fe94743628b3d8c249e
4
- data.tar.gz: af51abbaf1376b8cf2fadd1df32b6395609ecc237554803c562a661e365e9eb1
3
+ metadata.gz: 9b1c1f58f027b8a0b847c9c196c2f2e74ba75f2df78595cb1024f06560bf8ee6
4
+ data.tar.gz: bdbb04df325bf9f979de7497051267e6925ffc74c8a91c2e49008f03c1021401
5
5
  SHA512:
6
- metadata.gz: 4374ec558bed30fff9ee2578169fa832f28668dc43ebeaab5ce3f651f97b6bb8870ba4f2cfb3cf6500ad49e7dc3a64ace2904fad23399e509e13a19b1c1306a9
7
- data.tar.gz: cd45d0a0f890212298030dc1574fe900ccd13ae6b64bf7d57bce863ec7950e65d34238a6f8dedaabab0fadf04b9bf3e1defa4b2d47912e1285c6dd0756db7c1e
6
+ metadata.gz: 97627d8aba3e40cc3cba8f3fe3e0639f349001f548627267fca52d4ee820b8af027ebb33ae1dfff1b46f719b26d36d5aaaf4d2d7e392a918f59dc2bd4ec9e921
7
+ data.tar.gz: 932804f41294d61ceaa32eec0bdb20a8e6eb32d9abb746861cf5591ab09b29aba2980ad3b4d0508d8d2881240d91e2a64d28d83a9552cca669f3fd54521a4c90
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
+ require 'devops_helper'
5
+
4
6
  Rake::TestTask.new(:test) do |t|
5
7
  t.libs << "test"
6
8
  t.libs << "lib"
@@ -3,6 +3,8 @@ require "toolrack/version"
3
3
  require 'tlogger'
4
4
  require 'singleton'
5
5
 
6
+ require 'fileutils'
7
+
6
8
  require_relative 'toolrack/exception_utils'
7
9
  require_relative 'toolrack/condition_utils'
8
10
  require_relative 'toolrack/process_utils'
@@ -21,16 +23,19 @@ module Antrapol
21
23
  def initialize
22
24
  # boolean
23
25
  loggerDebug = ENV['TOOLRACK_DEBUG']
24
- logFile = ENV['TOOLRACK_LOGFILE']
26
+ logFile = ENV['TOOLRACK_LOGFILE'] || File.join(Dir.home, 'antrapol_logs','toolrack.log')
25
27
  maxLogNo = ENV['TOOLRACK_MAX_LOGFILE'] || 10
26
28
  logFileSize = ENV['TOOLRACK_MAX_LOGFILE_SIZE'] || 10*1024*1024
29
+
30
+ logFileDir = File.dirname(logFile)
31
+ if not File.exist?(logFileDir)
32
+ FileUtils.mkdir_p(logFileDir)
33
+ end
27
34
 
28
- if not is_empty?(loggerDebug) and loggerDebug
35
+ if not_empty?(loggerDebug) and (loggerDebug.downcase == 'true')
29
36
  @glogger = Tlogger.new(STDOUT)
30
- elsif not is_empty?(logFile)
31
- @glogger = Tlogger.new(logFile,maxLogNo,logFileSize)
32
37
  else
33
- @glogger = Tlogger.new('toolrack.log',maxLogNo,logFileSize)
38
+ @glogger = Tlogger.new(logFile,maxLogNo,logFileSize)
34
39
  end
35
40
  end
36
41
  end
@@ -13,13 +13,13 @@ module Antrapol
13
13
  def exec(cmd, opts = { }, &block)
14
14
  type = opts[:exec_type]
15
15
  if not type.nil?
16
- exec2(type, cmd, opts, &block)
16
+ instance(type, cmd, opts, &block)
17
17
  else
18
- exec2(:basic, cmd, opts, &block)
18
+ instance(:basic, cmd, opts, &block)
19
19
  end
20
20
  end
21
21
 
22
- def exec2(type, cmd, opts = { }, &block)
22
+ def instance(type, cmd, opts = { }, &block)
23
23
  case type
24
24
  when :basic
25
25
  Antrapol::ToolRack::Logger.instance.glogger.debug "Basic execution"
@@ -1,6 +1,6 @@
1
1
  module Antrapol
2
2
  module ToolRack
3
- VERSION = "0.4.1"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
6
6
 
@@ -0,0 +1,74 @@
1
+
2
+
3
+
4
+ require 'pty'
5
+ require 'expect'
6
+
7
+ #m, s = PTY.open
8
+ #r, w = IO.pipe
9
+ #
10
+ #pid = spawn("/usr/bin/openvpn --config /home/chris/.openvpn_cli/sg2-ovpn-tcp.ovpn", in: r, out: s)
11
+ #r.close
12
+ #s.close
13
+ #
14
+ #
15
+ #ret = begin
16
+ # p m.gets
17
+ # rescue Errno::EIO
18
+ # nil
19
+ # end
20
+ #
21
+
22
+
23
+ ##PTY.spawn("/usr/bin/sudo /usr/bin/openvpn --config /home/chris/.openvpn_cli/sg2-ovpn-tcp.ovpn") do |read, write, pid|
24
+ #PTY.spawn("/usr/bin/openvpn --config /home/chris/.openvpn_cli/sg2-ovpn-tcp.ovpn") do |read, write, pid|
25
+ # #read.expect(/\[sudo\] password for chris:/) { |m|
26
+ # # p m
27
+ # # puts "expect"
28
+ # # write.printf("chr1st0pher1120\n")
29
+ # #}
30
+ # #read.expect(/Username:/) { |msg|
31
+ # # puts "-- #{msg}"
32
+ # # write.printf("purevpn0s2643230\r\n")
33
+ # #}
34
+ #
35
+ # #read.expect(/no echo\)/) { |msg|
36
+ # # puts "++ #{msg}"
37
+ # # write.printf("\t@ntr@p0l.c0m\r\n")
38
+ # #}
39
+ #
40
+ # loop do
41
+ # read.expect(/\n/) { |l|
42
+ # p l
43
+ # @ln = l
44
+ # }
45
+ # break if @ln.nil?
46
+ # end
47
+ #end
48
+
49
+ read, write, pid = PTY.spawn("/usr/bin/openvpn --config /home/chris/.openvpn_cli/sg2-ovpn-tcp.ovpn")
50
+
51
+ puts "PID : #{pid}"
52
+
53
+ trap "SIGINT" do
54
+ read.close
55
+ write.close
56
+ begin
57
+ puts "Killing process"
58
+ Process.kill("HUP",pid)
59
+ puts "Kill done. Start waiting"
60
+ Process.wait(pid)
61
+ STDERR.puts "Cleanup Done!"
62
+ rescue PTY::ChildExited
63
+ end
64
+ end
65
+
66
+ loop do
67
+ read.expect(/\n/) do |l|
68
+ puts l
69
+ @ln = l
70
+ end
71
+ break if @ln.nil?
72
+ end
73
+
74
+
@@ -27,4 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ["lib"]
28
28
 
29
29
  spec.add_dependency "tlogger", "~> 0.21"
30
+
31
+ spec.add_development_dependency "devops_helper", "~> 0.1.0"
30
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toolrack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-03 00:00:00.000000000 Z
11
+ date: 2020-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tlogger
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.21'
27
+ - !ruby/object:Gem::Dependency
28
+ name: devops_helper
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
27
41
  description: Just collections of utilities
28
42
  email:
29
43
  - chrisliaw@antrapol.com