ghcurl 0.3.1 → 0.4.0

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -15
  3. data/bin/ghcurl +64 -28
  4. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3771f9aa9548747795af7e008d722600ba0fff7c1e0eb5bfd18a8584ea318a10
4
- data.tar.gz: 934f5db9d22eedb5a2542d32db9a90a39848cdd3317e598362f2155fbb5365b8
3
+ metadata.gz: 93c6f4a7b36d196072151ee1b8b62785072dac59291080436ff9d387e387e966
4
+ data.tar.gz: 6f441d27a1d0daa7ba05ed44dec04f436286eac3a5b2d2621d76c340eb442b2b
5
5
  SHA512:
6
- metadata.gz: feb421e23ab902a6b6feecfe8420f8b6a3cfe4ab674fbba7730efa7c6495a89af967b257097a897a7c68fee5892b7710b7a61f1d7a46e2f8540b4e1657717450
7
- data.tar.gz: 21d1b9d1bc3e634866fdc691dca923d77e8ba2f9c04ebd86e9ce08ae9d86ec82a742b35faa19f0236790f5e9cea77cfcc8d1183eae7917adf83a1b8590d4eaf1
6
+ metadata.gz: 66263a60ee4ada61f3901bad75ec026994ccffa9839962c18aa48c6e25212bc74d16e1aa402a2c4b6e50f638d2f6efd453c048ef231bed0f9cc85cb5029402c2
7
+ data.tar.gz: 60544aa30cbc50533763400c9e4296ff4017912585fd0d8adad24bdbf65d88f89557c358de012f768ca2a2b7467d409d692bc17256b6da4ffafb705383f97a83
data/README.md CHANGED
@@ -16,28 +16,52 @@ Download files (and install) from Github releases.
16
16
 
17
17
  ## Usage
18
18
 
19
+ Download latest deb/rpm package and install, notice the argument `deb` / `rpm` are just regular expressions.
19
20
  ```bash
20
- # Download latest timeleft to ~/.cache/ghcurl
21
- ghcurl BetaPictoris/timeleft timeleft
22
-
23
- # Download timeleft version 1.1.0
24
- ghcurl BetaPictoris/timeleft timeleft -v1.1.0
25
-
21
+ ghcurl cli/cli deb -i
22
+ ghcurl cli/cli rpm -i
23
+ ```
26
24
 
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
25
+ Normal download
26
+ ```bash
27
+ # Download latest rbspy-x86_64-unknown-linux-gnu.tar.gz to ~/.cache/ghcurl
28
+ ghcurl rbspy/rbspy x86_64.*linux
30
29
 
30
+ # Download rbspy version 0.11.1
31
+ ghcurl rbspy/rbspy 'x86_64.*linux' -v0.11.1
32
+ ```
31
33
 
32
- # Download a binary and install it
34
+ Download a binary and install it to anywhere
35
+ ```bash
36
+ # Install to /usr/local/bin
33
37
  ghcurl BetaPictoris/timeleft timeleft -i
34
38
 
35
- # Download and install it to a path you like
39
+ # Install to ~/tmp/bin
36
40
  ghcurl BetaPictoris/timeleft timeleft -i ~/tmp/bin
37
41
 
38
- # Install and rename it to what you like
39
- ghcurl BetaPictoris/timeleft timeleft -i tl
42
+ # Install and rename it to, here, 'gd' in /usr/local/bin
43
+ ghcurl dlvhdr/gh-dash linux-amd64 -i gd
40
44
 
41
- # Or, like this
42
- ghcurl BetaPictoris/timeleft timeleft -i ~/tmp/bin/tl
45
+ # or, like this
46
+ ghcurl dlvhdr/gh-dash linux-amd64 -i ~/tmp/bin/gd
43
47
  ```
