kscript 1.0.2 → 1.0.4
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.
- checksums.yaml +4 -4
- data/README.md +30 -7
- data/ext/mkrf_conf.rb +28 -0
- data/lib/completions/kscript.bash +20 -0
- data/lib/completions/kscript.zsh +29 -0
- data/lib/kscript/base.rb +5 -4
- data/lib/kscript/cli.rb +31 -40
- data/lib/kscript/config.rb +31 -0
- data/lib/kscript/plugins/kk_apnic_utils.rb +3 -3
- data/lib/kscript/plugins/kk_aws_s3_utils.rb +99 -0
- data/lib/kscript/plugins/kk_cleaner_utils.rb +4 -4
- data/lib/kscript/plugins/kk_es_fingerprint_utils.rb +3 -2
- data/lib/kscript/plugins/kk_ffmpeg_utils.rb +4 -0
- data/lib/kscript/plugins/kk_ip_utils.rb +3 -3
- data/lib/kscript/plugins/kk_jenkins_utils.rb +9 -7
- data/lib/kscript/plugins/kk_kibana_utils.rb +9 -7
- data/lib/kscript/plugins/kk_lvm_utils.rb +3 -2
- data/lib/kscript/plugins/kk_optimize_utils.rb +4 -0
- data/lib/kscript/plugins/kk_portscan_utils.rb +5 -5
- data/lib/kscript/plugins/kk_projscan_utils.rb +2 -3
- data/lib/kscript/plugins/kk_rename_utils.rb +5 -5
- data/lib/kscript/plugins/kk_sh_utils.rb +3 -3
- data/lib/kscript/plugins/kk_syscheck_utils.rb +26 -8
- data/lib/kscript/plugins/kk_top_utils.rb +4 -7
- data/lib/kscript/plugins/kk_usd_utils.rb +3 -12
- data/lib/kscript/plugins/kk_wg_acl_utils.rb +4 -0
- data/lib/kscript/plugins/kk_wg_pass_utils.rb +2 -3
- data/lib/kscript/post_install.rb +128 -0
- data/lib/kscript/utils.rb +0 -56
- data/lib/kscript/version.rb +1 -1
- data/lib/kscript.rb +3 -0
- metadata +63 -12
- data/Gemfile +0 -3
- data/LICENSE +0 -21
- data/Rakefile +0 -42
- data/kscript.gemspec +0 -40
- /data/{bin → exe}/kscript +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a38a099a45b7be84d12e6b0122dae45eb9891dab7ec2b24804b0c2628111de9a
|
4
|
+
data.tar.gz: 7b60a6c3aa2d320fe4f92e9bc23affcc6cd208aa6bf4ee68ccb154d92008269a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41ce72c538b84c8d27ced7099f4072cea6ec794a4ee758f568a61461263a5bf38d40c6ff7874a15361c9ead95834dd1c028fa5efe1c1dee78832a919b76e2554
|
7
|
+
data.tar.gz: de04332a98285246ea14f7dc583d2a89248a90594ca7ac00cee9c628d8181bacea464f88a2e3be368ca22e8667430302fff8ae1947856941fd67d069346131b5
|
data/README.md
CHANGED
@@ -25,6 +25,7 @@ _ ,< _(__ )/ /__ _ / _ / __ /_/ / /_
|
|
25
25
|
- **参数健壮**:所有插件兼容多余参数,支持全局参数过滤
|
26
26
|
- **CI/CD 自动发布**:GitHub Actions 自动构建并推送 RubyGem
|
27
27
|
- **多平台支持**:macOS、Linux、Windows(部分工具)
|
28
|
+
- **自动生成配置**:首次安装自动生成 `~/.kscript/.env` 配置示例
|
28
29
|
|
29
30
|
---
|
30
31
|
|
@@ -70,6 +71,7 @@ kscript apnic CN
|
|
70
71
|
kscript portscan 192.168.1.1
|
71
72
|
kscript sh 'ls -l'
|
72
73
|
kscript projscan ~/projects
|
74
|
+
kscript aws_s3 --file local.txt --bucket my-bucket --key test.txt --region ap-northeast-1 --access_key xxx --secret_key yyy
|
73
75
|
```
|
74
76
|
|
75
77
|
### 结构化日志模式
|
@@ -106,6 +108,8 @@ kscript portscan 192.168.1.1 --log-level=debug
|
|
106
108
|
- `kibana`:Kibana 空间/索引/用户/角色自动化
|
107
109
|
- **ci**
|
108
110
|
- `jenkins`:Jenkins Job 导入导出
|
111
|
+
- **cloud**
|
112
|
+
- `aws_s3`:AWS S3 文件上传测试
|
109
113
|
- **其它**
|
110
114
|
- `usd`:美元汇率工具
|
111
115
|
- `lvm`:LVM 卷管理
|
@@ -113,13 +117,15 @@ kscript portscan 192.168.1.1 --log-level=debug
|
|
113
117
|
|
114
118
|
---
|
115
119
|
|
116
|
-
## ⚡ Shell 自动补全
|
120
|
+
## ⚡ Shell 自动补全 & 配置示例
|
117
121
|
|
118
|
-
-
|
122
|
+
- **首次安装/升级自动为 zsh/bash 部署补全脚本,并生成 `~/.kscript/.env` 配置示例**
|
119
123
|
- 补全脚本路径:
|
120
124
|
- zsh: `~/.zsh/completions/_kscript`
|
121
125
|
- bash: `~/.bash_completion.d/kscript`
|
122
|
-
-
|
126
|
+
- 配置文件路径:
|
127
|
+
- `~/.kscript/.env`(自动生成,支持 ENV 变量注释说明)
|
128
|
+
- 手动生成补全:
|
123
129
|
```bash
|
124
130
|
kscript completion zsh > ~/.zsh/completions/_kscript
|
125
131
|
kscript completion bash > ~/.bash_completion.d/kscript
|
@@ -127,12 +133,20 @@ kscript portscan 192.168.1.1 --log-level=debug
|
|
127
133
|
|
128
134
|
---
|
129
135
|
|
130
|
-
## ⚙️
|
136
|
+
## ⚙️ 全局配置(.env 格式)
|
131
137
|
|
132
|
-
|
138
|
+
所有全局参数均通过 `~/.kscript/.env` 文件(自动生成,标准 .env 格式)或环境变量注入。例如:
|
133
139
|
|
134
|
-
```
|
135
|
-
|
140
|
+
```env
|
141
|
+
# AWS S3 upload config
|
142
|
+
AWS_BUCKET=my-bucket
|
143
|
+
AWS_REGION=ap-northeast-1
|
144
|
+
AWS_ACCESS_KEY_ID=xxx
|
145
|
+
AWS_SECRET_ACCESS_KEY=yyy
|
146
|
+
|
147
|
+
# Logging config
|
148
|
+
KSCRIPT_LOG_LEVEL=info
|
149
|
+
LOG=1
|
136
150
|
```
|
137
151
|
|
138
152
|
---
|
@@ -143,6 +157,7 @@ log_level: debug
|
|
143
157
|
- 支持 `self.description`、`self.usage`、`self.arguments`、`self.group`、`self.author`
|
144
158
|
- 输出统一用 `logger.kinfo`/`logger.kerror`,支持结构化日志
|
145
159
|
- 兼容多余参数,避免 ArgumentError
|
160
|
+
- 依赖统一在主入口 require,插件只需 require 'kscript'
|
146
161
|
|
147
162
|
---
|
148
163
|
|
@@ -154,6 +169,14 @@ log_level: debug
|
|
154
169
|
|
155
170
|
---
|
156
171
|
|
172
|
+
## 📦 依赖与兼容性
|
173
|
+
|
174
|
+
- Ruby >= 3.0
|
175
|
+
- 依赖:bcrypt, http, nokogiri, thor, aws-sdk-s3 等
|
176
|
+
- 支持 macOS、Linux,部分工具支持 Windows
|
177
|
+
|
178
|
+
---
|
179
|
+
|
157
180
|
## 📄 许可证
|
158
181
|
|
159
182
|
MIT License. 详见 [LICENSE](LICENSE)。
|
data/ext/mkrf_conf.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
# Create Rakefile for gem install hook
|
7
|
+
dir = File.dirname(__FILE__)
|
8
|
+
File.write(File.join(dir, 'Rakefile'), <<~RAKEFILE)
|
9
|
+
task :default do
|
10
|
+
# Add lib directory to load path
|
11
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
12
|
+
$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
|
13
|
+
require 'kscript/post_install'
|
14
|
+
Kscript::PostInstall.run
|
15
|
+
end
|
16
|
+
RAKEFILE
|
17
|
+
|
18
|
+
# Run post-install script immediately for local development
|
19
|
+
def local_dev?
|
20
|
+
ENV['GEM_ENV'] != 'production'
|
21
|
+
end
|
22
|
+
|
23
|
+
if local_dev?
|
24
|
+
lib_path = File.expand_path('../lib', __dir__)
|
25
|
+
$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
|
26
|
+
require 'kscript/post_install'
|
27
|
+
Kscript::PostInstall.run
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# kscript bash completion
|
2
|
+
# Auto-generated command completion for kscript CLI
|
3
|
+
|
4
|
+
_kscript_completions() {
|
5
|
+
local cur
|
6
|
+
COMPREPLY=()
|
7
|
+
cur="${COMP_WORDS[COMP_CWORD]}"
|
8
|
+
|
9
|
+
# Main command list as array
|
10
|
+
local opts=(
|
11
|
+
version help list apnic cleaner es_fingerprint ffmpeg ip jenkins kibana lvm optimize portscan projscan rename sh syscheck top usd wg_acl wg_pass
|
12
|
+
)
|
13
|
+
|
14
|
+
if [[ ${COMP_CWORD} == 1 ]]; then
|
15
|
+
COMPREPLY=( $(compgen -W "${opts[*]}" -- "${cur}") )
|
16
|
+
return 0
|
17
|
+
fi
|
18
|
+
}
|
19
|
+
|
20
|
+
complete -F _kscript_completions kscript
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#compdef kscript
|
2
|
+
_kscript() {
|
3
|
+
local -a commands
|
4
|
+
commands=(
|
5
|
+
'version:kscript command'
|
6
|
+
'help:kscript command'
|
7
|
+
'list:kscript command'
|
8
|
+
'apnic:kscript command'
|
9
|
+
'cleaner:kscript command'
|
10
|
+
'es_fingerprint:kscript command'
|
11
|
+
'ffmpeg:kscript command'
|
12
|
+
'ip:kscript command'
|
13
|
+
'jenkins:kscript command'
|
14
|
+
'kibana:kscript command'
|
15
|
+
'lvm:kscript command'
|
16
|
+
'optimize:kscript command'
|
17
|
+
'portscan:kscript command'
|
18
|
+
'projscan:kscript command'
|
19
|
+
'rename:kscript command'
|
20
|
+
'sh:kscript command'
|
21
|
+
'syscheck:kscript command'
|
22
|
+
'top:kscript command'
|
23
|
+
'usd:kscript command'
|
24
|
+
'wg_acl:kscript command'
|
25
|
+
'wg_pass:kscript command'
|
26
|
+
)
|
27
|
+
_describe 'command' commands
|
28
|
+
}
|
29
|
+
compdef _kscript kscript
|
data/lib/kscript/base.rb
CHANGED
@@ -7,11 +7,12 @@ module Kscript
|
|
7
7
|
class Base
|
8
8
|
attr_reader :logger
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
|
12
|
-
log_level
|
13
|
-
@logger = Kscript::Logger.new(service: service
|
10
|
+
def initialize(**opts)
|
11
|
+
service = opts.delete(:service) || self.class.name
|
12
|
+
log_level = opts.delete(:log_level) || ENV['KSCRIPT_LOG_LEVEL'] || :info
|
13
|
+
@logger = Kscript::Logger.new(service: service, level: log_level)
|
14
14
|
@logger.set_human_output(human_output?)
|
15
|
+
# 其余 opts 可由子类使用
|
15
16
|
end
|
16
17
|
|
17
18
|
# 通用工具方法可在此扩展
|
data/lib/kscript/cli.rb
CHANGED
@@ -5,6 +5,8 @@ require 'kscript/banner'
|
|
5
5
|
|
6
6
|
module Kscript
|
7
7
|
class CLI < Thor
|
8
|
+
Kscript::Config.load!
|
9
|
+
|
8
10
|
class_option :log_level, type: :string, desc: 'Set log level (debug, info, warn, error, fatal)',
|
9
11
|
aliases: '--log-level'
|
10
12
|
class_option :log, type: :boolean, desc: 'Enable structured log output', default: false
|
@@ -72,12 +74,27 @@ module Kscript
|
|
72
74
|
klass = info[:class]
|
73
75
|
desc command,
|
74
76
|
(info[:description] || 'No description') + (reserved.include?(orig_command) ? " (original: #{orig_command})" : '')
|
77
|
+
|
78
|
+
# 动态注册 option
|
79
|
+
if klass.respond_to?(:arguments) && klass.arguments.is_a?(String)
|
80
|
+
# 支持 '--file FILE --bucket BUCKET ...' 或 '<file> <bucket>'
|
81
|
+
arg_str = klass.arguments
|
82
|
+
arg_names = arg_str.scan(/--([a-zA-Z0-9_-]+)/).flatten
|
83
|
+
# 兼容 <file> <bucket> 形式
|
84
|
+
arg_names += arg_str.scan(/<([a-zA-Z0-9_-]+)>/).flatten
|
85
|
+
arg_names.uniq.each do |param|
|
86
|
+
next if %w[help version].include?(param)
|
87
|
+
|
88
|
+
option param.to_sym, type: :string, desc: param
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
75
92
|
define_method(command) do |*args|
|
76
93
|
puts Kscript::BANNER
|
77
94
|
puts color('─' * 80, 90)
|
78
95
|
begin
|
79
|
-
instance = klass.new(
|
80
|
-
instance.run
|
96
|
+
instance = klass.new(**options)
|
97
|
+
instance.run(*args)
|
81
98
|
rescue ArgumentError => e
|
82
99
|
warn "Argument error: #{e.message}"
|
83
100
|
puts "Usage: kscript #{command} #{klass.respond_to?(:arguments) ? klass.arguments : '[args...]'}"
|
@@ -86,38 +103,20 @@ module Kscript
|
|
86
103
|
end
|
87
104
|
end
|
88
105
|
|
89
|
-
desc '
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
97
|
-
output = StringIO.new
|
98
|
-
case shell
|
99
|
-
when 'zsh'
|
100
|
-
output.puts "#compdef kscript\n"
|
101
|
-
output.puts '_kscript() {'
|
102
|
-
output.puts ' local -a commands'
|
103
|
-
output.puts ' commands=('
|
104
|
-
commands.each do |cmd|
|
105
|
-
output.puts " '#{cmd}:kscript command'"
|
106
|
-
end
|
107
|
-
output.puts ' )'
|
108
|
-
output.puts " _describe 'command' commands"
|
109
|
-
output.puts '}'
|
110
|
-
output.puts 'compdef _kscript kscript'
|
111
|
-
when 'bash'
|
112
|
-
output.puts '_kscript_completions() {'
|
113
|
-
output.puts " COMPREPLY=($(compgen -W \"#{commands.join(' ')}\" -- \"${COMP_WORDS[1]}\"))"
|
114
|
-
output.puts '}'
|
115
|
-
output.puts 'complete -F _kscript_completions kscript'
|
106
|
+
desc 'env', 'Show current environment variables relevant to kscript'
|
107
|
+
def env
|
108
|
+
puts Kscript::BANNER
|
109
|
+
puts color('─' * 80, 90)
|
110
|
+
keys = ENV.keys.grep(/^(KSCRIPT_|AWS_|LOG$|SHELL$|HOME$)/)
|
111
|
+
if keys.empty?
|
112
|
+
puts gray('No relevant environment variables found.')
|
116
113
|
else
|
117
|
-
|
118
|
-
|
114
|
+
puts bold('Loaded environment variables:')
|
115
|
+
keys.sort.each do |k|
|
116
|
+
v = ENV[k]
|
117
|
+
puts green(k.ljust(28)) + gray('=') + cyan(v)
|
118
|
+
end
|
119
119
|
end
|
120
|
-
capture ? output.string : (puts output.string)
|
121
120
|
end
|
122
121
|
|
123
122
|
no_commands do
|
@@ -172,11 +171,3 @@ module Kscript
|
|
172
171
|
end
|
173
172
|
end
|
174
173
|
end
|
175
|
-
|
176
|
-
# CLI 启动时自动检测并安装 shell 补全脚本
|
177
|
-
begin
|
178
|
-
require_relative 'utils'
|
179
|
-
Kscript::Utils::Config.ensure_completion_installed
|
180
|
-
rescue StandardError => e
|
181
|
-
warn "[kscript] Shell completion auto-install failed: #{e.message}"
|
182
|
-
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Kscript::Config
|
4
|
+
# Responsible for loading ~/.kscript/.env and providing config access
|
5
|
+
# Usage:
|
6
|
+
# Kscript::Config.load!
|
7
|
+
# Kscript::Config.get('AWS_ACCESS_KEY_ID')
|
8
|
+
|
9
|
+
require 'dotenv'
|
10
|
+
|
11
|
+
module Kscript
|
12
|
+
module Config
|
13
|
+
CONFIG_PATH = File.expand_path('~/.kscript/.env')
|
14
|
+
@loaded = false
|
15
|
+
|
16
|
+
# Load ~/.kscript/.env using dotenv
|
17
|
+
def self.load!
|
18
|
+
return if @loaded
|
19
|
+
|
20
|
+
Dotenv.load(CONFIG_PATH)
|
21
|
+
@loaded = true
|
22
|
+
end
|
23
|
+
|
24
|
+
# Get config value from ENV, with optional default
|
25
|
+
# @param key [String] ENV key
|
26
|
+
# @param default [Object] default value if not set
|
27
|
+
def self.get(key, default = nil)
|
28
|
+
ENV[key] || default
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -12,9 +12,9 @@ module Kscript
|
|
12
12
|
attr_reader :country_sn, :cache_file
|
13
13
|
|
14
14
|
# Initialize class instance, set country code and cache file path
|
15
|
-
def initialize(country_sn = 'CN', *
|
16
|
-
super(**opts
|
17
|
-
@country_sn = country_sn
|
15
|
+
def initialize(country_sn = 'CN', *args, **opts)
|
16
|
+
super(*args, **opts)
|
17
|
+
@country_sn = country_sn || 'CN'
|
18
18
|
@cache_file = RUBY_PLATFORM.match?(/(linux|darwin)/) ? '/tmp/apnic.txt' : 'apnic.txt'
|
19
19
|
end
|
20
20
|
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2025 Kk
|
4
|
+
#
|
5
|
+
# This software is released under the MIT License.
|
6
|
+
# https://opensource.org/licenses/MIT
|
7
|
+
|
8
|
+
require 'kscript'
|
9
|
+
|
10
|
+
# AWS S3 文件上传测试工具
|
11
|
+
# 用法示例:
|
12
|
+
# kscript aws_s3 --file local.txt --bucket my-bucket --key test.txt --region ap-northeast-1 --access_key xxx --secret_key yyy
|
13
|
+
#
|
14
|
+
# 依赖:aws-sdk-s3(已在主入口 require)
|
15
|
+
|
16
|
+
module Kscript
|
17
|
+
class KkAwsS3Utils < Base
|
18
|
+
# 初始化,支持所有参数通过 CLI 传递
|
19
|
+
def initialize(*args, **opts)
|
20
|
+
super(*args, **opts)
|
21
|
+
# 兼容 --file test.txt 以及 --file=test.txt
|
22
|
+
@file = opts[:file] || args[0]
|
23
|
+
@bucket = opts[:bucket] || args[1] || ENV['AWS_BUCKET']
|
24
|
+
@key = opts[:key] || args[2]
|
25
|
+
@region = opts[:region] || ENV['AWS_REGION']
|
26
|
+
@access_key = opts[:access_key] || ENV['AWS_ACCESS_KEY_ID']
|
27
|
+
@secret_key = opts[:secret_key] || ENV['AWS_SECRET_ACCESS_KEY']
|
28
|
+
end
|
29
|
+
|
30
|
+
# 主入口
|
31
|
+
def run(*_args, **_opts)
|
32
|
+
with_error_handling do
|
33
|
+
upload_file_to_s3
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# 上传文件到 S3
|
38
|
+
def upload_file_to_s3
|
39
|
+
validate_params!
|
40
|
+
logger.kinfo('Uploading file to S3...', file: @file, bucket: @bucket, key: @key, region: @region)
|
41
|
+
s3 = Aws::S3::Resource.new(
|
42
|
+
region: @region,
|
43
|
+
access_key_id: @access_key,
|
44
|
+
secret_access_key: @secret_key
|
45
|
+
)
|
46
|
+
obj = s3.bucket(@bucket).object(@key)
|
47
|
+
obj.upload_file(@file)
|
48
|
+
url = obj.public_url
|
49
|
+
logger.kinfo('Upload success', url: url)
|
50
|
+
end
|
51
|
+
|
52
|
+
# 参数声明
|
53
|
+
def self.arguments
|
54
|
+
'--file FILE --bucket BUCKET --key KEY --region REGION --access_key AK --secret_key SK'
|
55
|
+
end
|
56
|
+
|
57
|
+
# 用法
|
58
|
+
def self.usage
|
59
|
+
'kscript aws_s3 --file local.txt --bucket my-bucket --key test.txt --region ap-northeast-1 --access_key xxx --secret_key yyy'
|
60
|
+
end
|
61
|
+
|
62
|
+
# 分组
|
63
|
+
def self.group
|
64
|
+
'cloud'
|
65
|
+
end
|
66
|
+
|
67
|
+
# 作者
|
68
|
+
def self.author
|
69
|
+
'kk'
|
70
|
+
end
|
71
|
+
|
72
|
+
# 描述
|
73
|
+
def self.description
|
74
|
+
'Upload a file to AWS S3 for testing.'
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
# 校验参数
|
80
|
+
def validate_params!
|
81
|
+
missing = []
|
82
|
+
missing << 'file' unless @file
|
83
|
+
missing << 'bucket' unless @bucket
|
84
|
+
missing << 'key' unless @key
|
85
|
+
missing << 'region' unless @region
|
86
|
+
missing << 'access_key' unless @access_key
|
87
|
+
missing << 'secret_key' unless @secret_key
|
88
|
+
unless missing.empty?
|
89
|
+
logger.kerror('Missing required parameters', missing: missing)
|
90
|
+
logger.kinfo(self.class.usage)
|
91
|
+
raise ArgumentError, "Missing: #{missing.join(', ')}"
|
92
|
+
end
|
93
|
+
return if File.exist?(@file)
|
94
|
+
|
95
|
+
logger.kerror('File not found', file: @file)
|
96
|
+
raise ArgumentError, "File not found: #{@file}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -16,10 +16,10 @@ module Kscript
|
|
16
16
|
# Initialize the cleaner with path and retention settings
|
17
17
|
# @param source_path [String] path to source code directory
|
18
18
|
# @param retain_count [Integer] number of versions to keep
|
19
|
-
def initialize(
|
20
|
-
super(**opts
|
21
|
-
@source_path =
|
22
|
-
@retain_count =
|
19
|
+
def initialize(*args, **opts)
|
20
|
+
super(*args, **opts)
|
21
|
+
@source_path = args[0] || '/data/sources/*/**'
|
22
|
+
@retain_count = args[1] || DEFAULT_RETAIN_VERSIONS
|
23
23
|
end
|
24
24
|
|
25
25
|
def run
|
@@ -15,8 +15,9 @@ module Kscript
|
|
15
15
|
|
16
16
|
# Initialize with certificate path
|
17
17
|
# @param cert_path [String] path to the certificate file
|
18
|
-
def initialize(
|
19
|
-
|
18
|
+
def initialize(*args, **opts)
|
19
|
+
super(*args, **opts)
|
20
|
+
@cert_path = opts[:cert_path] || self.class::DEFAULT_CERT_PATH
|
20
21
|
end
|
21
22
|
|
22
23
|
def run
|
@@ -14,9 +14,9 @@ module Kscript
|
|
14
14
|
|
15
15
|
attr_reader :ip_address
|
16
16
|
|
17
|
-
def initialize(
|
18
|
-
super(**opts
|
19
|
-
@ip_address =
|
17
|
+
def initialize(*args, **opts)
|
18
|
+
super(*args, **opts)
|
19
|
+
@ip_address = args.first || fetch_public_ip
|
20
20
|
end
|
21
21
|
|
22
22
|
def run
|
@@ -9,13 +9,9 @@ require 'kscript'
|
|
9
9
|
|
10
10
|
module Kscript
|
11
11
|
class KkJenkinsUtils < Base
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(jenkins_url, user, password)
|
12
|
+
def initialize(*args, **opts)
|
13
|
+
super(*args, **opts)
|
14
|
+
jenkins_url, user, password = args
|
19
15
|
@jenkins_url = jenkins_url
|
20
16
|
@user = user
|
21
17
|
@password = password
|
@@ -24,6 +20,12 @@ module Kscript
|
|
24
20
|
@output.sync = true
|
25
21
|
end
|
26
22
|
|
23
|
+
def run
|
24
|
+
with_error_handling do
|
25
|
+
logger.kinfo('Jenkins job manager executed.')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
27
29
|
def export_all_jobs
|
28
30
|
FileUtils.mkdir_p('jobs')
|
29
31
|
|
@@ -9,13 +9,9 @@ require 'kscript'
|
|
9
9
|
|
10
10
|
module Kscript
|
11
11
|
class KkKibanaUtils < Base
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(project_name, project_env, base_url, username, password)
|
12
|
+
def initialize(*args, **opts)
|
13
|
+
super(*args, **opts)
|
14
|
+
project_name, project_env, base_url, username, password = args
|
19
15
|
@base_url = base_url
|
20
16
|
@username = username
|
21
17
|
@password = password
|
@@ -27,6 +23,12 @@ module Kscript
|
|
27
23
|
create_space unless space_exists?
|
28
24
|
end
|
29
25
|
|
26
|
+
def run
|
27
|
+
with_error_handling do
|
28
|
+
logger.kinfo('Kibana utils executed.')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
30
32
|
# Check if the space exists
|
31
33
|
def space_exists?
|
32
34
|
url = "#{@base_url}/api/spaces/space/#{@space_name}"
|
@@ -20,8 +20,9 @@ module Kscript
|
|
20
20
|
|
21
21
|
# Initialize the LVM mounter with configuration
|
22
22
|
# @param config [Hash] configuration options
|
23
|
-
def initialize(
|
24
|
-
|
23
|
+
def initialize(*args, **opts)
|
24
|
+
super(*args, **opts)
|
25
|
+
@config = DEFAULT_CONFIG.merge(opts)
|
25
26
|
end
|
26
27
|
|
27
28
|
def run
|
@@ -15,11 +15,11 @@ module Kscript
|
|
15
15
|
# @param host [String] target host to scan
|
16
16
|
# @param ports [Array<Integer>] list of ports to scan
|
17
17
|
# @param thread_count [Integer] number of concurrent threads
|
18
|
-
def initialize(
|
19
|
-
super(**opts
|
20
|
-
@target =
|
21
|
-
@ports = parse_ports(
|
22
|
-
@thread_count = (opts[:thread_count] ||
|
18
|
+
def initialize(*args, **opts)
|
19
|
+
super(*args, **opts)
|
20
|
+
@target = args[0]
|
21
|
+
@ports = parse_ports(args[1] || (1..1024))
|
22
|
+
@thread_count = (opts[:thread_count] || 50).to_i
|
23
23
|
end
|
24
24
|
|
25
25
|
def run
|
@@ -9,9 +9,8 @@ require 'kscript'
|
|
9
9
|
|
10
10
|
module Kscript
|
11
11
|
class KkProjscanUtils < Base
|
12
|
-
def initialize(
|
13
|
-
super(**opts
|
14
|
-
@src_path = src_path || File.expand_path('~/projects/src')
|
12
|
+
def initialize(*args, **opts)
|
13
|
+
super(*args, **opts)
|
15
14
|
end
|
16
15
|
|
17
16
|
def run
|
@@ -11,11 +11,11 @@ module Kscript
|
|
11
11
|
class KkRenameUtils < Base
|
12
12
|
attr_reader :source_pattern, :target_pattern, :directory
|
13
13
|
|
14
|
-
def initialize(
|
15
|
-
super(**opts
|
16
|
-
@source_pattern =
|
17
|
-
@target_pattern =
|
18
|
-
@directory =
|
14
|
+
def initialize(*args, **opts)
|
15
|
+
super(*args, **opts)
|
16
|
+
@source_pattern = args[0]
|
17
|
+
@target_pattern = args[1]
|
18
|
+
@directory = args[2] || Dir.pwd
|
19
19
|
end
|
20
20
|
|
21
21
|
def run
|
@@ -15,9 +15,9 @@ module Kscript
|
|
15
15
|
|
16
16
|
# Initialize with shell command to look up
|
17
17
|
# @param command [String] command to get help for
|
18
|
-
def initialize(
|
19
|
-
super(**opts
|
20
|
-
@command =
|
18
|
+
def initialize(*args, **opts)
|
19
|
+
super(*args, **opts)
|
20
|
+
@command = args.first
|
21
21
|
end
|
22
22
|
|
23
23
|
def run
|
@@ -9,6 +9,10 @@ require 'kscript'
|
|
9
9
|
|
10
10
|
module Kscript
|
11
11
|
class KkSyscheckUtils < Base
|
12
|
+
def initialize(*_args, **opts)
|
13
|
+
super(**opts.merge(service: 'kk_syscheck'))
|
14
|
+
end
|
15
|
+
|
12
16
|
def run
|
13
17
|
with_error_handling do
|
14
18
|
check
|
@@ -20,20 +24,33 @@ module Kscript
|
|
20
24
|
logger.kinfo("📅 Date Time: #{Time.now}")
|
21
25
|
logger.kinfo('')
|
22
26
|
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
# CPU Usage
|
28
|
+
logger.kinfo('===============================')
|
29
|
+
logger.kinfo(' CPU Usage (Top 10)')
|
30
|
+
logger.kinfo('===============================')
|
31
|
+
cpu_output = `ps aux | sort -nrk 3 | head -n 10`
|
32
|
+
logger.kinfo(cpu_output)
|
33
|
+
|
34
|
+
# Memory Usage
|
35
|
+
logger.kinfo('===============================')
|
36
|
+
logger.kinfo(' Memory Usage (Top 10)')
|
37
|
+
logger.kinfo('===============================')
|
38
|
+
mem_output = `ps aux | sort -nrk 4 | head -n 10`
|
39
|
+
logger.kinfo(mem_output)
|
40
|
+
|
41
|
+
# GPU Usage
|
30
42
|
if `which powermetrics`.strip.empty?
|
31
43
|
logger.kinfo("\n👉 GPU Usage:")
|
32
44
|
logger.kwarn('⚠️ powermetrics not installed, please run: xcode-select --install')
|
33
45
|
else
|
34
|
-
|
46
|
+
logger.kinfo('===============================')
|
47
|
+
logger.kinfo(' GPU Usage')
|
48
|
+
logger.kinfo('===============================')
|
49
|
+
gpu_output = `sudo powermetrics --samplers gpu_power -n 1 2>/dev/null`
|
50
|
+
logger.kinfo(gpu_output)
|
35
51
|
end
|
36
52
|
|
53
|
+
# Network Connections
|
37
54
|
logger.kinfo("\n👉 Top 10 Processes by Network Connections:")
|
38
55
|
lsof_output = `lsof -i -nP | grep ESTABLISHED`
|
39
56
|
counts = Hash.new(0)
|
@@ -45,6 +62,7 @@ module Kscript
|
|
45
62
|
logger.kinfo("#{proc}: #{count} connections")
|
46
63
|
end
|
47
64
|
|
65
|
+
# System Overview
|
48
66
|
logger.kinfo("\n👉 System Overview:")
|
49
67
|
cpu_core = `sysctl -n hw.ncpu`.strip
|
50
68
|
mem_size = `sysctl -n hw.memsize`.to_i / 1024 / 1024 / 1024
|
@@ -7,15 +7,12 @@
|
|
7
7
|
|
8
8
|
require 'kscript'
|
9
9
|
|
10
|
-
# 彩色输出定义
|
11
|
-
RED = "\e[1;31m"
|
12
|
-
GREEN = "\e[1;32m"
|
13
|
-
YELLOW = "\e[1;33m"
|
14
|
-
CYAN = "\e[1;36m"
|
15
|
-
NC = "\e[0m" # No Color
|
16
|
-
|
17
10
|
module Kscript
|
18
11
|
class KkTopUtils < Base
|
12
|
+
def initialize(*args, **opts)
|
13
|
+
super(*args, **opts)
|
14
|
+
end
|
15
|
+
|
19
16
|
def run
|
20
17
|
with_error_handling do
|
21
18
|
print_report
|
@@ -14,8 +14,8 @@ module Kscript
|
|
14
14
|
class KkUsdUtils < Base
|
15
15
|
API_URL = 'https://api.exchangerate-api.com/v4/latest/USD'
|
16
16
|
|
17
|
-
def initialize(currency_code =
|
18
|
-
super(**opts
|
17
|
+
def initialize(currency_code = 'CNY', *args, **opts)
|
18
|
+
super(*args, **opts)
|
19
19
|
@currency_code = currency_code
|
20
20
|
end
|
21
21
|
|
@@ -31,18 +31,9 @@ module Kscript
|
|
31
31
|
data = JSON.parse(response)
|
32
32
|
if @currency_code && data['rates'][@currency_code.upcase]
|
33
33
|
rate = data['rates'][@currency_code.upcase]
|
34
|
-
|
35
|
-
logger.kinfo("1 USD = #{rate} #{@currency_code.upcase}")
|
36
|
-
else
|
37
|
-
logger.kinfo("USD -> #{@currency_code.upcase}", rate: rate)
|
38
|
-
end
|
34
|
+
logger.kinfo("1 USD = #{rate} #{@currency_code.upcase}")
|
39
35
|
elsif @currency_code
|
40
|
-
if human_output?
|
41
|
-
end
|
42
36
|
logger.kerror("Currency code not found: #{@currency_code}")
|
43
|
-
elsif human_output?
|
44
|
-
logger.kinfo('USD Exchange Rates:')
|
45
|
-
data['rates'].each { |k, v| logger.kinfo(" 1 USD = #{v} #{k}") }
|
46
37
|
else
|
47
38
|
logger.kinfo('USD rates', rates: data['rates'])
|
48
39
|
end
|
@@ -9,9 +9,8 @@ require 'kscript'
|
|
9
9
|
|
10
10
|
module Kscript
|
11
11
|
class KkWgPassUtils < Base
|
12
|
-
def initialize(
|
13
|
-
super(**opts
|
14
|
-
@length = length.to_i
|
12
|
+
def initialize(*args, **opts)
|
13
|
+
super(*args, **opts)
|
15
14
|
end
|
16
15
|
|
17
16
|
def run
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kscript
|
4
|
+
class PostInstall
|
5
|
+
class << self
|
6
|
+
def run
|
7
|
+
setup_env_example
|
8
|
+
setup_shell_completion
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def setup_env_example
|
14
|
+
env_dir = File.expand_path('~/.kscript')
|
15
|
+
env_file = File.join(env_dir, '.env')
|
16
|
+
return if File.exist?(env_file)
|
17
|
+
|
18
|
+
FileUtils.mkdir_p(env_dir)
|
19
|
+
File.open(env_file, 'w') do |f|
|
20
|
+
f.puts "# kscript config: all variables are optional, remove '#' to enable"
|
21
|
+
f.puts '# AWS S3 upload config'
|
22
|
+
f.puts '# AWS_BUCKET=my-bucket # S3 bucket name'
|
23
|
+
f.puts '# AWS_REGION=ap-northeast-1 # AWS region, e.g. ap-northeast-1'
|
24
|
+
f.puts '# AWS_ACCESS_KEY_ID=xxx # AWS access key id'
|
25
|
+
f.puts '# AWS_SECRET_ACCESS_KEY=yyy # AWS secret access key'
|
26
|
+
f.puts
|
27
|
+
f.puts '# Shell environment (auto detected, usually not needed)'
|
28
|
+
f.puts '# SHELL=/bin/zsh # User shell'
|
29
|
+
f.puts '# HOME=/Users/yourname # User home directory'
|
30
|
+
f.puts
|
31
|
+
f.puts '# Logging config'
|
32
|
+
f.puts '# KSCRIPT_LOG_LEVEL=info # Log level: debug, info, warn, error, fatal'
|
33
|
+
f.puts '# LOG=1 # Enable structured log output'
|
34
|
+
end
|
35
|
+
puts '[kscript] ~/.kscript/.env example created. Edit and uncomment as needed.'
|
36
|
+
end
|
37
|
+
|
38
|
+
def setup_shell_completion
|
39
|
+
setup_bash_completion
|
40
|
+
setup_zsh_completion
|
41
|
+
end
|
42
|
+
|
43
|
+
def setup_bash_completion
|
44
|
+
return unless File.exist?(bashrc_path)
|
45
|
+
|
46
|
+
completion_path = find_completion_file('kscript.bash')
|
47
|
+
return if completion_path.nil?
|
48
|
+
|
49
|
+
source_line = "source \"#{completion_path}\""
|
50
|
+
content = File.read(bashrc_path)
|
51
|
+
if content.match?(/source.*kscript\.bash/)
|
52
|
+
# Update existing config
|
53
|
+
new_content = content.gsub(/source.*kscript\.bash.*$/, source_line)
|
54
|
+
File.write(bashrc_path, new_content)
|
55
|
+
else
|
56
|
+
# Append new config
|
57
|
+
File.open(bashrc_path, 'a') do |f|
|
58
|
+
f.puts "\n# Kscript completion"
|
59
|
+
f.puts source_line
|
60
|
+
end
|
61
|
+
end
|
62
|
+
puts "✅ Bash completion configured in #{bashrc_path}"
|
63
|
+
rescue StandardError => e
|
64
|
+
puts "⚠️ Failed to configure Bash completion: #{e.message}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def setup_zsh_completion
|
68
|
+
return unless File.exist?(zshrc_path)
|
69
|
+
|
70
|
+
completion_path = find_completion_file('kscript.zsh')
|
71
|
+
return if completion_path.nil?
|
72
|
+
|
73
|
+
source_lines = [
|
74
|
+
"source \"#{completion_path}\"",
|
75
|
+
'autoload -Uz compinit && compinit'
|
76
|
+
]
|
77
|
+
content = File.read(zshrc_path)
|
78
|
+
if content.match?(/source.*kscript\.zsh/)
|
79
|
+
# Update existing config
|
80
|
+
new_content = content.gsub(/source.*kscript\.zsh.*$/, source_lines[0])
|
81
|
+
File.write(zshrc_path, new_content)
|
82
|
+
else
|
83
|
+
# Append new config
|
84
|
+
File.open(zshrc_path, 'a') do |f|
|
85
|
+
f.puts "\n# Kscript completion"
|
86
|
+
source_lines.each { |line| f.puts line unless content.include?(line) }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
puts "✅ Zsh completion configured in #{zshrc_path}"
|
90
|
+
rescue StandardError => e
|
91
|
+
puts "⚠️ Failed to configure Zsh completion: #{e.message}"
|
92
|
+
end
|
93
|
+
|
94
|
+
def find_completion_file(filename)
|
95
|
+
# Try all possible paths
|
96
|
+
paths = [
|
97
|
+
# Dev path
|
98
|
+
File.expand_path("../completions/#{filename}", __FILE__),
|
99
|
+
# Gem install paths
|
100
|
+
*Gem.path.map { |path| File.join(path, "gems/kscript-*/lib/completions/#{filename}") },
|
101
|
+
# System paths
|
102
|
+
"/usr/local/share/kscript/completions/#{filename}",
|
103
|
+
"/usr/share/kscript/completions/#{filename}"
|
104
|
+
]
|
105
|
+
paths.each do |path|
|
106
|
+
if path.include?('*')
|
107
|
+
matches = Dir.glob(path)
|
108
|
+
return matches.first if matches.any?
|
109
|
+
elsif File.exist?(path)
|
110
|
+
return path
|
111
|
+
end
|
112
|
+
end
|
113
|
+
puts "⚠️ Could not find completion file: #{filename}"
|
114
|
+
puts 'Searched paths:'
|
115
|
+
paths.each { |path| puts " - #{path}" }
|
116
|
+
nil
|
117
|
+
end
|
118
|
+
|
119
|
+
def bashrc_path
|
120
|
+
File.join(Dir.home, '.bashrc')
|
121
|
+
end
|
122
|
+
|
123
|
+
def zshrc_path
|
124
|
+
File.join(Dir.home, '.zshrc')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/lib/kscript/utils.rb
CHANGED
@@ -1,57 +1 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Kscript
|
4
|
-
module Utils
|
5
|
-
class Config
|
6
|
-
DEFAULT_PATH = File.expand_path('~/.kscriptrc')
|
7
|
-
|
8
|
-
def self.load
|
9
|
-
@load ||= new
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@data = File.exist?(DEFAULT_PATH) ? YAML.load_file(DEFAULT_PATH) : {}
|
14
|
-
end
|
15
|
-
|
16
|
-
def [](key)
|
17
|
-
@data[key.to_s] || ENV["KSCRIPT_#{key.to_s.upcase}"]
|
18
|
-
end
|
19
|
-
|
20
|
-
def log_level
|
21
|
-
self['log_level']
|
22
|
-
end
|
23
|
-
|
24
|
-
# 自动检测并安装 shell 补全脚本
|
25
|
-
def self.ensure_completion_installed(shell = nil)
|
26
|
-
shell ||= ENV['SHELL']
|
27
|
-
home = Dir.respond_to?(:home) ? Dir.home : ENV['HOME']
|
28
|
-
return unless shell && home
|
29
|
-
|
30
|
-
if shell.include?('zsh')
|
31
|
-
completion_path = File.join(home, '.zsh/completions/_kscript')
|
32
|
-
shell_type = 'zsh'
|
33
|
-
elsif shell.include?('bash')
|
34
|
-
completion_path = File.join(home, '.bash_completion.d/kscript')
|
35
|
-
shell_type = 'bash'
|
36
|
-
else
|
37
|
-
return
|
38
|
-
end
|
39
|
-
|
40
|
-
# 已存在则跳过
|
41
|
-
return if File.exist?(completion_path)
|
42
|
-
|
43
|
-
# 生成补全脚本内容
|
44
|
-
require_relative 'cli'
|
45
|
-
script = case shell_type
|
46
|
-
when 'zsh' then Kscript::CLI.new.completion('zsh', capture: true)
|
47
|
-
when 'bash' then Kscript::CLI.new.completion('bash', capture: true)
|
48
|
-
end
|
49
|
-
FileUtils.mkdir_p(File.dirname(completion_path))
|
50
|
-
File.write(completion_path, script)
|
51
|
-
puts "\e[32m[kscript] Shell completion installed to #{completion_path}\e[0m"
|
52
|
-
rescue StandardError => e
|
53
|
-
warn "[kscript] Failed to install shell completion: #{e.message}"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
data/lib/kscript/version.rb
CHANGED
data/lib/kscript.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kscript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kk
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-07-
|
11
|
+
date: 2025-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk-s3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.130'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.130'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bcrypt
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -30,6 +44,20 @@ dependencies:
|
|
30
44
|
- - "<"
|
31
45
|
- !ruby/object:Gem::Version
|
32
46
|
version: '4.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: dotenv
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.0'
|
33
61
|
- !ruby/object:Gem::Dependency
|
34
62
|
name: http
|
35
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,6 +98,20 @@ dependencies:
|
|
70
98
|
- - "<"
|
71
99
|
- !ruby/object:Gem::Version
|
72
100
|
version: '2.0'
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: rake
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - "~>"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '13.0'
|
108
|
+
type: :runtime
|
109
|
+
prerelease: false
|
110
|
+
version_requirements: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - "~>"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '13.0'
|
73
115
|
- !ruby/object:Gem::Dependency
|
74
116
|
name: thor
|
75
117
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,36 +132,38 @@ dependencies:
|
|
90
132
|
requirements:
|
91
133
|
- - "~>"
|
92
134
|
- !ruby/object:Gem::Version
|
93
|
-
version: '1.
|
135
|
+
version: '1.21'
|
94
136
|
type: :development
|
95
137
|
prerelease: false
|
96
138
|
version_requirements: !ruby/object:Gem::Requirement
|
97
139
|
requirements:
|
98
140
|
- - "~>"
|
99
141
|
- !ruby/object:Gem::Version
|
100
|
-
version: '1.
|
142
|
+
version: '1.21'
|
101
143
|
description: Kscript provides a set of handy Ruby scripts for system administration,
|
102
144
|
development, and automation.
|
103
145
|
email:
|
104
146
|
- kevin197011@outlook.com
|
105
147
|
executables:
|
106
148
|
- kscript
|
107
|
-
extensions:
|
149
|
+
extensions:
|
150
|
+
- ext/mkrf_conf.rb
|
108
151
|
extra_rdoc_files: []
|
109
152
|
files:
|
110
|
-
- Gemfile
|
111
|
-
- LICENSE
|
112
153
|
- README.md
|
113
|
-
-
|
114
|
-
-
|
115
|
-
- kscript.
|
154
|
+
- exe/kscript
|
155
|
+
- ext/mkrf_conf.rb
|
156
|
+
- lib/completions/kscript.bash
|
157
|
+
- lib/completions/kscript.zsh
|
116
158
|
- lib/kscript.rb
|
117
159
|
- lib/kscript/banner.rb
|
118
160
|
- lib/kscript/base.rb
|
119
161
|
- lib/kscript/cli.rb
|
162
|
+
- lib/kscript/config.rb
|
120
163
|
- lib/kscript/logger.rb
|
121
164
|
- lib/kscript/plugins.rb
|
122
165
|
- lib/kscript/plugins/kk_apnic_utils.rb
|
166
|
+
- lib/kscript/plugins/kk_aws_s3_utils.rb
|
123
167
|
- lib/kscript/plugins/kk_cleaner_utils.rb
|
124
168
|
- lib/kscript/plugins/kk_es_fingerprint_utils.rb
|
125
169
|
- lib/kscript/plugins/kk_ffmpeg_utils.rb
|
@@ -137,14 +181,21 @@ files:
|
|
137
181
|
- lib/kscript/plugins/kk_usd_utils.rb
|
138
182
|
- lib/kscript/plugins/kk_wg_acl_utils.rb
|
139
183
|
- lib/kscript/plugins/kk_wg_pass_utils.rb
|
184
|
+
- lib/kscript/post_install.rb
|
140
185
|
- lib/kscript/utils.rb
|
141
186
|
- lib/kscript/version.rb
|
142
187
|
homepage: https://github.com/kevin197011/kscript
|
143
188
|
licenses:
|
144
189
|
- MIT
|
145
190
|
metadata:
|
191
|
+
homepage_uri: https://github.com/kevin197011/kscript
|
192
|
+
source_code_uri: https://github.com/kevin197011/kscript.git
|
193
|
+
changelog_uri: https://github.com/kevin197011/kscript/blob/main/CHANGELOG.md
|
146
194
|
rubygems_mfa_required: 'true'
|
147
|
-
post_install_message:
|
195
|
+
post_install_message: "\U0001F389 Thanks for installing kscript!\n\nShell completion
|
196
|
+
and config example will be configured automatically.\nYou may need to restart your
|
197
|
+
shell or run:\n - For Bash: source ~/.bashrc\n - For Zsh: source ~/.zshrc\n\nEdit
|
198
|
+
~/.kscript/.env to customize your environment variables.\n\nHappy scripting! \U0001F680\n"
|
148
199
|
rdoc_options: []
|
149
200
|
require_paths:
|
150
201
|
- lib
|
data/Gemfile
DELETED
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2021 kevin197011
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
data/Rakefile
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (c) 2025 kk
|
4
|
-
#
|
5
|
-
# This software is released under the MIT License.
|
6
|
-
# https://opensource.org/licenses/MIT
|
7
|
-
|
8
|
-
require 'time'
|
9
|
-
require 'rake'
|
10
|
-
require 'bundler/gem_tasks'
|
11
|
-
|
12
|
-
task default: %w[push]
|
13
|
-
|
14
|
-
task :push do
|
15
|
-
system <<-SHELL
|
16
|
-
rubocop -A
|
17
|
-
git update-index --chmod=+x push
|
18
|
-
git add .
|
19
|
-
git commit -m "Update #{Time.now}"
|
20
|
-
git pull
|
21
|
-
git push origin main
|
22
|
-
SHELL
|
23
|
-
end
|
24
|
-
|
25
|
-
# 其他自定义任务可在此添加
|
26
|
-
task :dev do
|
27
|
-
sh <<-SHELL
|
28
|
-
gem uninstall kscript -aIx
|
29
|
-
gem build kscript.gemspec
|
30
|
-
gem install kscript-*.gem
|
31
|
-
kscript help
|
32
|
-
kscript list
|
33
|
-
kscript version
|
34
|
-
SHELL
|
35
|
-
end
|
36
|
-
|
37
|
-
task :install do
|
38
|
-
sh <<-SHELL
|
39
|
-
gem uninstall kscript -aIx
|
40
|
-
gem install kscript
|
41
|
-
SHELL
|
42
|
-
end
|
data/kscript.gemspec
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'lib/kscript/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = 'kscript'
|
7
|
-
spec.version = Kscript::VERSION
|
8
|
-
spec.authors = ['Kk']
|
9
|
-
spec.email = ['kevin197011@outlook.com']
|
10
|
-
|
11
|
-
spec.summary = 'A collection of Ruby utility scripts for sysadmin and development.'
|
12
|
-
spec.description = 'Kscript provides a set of handy Ruby scripts for system administration, development, and automation.'
|
13
|
-
spec.homepage = 'https://github.com/kevin197011/kscript'
|
14
|
-
spec.license = 'MIT'
|
15
|
-
|
16
|
-
spec.required_ruby_version = '>= 3.0.0'
|
17
|
-
|
18
|
-
spec.files = Dir.chdir(__dir__) do
|
19
|
-
files = `git ls-files -z`.split("\x0")
|
20
|
-
files.select! do |f|
|
21
|
-
f =~ %r{^(lib/|bin/kscript|README|LICENSE|Rakefile|Gemfile|kscript\.gemspec)}
|
22
|
-
end
|
23
|
-
files
|
24
|
-
end
|
25
|
-
spec.bindir = 'bin'
|
26
|
-
spec.executables = ['kscript']
|
27
|
-
spec.require_paths = ['lib']
|
28
|
-
|
29
|
-
# Runtime dependencies
|
30
|
-
spec.add_dependency 'bcrypt', '>= 3.1', '< 4.0'
|
31
|
-
spec.add_dependency 'http', '>= 4.0', '< 6.0'
|
32
|
-
spec.add_dependency 'nokogiri', '>= 1.13', '< 2.0'
|
33
|
-
spec.add_dependency 'thor', '1.3.2'
|
34
|
-
|
35
|
-
# Development dependencies
|
36
|
-
spec.add_development_dependency 'rubocop', '~> 1.0'
|
37
|
-
spec.metadata['rubygems_mfa_required'] = 'true'
|
38
|
-
|
39
|
-
# spec.extensions = ['ext/install.rb'] # 已移除,防止 native extension build 错误
|
40
|
-
end
|
/data/{bin → exe}/kscript
RENAMED
File without changes
|