ghcurl 0.1.0 → 0.3.1
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/LICENSE +22 -0
- data/README.md +27 -19
- data/bin/ghcurl +196 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3771f9aa9548747795af7e008d722600ba0fff7c1e0eb5bfd18a8584ea318a10
|
4
|
+
data.tar.gz: 934f5db9d22eedb5a2542d32db9a90a39848cdd3317e598362f2155fbb5365b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: feb421e23ab902a6b6feecfe8420f8b6a3cfe4ab674fbba7730efa7c6495a89af967b257097a897a7c68fee5892b7710b7a61f1d7a46e2f8540b4e1657717450
|
7
|
+
data.tar.gz: 21d1b9d1bc3e634866fdc691dca923d77e8ba2f9c04ebd86e9ce08ae9d86ec82a742b35faa19f0236790f5e9cea77cfcc8d1183eae7917adf83a1b8590d4eaf1
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 ccmywish
|
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.
|
data/README.md
CHANGED
@@ -1,35 +1,43 @@
|
|
1
|
-
|
1
|
+
<div align="center">
|
2
2
|
|
3
|
-
|
3
|
+
# ghcurl
|
4
4
|
|
5
|
-
|
5
|
+
[](https://rubygems.org/gems/ghcurl)
|
6
6
|
|
7
|
-
|
7
|
+
```bash
|
8
|
+
gem install ghcurl
|
9
|
+
```
|
8
10
|
|
9
|
-
|
11
|
+
<br>
|
10
12
|
|
11
|
-
|
12
|
-
gem 'ghcurl'
|
13
|
-
```
|
13
|
+
Download files (and install) from Github releases.
|
14
14
|
|
15
|
-
|
15
|
+
</div>
|
16
16
|
|
17
|
-
|
17
|
+
## Usage
|
18
18
|
|
19
|
-
|
19
|
+
```bash
|
20
|
+
# Download latest timeleft to ~/.cache/ghcurl
|
21
|
+
ghcurl BetaPictoris/timeleft timeleft
|
20
22
|
|
21
|
-
|
23
|
+
# Download timeleft version 1.1.0
|
24
|
+
ghcurl BetaPictoris/timeleft timeleft -v1.1.0
|
22
25
|
|
23
|
-
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
# Download deb/rpm and install it
|
28
|
+
ghcurl cli/cli gh_2.7.0_linux_amd64.deb -i
|
29
|
+
ghcurl cli/cli gh_2.7.0_linux_amd64.rpm -i
|
26
30
|
|
27
|
-
## Development
|
28
31
|
|
29
|
-
|
32
|
+
# Download a binary and install it
|
33
|
+
ghcurl BetaPictoris/timeleft timeleft -i
|
30
34
|
|
31
|
-
|
35
|
+
# Download and install it to a path you like
|
36
|
+
ghcurl BetaPictoris/timeleft timeleft -i ~/tmp/bin
|
32
37
|
|
33
|
-
|
38
|
+
# Install and rename it to what you like
|
39
|
+
ghcurl BetaPictoris/timeleft timeleft -i tl
|
34
40
|
|
35
|
-
|
41
|
+
# Or, like this
|
42
|
+
ghcurl BetaPictoris/timeleft timeleft -i ~/tmp/bin/tl
|
43
|
+
```
|
data/bin/ghcurl
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# ------------------------------------------------------
|
3
|
+
# File : ghcurl.rb
|
4
|
+
# Authors : ccmywish <ccmywish@qq.com>
|
5
|
+
# Created on : <2022-04-12>
|
6
|
+
# Last modified : <2022-04-12>
|
7
|
+
#
|
8
|
+
# ghcurl:
|
9
|
+
#
|
10
|
+
# Download files (and install) from Github releases
|
11
|
+
#
|
12
|
+
# ------------------------------------------------------
|
13
|
+
|
14
|
+
module Ghcurl
|
15
|
+
|
16
|
+
VERSION = "0.3.1"
|
17
|
+
WAREHOUSE = File.expand_path("~/.cache/ghcurl")
|
18
|
+
BIN_PATH = "/usr/local/bin"
|
19
|
+
|
20
|
+
class Error < StandardError; end
|
21
|
+
|
22
|
+
|
23
|
+
def curl(url, ware)
|
24
|
+
#if !test('d', WAREHOUSE)
|
25
|
+
# require 'fileutils'
|
26
|
+
# FileUtils.mkdir_p(WAREHOUSE)
|
27
|
+
#end
|
28
|
+
cmd = "curl -L #{url} --create-dirs -o #{WAREHOUSE}/#{ware}"
|
29
|
+
system cmd
|
30
|
+
puts "ghcurl: Downloaded to #{WAREHOUSE}/#{ware}"
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def download(repo, ware, version: nil)
|
35
|
+
|
36
|
+
if repo =~ /^https:\/\/github.com/
|
37
|
+
require 'uri'
|
38
|
+
uri = URI(repo)
|
39
|
+
# index 1, take 2
|
40
|
+
repo = uri.path.split('/')[1,2].join('/')
|
41
|
+
end
|
42
|
+
|
43
|
+
unless version
|
44
|
+
# Notice: releases/tag/vx.x.x/download not works!!!
|
45
|
+
# This is a link relocation
|
46
|
+
url = "https://github.com/#{repo}/releases/latest/download/#{ware}"
|
47
|
+
else
|
48
|
+
# The real download link
|
49
|
+
url = "https://github.com/#{repo}/releases/download/v#{version}/#{ware}"
|
50
|
+
end
|
51
|
+
|
52
|
+
puts url
|
53
|
+
|
54
|
+
curl(url, ware)
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def install(ware, place: BIN_PATH)
|
59
|
+
case RUBY_PLATFORM
|
60
|
+
when /ucrt/i, /mingw/i
|
61
|
+
install_on_windows(ware, place)
|
62
|
+
else
|
63
|
+
install_on_nix(ware, place)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def install_on_nix(ware, place)
|
69
|
+
|
70
|
+
target = "#{WAREHOUSE}/#{ware}"
|
71
|
+
|
72
|
+
if target.end_with?('.deb')
|
73
|
+
system "sudo dpkg -i #{target}"
|
74
|
+
return
|
75
|
+
end
|
76
|
+
|
77
|
+
if target.end_with?('.rpm')
|
78
|
+
system "sudo rpm -i #{target}"
|
79
|
+
return
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
if test 'd', place
|
84
|
+
cmd = "sudo install -Dt #{place} -m 755 #{target} "
|
85
|
+
system cmd
|
86
|
+
puts "\nghcurl: Install #{ware} to " + place
|
87
|
+
|
88
|
+
else
|
89
|
+
unless place.include?('/')
|
90
|
+
# User just give it another name
|
91
|
+
place = BIN_PATH + '/' + place
|
92
|
+
else
|
93
|
+
# User give it a path and its name
|
94
|
+
end
|
95
|
+
puts "\nghcurl: Installed as " + place
|
96
|
+
system "sudo cp #{target} #{place}"
|
97
|
+
system "sudo chmod +x #{place}"
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
def install_on_windows
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
def list_wares
|
108
|
+
|
109
|
+
def bold(str) "\e[1m#{str}\e[0m" end
|
110
|
+
def green(str) "\e[32m#{str}\e[0m" end
|
111
|
+
def blue(str) "\e[34m#{str}\e[0m" end
|
112
|
+
|
113
|
+
puts blue("In #{WAREHOUSE}")
|
114
|
+
puts
|
115
|
+
Dir.children(WAREHOUSE).each_with_index do |dict,i|
|
116
|
+
puts " #{blue(i+1)}. #{bold(green(dict))}"
|
117
|
+
end
|
118
|
+
puts
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def help
|
123
|
+
puts <<~EOC
|
124
|
+
ghcurl (v#{VERSION}): Download files (and install) from Github releases
|
125
|
+
|
126
|
+
usage:
|
127
|
+
ghcurl repo_url file => Specify a repo's url
|
128
|
+
ghcurl user/repo file => Specify by user/repo
|
129
|
+
ghcurl xxx -v tag => Specify a tag version
|
130
|
+
ghcurl xxx -i [path] => Download and install, default to /usr/local/bin
|
131
|
+
ghcurl xxx -i filename => Download and install it as filename
|
132
|
+
ghcurl -l => List downloaded files
|
133
|
+
ghcurl -h => Print this help
|
134
|
+
|
135
|
+
EOC
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
####################
|
143
|
+
# main: CLI Handling
|
144
|
+
####################
|
145
|
+
extend Ghcurl
|
146
|
+
|
147
|
+
# e.g. ccmywish/binary
|
148
|
+
gh_repo, ware = ARGV.shift(2)
|
149
|
+
case gh_repo
|
150
|
+
when '-l' then list_wares ; exit
|
151
|
+
when '-h', '--help' then help ; exit
|
152
|
+
when nil then help ; exit
|
153
|
+
end
|
154
|
+
|
155
|
+
if ware.nil?
|
156
|
+
puts "ghcurl: Download what?"
|
157
|
+
puts " use: ghcurl repo file"
|
158
|
+
exit
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
arg = ARGV.shift
|
163
|
+
|
164
|
+
next_op = true
|
165
|
+
|
166
|
+
case arg
|
167
|
+
when '-v'
|
168
|
+
download gh_repo, ware, version: ARGV.shift
|
169
|
+
when /-v\d.*/
|
170
|
+
v = arg.split('-v')[1]
|
171
|
+
download gh_repo, ware, version: v
|
172
|
+
else
|
173
|
+
download gh_repo, ware
|
174
|
+
next_op = false
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
if next_op
|
179
|
+
next_op = ARGV.shift
|
180
|
+
else
|
181
|
+
next_op = arg
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
case next_op
|
186
|
+
when '-i'
|
187
|
+
place = ARGV.shift
|
188
|
+
if place.nil?
|
189
|
+
install(ware)
|
190
|
+
else
|
191
|
+
install(ware, place: place)
|
192
|
+
end
|
193
|
+
when /-i.*/
|
194
|
+
place = next_op.split('-i')[1]
|
195
|
+
install(ware, place: place)
|
196
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghcurl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ccmywish
|
@@ -13,13 +13,16 @@ dependencies: []
|
|
13
13
|
description: Download files (and install) from Github releases.
|
14
14
|
email:
|
15
15
|
- ccmywish@qq.com
|
16
|
-
executables:
|
16
|
+
executables:
|
17
|
+
- ghcurl
|
17
18
|
extensions: []
|
18
19
|
extra_rdoc_files: []
|
19
20
|
files:
|
20
21
|
- Gemfile
|
22
|
+
- LICENSE
|
21
23
|
- README.md
|
22
24
|
- Rakefile
|
25
|
+
- bin/ghcurl
|
23
26
|
homepage: https://github.com/ccmywish/ghcurl
|
24
27
|
licenses:
|
25
28
|
- MIT
|