This repository has been archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonathan Claudius
committed
Sep 20, 2016
1 parent
779ce9b
commit c6367b1
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require 'ssh_scan/os' | ||
require 'ssh_scan/ssh_lib' | ||
require 'ssh_scan/version' | ||
require 'net/http' | ||
|
||
module SSHScan | ||
class Update | ||
def next_patch_version(version = SSHScan::VERSION) | ||
major, minor, patch = version.split(".") | ||
patch_num = patch.to_i | ||
patch_num += 1 | ||
|
||
return [major, minor, patch_num.to_s].join(".") | ||
end | ||
|
||
def next_minor_version(version = SSHScan::VERSION) | ||
major, minor, patch = version.split(".") | ||
minor_num = minor.to_i | ||
minor_num += 1 | ||
|
||
return [major, minor_num.to_s, "0"].join(".") | ||
end | ||
|
||
def next_major_version(version = SSHScan::VERSION) | ||
major, minor, patch = version.split(".") | ||
major_num = major.to_i | ||
major_num += 1 | ||
|
||
return [major_num.to_s, "0", "0"].join(".") | ||
end | ||
|
||
def gem_exists?(version = SSHScan::VERSION) | ||
uri = URI("https://rubygems.org/gems/ssh_scan/versions/#{version}") | ||
|
||
begin | ||
res = Net::HTTP.get_response(uri) | ||
rescue | ||
return false | ||
end | ||
|
||
if res.code != "200" | ||
return false | ||
else | ||
return true | ||
end | ||
end | ||
|
||
def newer_gem_available?(version = SSHScan::VERSION) | ||
if gem_exists?(next_patch_version(version)) | ||
return true | ||
end | ||
|
||
if gem_exists?(next_minor_version(version)) | ||
return true | ||
end | ||
|
||
if gem_exists?(next_major_version(version)) | ||
return true | ||
end | ||
|
||
return false | ||
end | ||
end | ||
end |