48
+
49
+ <br>
50
+
51
+ ## How does it works?
52
+
53
+ For future contributers and myself, I'll tell you how to maintain this.
54
+
55
+ In `ghcurl` previous to `0.3.1`, I write this code piece:
56
+ ```ruby
57
+ unless version
58
+ # Notice: releases/tag/vx.x.x/download not works!!!
59
+ # This is a link relocation
60
+ url = "https://github.com/#{repo}/releases/latest/download/#{ware}"
61
+ else
62
+ # The real download link
63
+ url = "https://github.com/#{repo}/releases/download/v#{version}/#{ware}"
64
+ end
65
+ ```
66
+
67
+ As you can see, it considers the Github router when you try to install a **latest** one, which are very unreliable, and you should specify a precise name for the thing you want to download. So from `0.4.0` I changed this via a slow but useful method: check the HTML file in the release page, and search the string user request which is not necessarily accurate, to find the download link directly.
data/bin/ghcurl CHANGED
@@ -3,7 +3,7 @@
3
3
  # File : ghcurl.rb
4
4
  # Authors : ccmywish <ccmywish@qq.com>
5
5
  # Created on : <2022-04-12>
6
- # Last modified : <2022-04-12>
6
+ # Last modified : <2022-04-13>
7
7
  #
8
8
  # ghcurl:
9
9
  #
@@ -11,23 +11,36 @@
11
11
  #
12
12
  # ------------------------------------------------------
13
13
 
14
+ require 'nokogiri'
15
+ require 'open-uri'
16
+
14
17
  module Ghcurl
15
18
 
16
- VERSION = "0.3.1"
19
+ VERSION = "0.4.0"
17
20
  WAREHOUSE = File.expand_path("~/.cache/ghcurl")
18
21
  BIN_PATH = "/usr/local/bin"
19
22
 
20
23
  class Error < StandardError; end
24
+
25
+
26
+ def bold(str) "\e[1m#{str}\e[0m" end
27
+ def green(str) "\e[32m#{str}\e[0m" end
28
+ def blue(str) "\e[34m#{str}\e[0m" end
29
+
30
+
31
+ def log(msg)
32
+ puts blue(bold("ghcurl: #{msg}"))
33
+ end
21
34
 
22
35
 
23
- def curl(url, ware)
36
+ def curl(url, name)
24
37
  #if !test('d', WAREHOUSE)
25
38
  # require 'fileutils'
26
39
  # FileUtils.mkdir_p(WAREHOUSE)
27
40
  #end
28
- cmd = "curl -L #{url} --create-dirs -o #{WAREHOUSE}/#{ware}"
41
+ cmd = "curl -L #{url} --create-dirs -o #{WAREHOUSE}/#{name}"
29
42
  system cmd
30
- puts "ghcurl: Downloaded to #{WAREHOUSE}/#{ware}"
43
+ log "Downloaded to #{WAREHOUSE}/#{name}"
31
44
  end
32
45
 
33
46
 
@@ -40,18 +53,37 @@ module Ghcurl
40
53
  repo = uri.path.split('/')[1,2].join('/')
41
54
  end
42
55
 
56
+ log "checking..."
43
57
  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}"
58
+ doc = Nokogiri::HTML5 URI.open("https://github.com/#{repo}/releases/latest")
47
59
  else
48
- # The real download link
49
- url = "https://github.com/#{repo}/releases/download/v#{version}/#{ware}"
60
+ doc = Nokogiri::HTML5 URI.open("https://github.com/#{repo}/releases/tag/v#{version}")
50
61
  end
51
62
 
52
- puts url
53
63
 
54
- curl(url, ware)
64
+ links = doc.css("li>a[href^='/#{repo}/releases/download']")
65
+ if links.empty?
66
+ puts doc.css('li a').map(&:to_s)
67
+ log <<~EOE
68
+ The search result is empty, check the args:
69
+ repo: #{repo}
70
+ version: #{version ? version:'nil'}
71
+ regexp: #{ware}
72
+ EOE
73
+ puts
74
+ end
75
+
76
+ link = links.each do
77
+ break _1['href'] if _1['href'] =~ /#{ware}/
78
+ end
79
+
80
+ url = "https://github.com" + link
81
+
82
+ log "Downloading #{url}"
83
+
84
+ $downloaded = link.split('/').last
85
+
86
+ curl(url, $downloaded)
55
87
 
