apt-spy2 0.7.3 → 0.8.2
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/.github/dependabot.yml +6 -0
- data/.github/workflows/codeql-analysis.yml +70 -0
- data/.github/workflows/pr.yml +19 -3
- data/.github/workflows/release.yml +2 -1
- data/Dockerfile +10 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +30 -8
- data/Makefile +21 -3
- data/README.md +16 -14
- data/Rakefile +10 -17
- data/apt-spy2.gemspec +21 -18
- data/bin/apt-spy2 +3 -2
- data/lib/apt/spy2/country.rb +8 -9
- data/lib/apt/spy2/downloader.rb +14 -17
- data/lib/apt/spy2/launchpad.rb +5 -6
- data/lib/apt/spy2/request.rb +33 -0
- data/lib/apt/spy2/ubuntu_mirrors.rb +5 -7
- data/lib/apt/spy2/url.rb +28 -0
- data/lib/apt/spy2/version.rb +3 -1
- data/lib/apt/spy2/writer.rb +17 -20
- data/lib/apt/spy2.rb +74 -66
- data/test_helper.rb +30 -0
- data/tests/country_test.rb +7 -5
- data/tests/downloader_test.rb +10 -7
- data/tests/launchpad_test.rb +7 -3
- data/tests/ubuntu_mirrors_test.rb +15 -0
- data/tests/url_test.rb +23 -0
- data/tests/writer_test.rb +27 -0
- metadata +48 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7622e67a84b791b9ff1e03931d4b216d5a2bd879b0ac9334ee6ccc140e1c16b9
|
4
|
+
data.tar.gz: a5fc5ef8e9fc0a98e7448253d0e95dc6a55113b3586ae7fbfabb260d78f0c6ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f4fd668a86d485758610e2870cd7650c5875671711a027f6149a80ce63134f817b41087aa795ff40106ee39041f78f333224b5285c90d769ee4142a225f3693
|
7
|
+
data.tar.gz: d6be7ad7b4db2471f3ef28d5ae6efc4bd9e44fb09c8f3fb337330c42aed0913c784e501eab6bdc6d8f7ac252da759336d06cb2034158c4d221dce21f4fb464b9
|
data/.github/dependabot.yml
CHANGED
@@ -0,0 +1,70 @@
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
2
|
+
# to commit it to your repository.
|
3
|
+
#
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
5
|
+
# or to provide custom queries or build logic.
|
6
|
+
#
|
7
|
+
# ******** NOTE ********
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
10
|
+
# supported CodeQL languages.
|
11
|
+
#
|
12
|
+
name: "CodeQL"
|
13
|
+
|
14
|
+
on:
|
15
|
+
push:
|
16
|
+
branches: [ master ]
|
17
|
+
pull_request:
|
18
|
+
# The branches below must be a subset of the branches above
|
19
|
+
branches: [ master ]
|
20
|
+
schedule:
|
21
|
+
- cron: '43 11 * * 5'
|
22
|
+
|
23
|
+
jobs:
|
24
|
+
analyze:
|
25
|
+
name: Analyze
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
permissions:
|
28
|
+
actions: read
|
29
|
+
contents: read
|
30
|
+
security-events: write
|
31
|
+
|
32
|
+
strategy:
|
33
|
+
fail-fast: false
|
34
|
+
matrix:
|
35
|
+
language: [ 'ruby' ]
|
36
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
37
|
+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout repository
|
41
|
+
uses: actions/checkout@v3
|
42
|
+
|
43
|
+
# Initializes the CodeQL tools for scanning.
|
44
|
+
- name: Initialize CodeQL
|
45
|
+
uses: github/codeql-action/init@v2
|
46
|
+
with:
|
47
|
+
languages: ${{ matrix.language }}
|
48
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
49
|
+
# By default, queries listed here will override any specified in a config file.
|
50
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
51
|
+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
52
|
+
|
53
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
54
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
55
|
+
- name: Autobuild
|
56
|
+
uses: github/codeql-action/autobuild@v2
|
57
|
+
|
58
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
59
|
+
# 📚 https://git.io/JvXDl
|
60
|
+
|
61
|
+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
62
|
+
# and modify them (or add more) to build your code if your project
|
63
|
+
# uses a compiled language
|
64
|
+
|
65
|
+
#- run: |
|
66
|
+
# make bootstrap
|
67
|
+
# make release
|
68
|
+
|
69
|
+
- name: Perform CodeQL Analysis
|
70
|
+
uses: github/codeql-action/analyze@v2
|
data/.github/workflows/pr.yml
CHANGED
@@ -11,12 +11,12 @@ jobs:
|
|
11
11
|
strategy:
|
12
12
|
matrix:
|
13
13
|
ruby-version:
|
14
|
+
- '3.2'
|
14
15
|
- '3.1'
|
15
16
|
- '3.0'
|
16
|
-
- 2.7
|
17
|
-
- 2.6
|
17
|
+
- '2.7'
|
18
18
|
steps:
|
19
|
-
- uses: actions/checkout@
|
19
|
+
- uses: actions/checkout@v3
|
20
20
|
- uses: ruby/setup-ruby@v1
|
21
21
|
with:
|
22
22
|
ruby-version: ${{ matrix.ruby-version }}
|
@@ -26,8 +26,24 @@ jobs:
|
|
26
26
|
- run: ls -lah ./pkg/apt-spy2*
|
27
27
|
- run: gem install pkg/apt-spy2*
|
28
28
|
- run: apt-spy2 check
|
29
|
+
- run: sudo env "PATH=$PATH" apt-spy2 fix --commit
|
29
30
|
- uses: coverallsapp/github-action@master
|
30
31
|
with:
|
31
32
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
32
33
|
|
34
|
+
test_strict:
|
35
|
+
runs-on: ubuntu-latest
|
36
|
+
steps:
|
37
|
+
- uses: actions/checkout@v3
|
38
|
+
- uses: ruby/setup-ruby@v1
|
39
|
+
with:
|
40
|
+
ruby-version: 3.2
|
41
|
+
- run: bundle install
|
42
|
+
- run: bundle exec rake test
|
43
|
+
- run: bundle exec rake build
|
44
|
+
- run: ls -lah ./pkg/apt-spy2*
|
45
|
+
- run: gem install pkg/apt-spy2*
|
46
|
+
- run: apt-spy2 check --strict
|
47
|
+
- run: sudo env "PATH=$PATH" apt-spy2 fix --commit --strict
|
48
|
+
|
33
49
|
|
data/Dockerfile
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,25 +1,45 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
apt-spy2 (0.
|
4
|
+
apt-spy2 (0.8.2)
|
5
5
|
colored (>= 1.2)
|
6
6
|
json
|
7
|
-
nokogiri (
|
7
|
+
nokogiri (~> 1.14.1)
|
8
8
|
thor (>= 0.18.1)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
+
ast (2.4.2)
|
13
14
|
colored (1.2)
|
14
15
|
docile (1.4.0)
|
15
|
-
json (2.6.
|
16
|
-
mini_portile2 (2.
|
16
|
+
json (2.6.3)
|
17
|
+
mini_portile2 (2.8.1)
|
17
18
|
minitest (5.15.0)
|
18
|
-
nokogiri (1.
|
19
|
-
mini_portile2 (~> 2.
|
19
|
+
nokogiri (1.14.1)
|
20
|
+
mini_portile2 (~> 2.8.0)
|
20
21
|
racc (~> 1.4)
|
21
|
-
|
22
|
+
parallel (1.22.1)
|
23
|
+
parser (3.2.1.0)
|
24
|
+
ast (~> 2.4.1)
|
25
|
+
racc (1.6.2)
|
26
|
+
rainbow (3.1.1)
|
22
27
|
rake (13.0.6)
|
28
|
+
regexp_parser (2.7.0)
|
29
|
+
rexml (3.2.5)
|
30
|
+
rubocop (1.45.1)
|
31
|
+
json (~> 2.3)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 3.2.0.0)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
regexp_parser (>= 1.8, < 3.0)
|
36
|
+
rexml (>= 3.2.5, < 4.0)
|
37
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
38
|
+
ruby-progressbar (~> 1.7)
|
39
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
40
|
+
rubocop-ast (1.24.1)
|
41
|
+
parser (>= 3.1.1.0)
|
42
|
+
ruby-progressbar (1.11.0)
|
23
43
|
simplecov (0.21.2)
|
24
44
|
docile (~> 1.1)
|
25
45
|
simplecov-html (~> 0.11)
|
@@ -27,7 +47,8 @@ GEM
|
|
27
47
|
simplecov-html (0.12.3)
|
28
48
|
simplecov-lcov (0.8.0)
|
29
49
|
simplecov_json_formatter (0.1.3)
|
30
|
-
thor (1.1
|
50
|
+
thor (1.2.1)
|
51
|
+
unicode-display_width (2.4.2)
|
31
52
|
|
32
53
|
PLATFORMS
|
33
54
|
ruby
|
@@ -37,6 +58,7 @@ DEPENDENCIES
|
|
37
58
|
bundler (~> 2.0)
|
38
59
|
minitest (~> 5.15.0)
|
39
60
|
rake
|
61
|
+
rubocop
|
40
62
|
simplecov (~> 0.18)
|
41
63
|
simplecov-lcov (~> 0.8.0)
|
42
64
|
|
data/Makefile
CHANGED
@@ -1,11 +1,29 @@
|
|
1
|
+
.PHONY: clean install release docker-build docker-run
|
2
|
+
|
3
|
+
IMAGE?=lagged/apt-spy2:dev
|
4
|
+
|
5
|
+
container:=apt-spy2
|
6
|
+
|
7
|
+
clean:
|
8
|
+
docker rm -f $(container) || true
|
9
|
+
|
1
10
|
install:
|
2
11
|
bundle install --path ./vendor/bundle
|
3
12
|
|
4
13
|
release:
|
5
14
|
bundle exec rake release
|
6
15
|
|
16
|
+
lint:
|
17
|
+
bundle exec rubocop .
|
18
|
+
|
19
|
+
test: install
|
20
|
+
bundle exec rake test
|
21
|
+
|
7
22
|
docker-build:
|
8
|
-
docker build -t
|
23
|
+
docker build -t $(IMAGE) .
|
9
24
|
|
10
|
-
docker-run: docker-build
|
11
|
-
docker run -it
|
25
|
+
docker-run: clean docker-build
|
26
|
+
docker run --rm -it \
|
27
|
+
--name $(container) \
|
28
|
+
-v $(CURDIR):/work \
|
29
|
+
$(IMAGE) bash
|
data/README.md
CHANGED
@@ -3,20 +3,20 @@
|
|
3
3
|
… or: "apt-spy for Ubuntu"
|
4
4
|
|
5
5
|
[](https://github.com/lagged/apt-spy2/actions/workflows/pr.yml)
|
6
|
-
|
6
|
+

|
7
7
|
[](https://codeclimate.com/github/lagged/apt-spy2)
|
8
8
|
[](https://coveralls.io/r/lagged/apt-spy2)
|
9
9
|
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
13
|
-
```
|
13
|
+
```sh
|
14
14
|
gem install apt-spy2
|
15
15
|
```
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
19
|
-
```
|
19
|
+
```sh
|
20
20
|
$ apt-spy2 [21:03:52]
|
21
21
|
apt-spy2 commands:
|
22
22
|
apt-spy2 check # Evaluate mirrors
|
@@ -30,27 +30,28 @@ apt-spy2 commands:
|
|
30
30
|
Displays a list of currently available mirrors. These mirrors are automatically selected via
|
31
31
|
[ubuntu-mirrors](http://mirrors.ubuntu.com) using your IP's location.
|
32
32
|
|
33
|
-
```
|
33
|
+
```sh
|
34
34
|
$ apt-spy2 list
|
35
35
|
...
|
36
36
|
```
|
37
37
|
|
38
38
|
Since `mirrors.ubuntu.com` is frequently down, you can the list on [Launchpad](launchpad.net/ubuntu/+archivemirrors):
|
39
39
|
|
40
|
-
```
|
40
|
+
```sh
|
41
41
|
$ apt-spy2 list --launchpad --country=Germany
|
42
42
|
...
|
43
43
|
```
|
44
44
|
|
45
45
|
### check command
|
46
46
|
|
47
|
-
`check` works like `list`, but also determines if the servers returned are working. It supports
|
47
|
+
`check` works like `list`, but also determines if the servers returned are working. It supports the flag `--launchpad` as well and additionally a flag `--strict` which checks if a mirror carries a certain release and distribution.
|
48
48
|
|
49
|
-
```
|
49
|
+
```sh
|
50
50
|
$ apt-spy2 check
|
51
51
|
...
|
52
|
-
$ apt-spy2
|
52
|
+
$ apt-spy2 check --launchpad --country=US
|
53
53
|
...
|
54
|
+
$ apt-spy2 check --strict
|
54
55
|
```
|
55
56
|
|
56
57
|
### fix command
|
@@ -69,10 +70,10 @@ See `apt-spy2 help list|check|fix` for available options.
|
|
69
70
|
|
70
71
|
### exit codes
|
71
72
|
|
72
|
-
|
73
|
-
|
73
|
+
* 0 - all went well
|
74
|
+
* 1 - some kind of error
|
74
75
|
|
75
|
-
### output and non-
|
76
|
+
### output and non-interactive behavior
|
76
77
|
|
77
78
|
See `apt-spy2 help COMMAND` for more information.
|
78
79
|
|
@@ -84,6 +85,7 @@ Generally, `apt-spy2` plays especially nice in a non-interactive environment and
|
|
84
85
|
|
85
86
|
### Release (procedure)
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
88
|
+
* update version in `lib/apt/spy2/version.rb`
|
89
|
+
* `bundle install`
|
90
|
+
* `git commit -a 'Prep x.y.z'
|
91
|
+
* `git tag -a vVERSION && git push --tags`
|
data/Rakefile
CHANGED
@@ -1,24 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
5
5
|
|
6
6
|
Encoding.default_external = Encoding::UTF_8
|
7
7
|
Encoding.default_internal = Encoding::UTF_8
|
8
8
|
|
9
|
-
|
9
|
+
Rake::TestTask.new do |t|
|
10
10
|
ENV['COVERAGE'] = 'true'
|
11
|
+
t.pattern = 'tests/*_test.rb'
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
c.single_report_path = './coverage/lcov.info'
|
17
|
-
end
|
18
|
-
SimpleCov.start
|
19
|
-
|
20
|
-
$LOAD_PATH.unshift('lib', 'tests')
|
21
|
-
Dir.glob('./tests/*_test.rb') do |f|
|
22
|
-
require f
|
23
|
-
end
|
13
|
+
# $LOAD_PATH.unshift('lib', 'tests')
|
14
|
+
# Dir.glob('./tests/*_test.rb').sort.each do |f|
|
15
|
+
# require f
|
16
|
+
# end
|
24
17
|
end
|
data/apt-spy2.gemspec
CHANGED
@@ -1,33 +1,36 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'English'
|
4
|
+
lib = File.expand_path('lib', __dir__)
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
6
|
require 'apt/spy2/version'
|
5
7
|
|
6
8
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
9
|
+
spec.name = 'apt-spy2'
|
8
10
|
spec.version = Apt::Spy2::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
11
|
+
spec.authors = ['till']
|
12
|
+
spec.email = ['till@php.net']
|
13
|
+
spec.description = 'Keep your /etc/apt/sources.list up to date'
|
14
|
+
spec.summary = 'apt-spy2, or apt-spy for ubuntu'
|
15
|
+
spec.homepage = 'https://github.com/lagged/apt-spy2'
|
14
16
|
spec.license = 'BSD-2-Clause'
|
15
17
|
|
16
|
-
spec.required_ruby_version = '>= 2.
|
18
|
+
spec.required_ruby_version = '>= 2.7', '< 3.3'
|
17
19
|
|
18
|
-
spec.files = `git ls-files`.split(
|
20
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
19
21
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
22
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
-
spec.require_paths = [
|
23
|
+
spec.require_paths = ['lib']
|
22
24
|
|
23
|
-
spec.add_dependency 'thor', '>= 0.18.1'
|
24
25
|
spec.add_dependency 'colored', '>= 1.2'
|
25
26
|
spec.add_dependency 'json'
|
26
|
-
spec.add_dependency 'nokogiri', '
|
27
|
+
spec.add_dependency 'nokogiri', '~> 1.14.1'
|
28
|
+
spec.add_dependency 'thor', '>= 0.18.1'
|
27
29
|
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
30
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
31
|
+
spec.add_development_dependency 'minitest', '~> 5.15.0'
|
32
|
+
spec.add_development_dependency 'rake'
|
33
|
+
spec.add_development_dependency 'rubocop'
|
34
|
+
spec.add_development_dependency 'simplecov', '~> 0.18'
|
35
|
+
spec.add_development_dependency 'simplecov-lcov', '~> 0.8.0'
|
33
36
|
end
|
data/bin/apt-spy2
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'apt/spy2'
|
4
5
|
require 'colored'
|
@@ -8,7 +9,7 @@ Encoding.default_internal = Encoding::UTF_8
|
|
8
9
|
|
9
10
|
begin
|
10
11
|
AptSpy2.start
|
11
|
-
rescue =>
|
12
|
-
puts
|
12
|
+
rescue StandardError => e
|
13
|
+
puts e.to_s.white_on_red
|
13
14
|
exit 1
|
14
15
|
end
|
data/lib/apt/spy2/country.rb
CHANGED
@@ -1,33 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Apt
|
2
4
|
module Spy2
|
5
|
+
# lookup a country based on code
|
3
6
|
class Country
|
4
|
-
|
5
7
|
def initialize(country_database)
|
6
8
|
@database = country_database
|
7
9
|
end
|
8
10
|
|
9
11
|
def to_country_name(code)
|
10
12
|
code = code.upcase
|
11
|
-
return capitalize(code) unless code.length == 2
|
13
|
+
return capitalize!(code) unless code.length == 2
|
12
14
|
|
13
15
|
File.open(@database).each do |line|
|
14
16
|
country, tld = line.split(';', 2)
|
15
17
|
tld.gsub!(/\n/, '')
|
16
18
|
|
17
|
-
if code == tld
|
18
|
-
return capitalize(country)
|
19
|
-
end
|
20
|
-
|
19
|
+
return capitalize!(country) if code == tld
|
21
20
|
end
|
22
21
|
|
23
22
|
raise "Could not look up: #{code}"
|
24
23
|
end
|
25
24
|
|
26
25
|
private
|
27
|
-
def capitalize(str)
|
28
|
-
return str.split(" ").map(&:capitalize).join(" ")
|
29
|
-
end
|
30
26
|
|
27
|
+
def capitalize!(str)
|
28
|
+
str.split(' ').map(&:capitalize).join(' ')
|
29
|
+
end
|
31
30
|
end
|
32
31
|
end
|
33
32
|
end
|
data/lib/apt/spy2/downloader.rb
CHANGED
@@ -1,30 +1,27 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'apt/spy2/request'
|
2
4
|
|
3
5
|
module Apt
|
4
6
|
module Spy2
|
7
|
+
# download url (e.g. mirror list or launchpad page)
|
5
8
|
class Downloader
|
6
|
-
|
7
|
-
def initialize(url = nil)
|
8
|
-
@url = url if !url.nil?
|
9
|
-
end
|
10
|
-
|
11
9
|
def do_download(url = nil)
|
12
|
-
|
10
|
+
raise 'Please supply a url.' if url.nil?
|
13
11
|
|
14
|
-
|
12
|
+
req = Apt::Spy2::Request.new(url)
|
15
13
|
|
16
14
|
begin
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
response = req.get
|
16
|
+
return response.body if response.code == '200'
|
17
|
+
|
18
|
+
raise "The URL #{@url} does not exist." if response.code == '404'
|
19
|
+
|
20
|
+
raise "Status code: #{response.code}"
|
21
|
+
rescue StandardError => e
|
22
|
+
raise e
|
25
23
|
end
|
26
24
|
end
|
27
|
-
|
28
25
|
end
|
29
26
|
end
|
30
27
|
end
|
data/lib/apt/spy2/launchpad.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'nokogiri'
|
2
4
|
|
3
5
|
module Apt
|
4
6
|
module Spy2
|
7
|
+
# parse launchpad output
|
5
8
|
class Launchpad
|
6
|
-
|
7
9
|
def initialize(download)
|
8
10
|
@launchpad = download
|
9
11
|
end
|
10
12
|
|
11
|
-
def
|
12
|
-
|
13
|
+
def mirrors(country)
|
13
14
|
mirrors = []
|
14
15
|
|
15
16
|
document = Nokogiri::HTML(@launchpad)
|
@@ -27,10 +28,8 @@ module Apt
|
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
mirrors
|
32
32
|
end
|
33
|
-
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
module Apt
|
8
|
+
module Spy2
|
9
|
+
# make requests
|
10
|
+
class Request
|
11
|
+
def initialize(url)
|
12
|
+
uri = URI(url)
|
13
|
+
|
14
|
+
# sets hopefully sensible timeouts for read and connection
|
15
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
16
|
+
http.read_timeout = 10
|
17
|
+
http.open_timeout = 10
|
18
|
+
http.use_ssl = true if uri.scheme == 'https'
|
19
|
+
|
20
|
+
@http = http
|
21
|
+
@request_uri = uri.request_uri
|
22
|
+
end
|
23
|
+
|
24
|
+
def get
|
25
|
+
@http.request(Net::HTTP::Get.new(@request_uri))
|
26
|
+
end
|
27
|
+
|
28
|
+
def head
|
29
|
+
@http.request(Net::HTTP::Head.new(@request_uri))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,19 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Apt
|
2
4
|
module Spy2
|
5
|
+
# wraps around the \n delimited list of mirrors
|
3
6
|
class UbuntuMirrors
|
4
|
-
|
5
7
|
def initialize(download)
|
6
8
|
@ubuntu_mirrors = download
|
7
9
|
end
|
8
10
|
|
9
|
-
def
|
10
|
-
|
11
|
+
def mirrors(_country)
|
11
12
|
mirrors = @ubuntu_mirrors
|
12
|
-
mirrors
|
13
|
-
return mirrors
|
14
|
-
|
13
|
+
mirrors.split(/\n/)
|
15
14
|
end
|
16
|
-
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
data/lib/apt/spy2/url.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Apt
|
4
|
+
module Spy2
|
5
|
+
# build mirror url
|
6
|
+
class Url
|
7
|
+
def initialize(strict)
|
8
|
+
@strict = strict
|
9
|
+
end
|
10
|
+
|
11
|
+
def adjust!(mirror)
|
12
|
+
return mirror unless @strict
|
13
|
+
|
14
|
+
"#{mirror}dists/#{release}/Contents-#{arch}.gz"
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def arch
|
20
|
+
`dpkg --print-architecture`.strip
|
21
|
+
end
|
22
|
+
|
23
|
+
def release
|
24
|
+
`lsb_release -c`.split(' ')[1].strip
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|