56
88
  end
57
89
 
@@ -62,6 +94,7 @@ module Ghcurl
62
94
  else
63
95
  install_on_nix(ware, place)
64
96
  end
97
+ log "Install finish!"
65
98
  end
66
99
 
67
100
 
@@ -70,11 +103,13 @@ module Ghcurl
70
103
  target = "#{WAREHOUSE}/#{ware}"
71
104
 
72
105
  if target.end_with?('.deb')
106
+ log "Install deb package for you"
73
107
  system "sudo dpkg -i #{target}"
74
108
  return
75
109
  end
76
110
 
77
111
  if target.end_with?('.rpm')
112
+ log "Install rpm package for you"
78
113
  system "sudo rpm -i #{target}"
79
114
  return
80
115
  end
@@ -83,7 +118,7 @@ module Ghcurl
83
118
  if test 'd', place
84
119
  cmd = "sudo install -Dt #{place} -m 755 #{target} "
85
120
  system cmd
86
- puts "\nghcurl: Install #{ware} to " + place
121
+ log "Install #{ware} to " + place
87
122
 
88
123
  else
89
124
  unless place.include?('/')
@@ -92,7 +127,7 @@ module Ghcurl
92
127
  else
93
128
  # User give it a path and its name
94
129
  end
95
- puts "\nghcurl: Installed as " + place
130
+ log "Installed as " + place
96
131
  system "sudo cp #{target} #{place}"
97
132
  system "sudo chmod +x #{place}"
98
133
  end
@@ -105,10 +140,6 @@ module Ghcurl
105
140
 
106
141
 
107
142
  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
143
 
113
144
  puts blue("In #{WAREHOUSE}")
114
145
  puts
@@ -124,14 +155,19 @@ module Ghcurl
124
155
  ghcurl (v#{VERSION}): Download files (and install) from Github releases
125
156
 
126
157
  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
158
+ ghcurl repo_url regexp => Search in repo_url the latest to download
159
+ ghcurl user/repo regexp => Search in user/repo the latest to download
160
+ ghcurl url re -v tag => Download a specific tag version
161
+ ghcurl url re deb/rpm => Download and install deb/rpm package
162
+ ghcurl url re -i [path] => Download and install to /usr/local/bin
163
+ ghcurl url re -i name => Download and install as 'name'
132
164
  ghcurl -l => List downloaded files
133
165
  ghcurl -h => Print this help
134
166
 
167
+ example:
168
+ ghcurl rbspy/rbspy 'x86_64.*linux' -v0.11.1
169
+ ghcurl cli/cli deb -i
170
+
135
171
  EOC
136
172
  end
137
173
 
@@ -153,8 +189,8 @@ when nil then help ; exit
153
189
  end
154
190
 
155
191
  if ware.nil?
156
- puts "ghcurl: Download what?"
157
- puts " use: ghcurl repo file"
192
+ log "ghcurl: Download what?"
193
+ log " use: ghcurl repo file"
158
194
  exit
159
195
  end
160
196
 
@@ -186,11 +222,11 @@ case next_op
186
222
  when '-i'
187
223
  place = ARGV.shift
188
224
  if place.nil?
189
- install(ware)
225
+ install($downloaded)
190
226
  else
191
- install(ware, place: place)
227
+ install($downloaded, place: place)
192
228
  end
193
229
  when /-i.*/
194
230
  place = next_op.split('-i')[1]
195
- install(ware, place: place)
231
+ install($downloaded, place: place)
196
232
  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.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ccmywish
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2022-04-12 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
13
27
  description: Download files (and install) from Github releases.
14
28
  email:
15
29
  - ccmywish@qq.com