Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 136 lines (113 sloc) 2.35 KB
#!/usr/bin/env ruby
Version = '0.0.1 mac edition'
#curl -L http://goo.gl/Vk252 | bash
#sudo curl -L http://goo.gl/8i6Fu -o /usr/bin/apt-nyaa && sudo chmod +x /usr/bin/apt-nyaa
def gem_available?(name)
Gem::Specification.find_by_name(name)
rescue Gem::LoadError
false
rescue
Gem.available?(name)
end
unless gem_available?("colorize")
puts "[WARNING]: Please install colorize: gem install colorize"
else
require 'colorize'
end
def is_brew?
`which brew` != ''
end
unless is_brew?
puts "[WARNING]: Please install brew: apt-nyaa install brew (it uses almost for all installations)"
end
def is_color?
String.method_defined?(:colorize)
end
unless is_color?
class String
def colorize(color)
self
end
end
end
if `id -u`.to_i == 0
puts 'apt-nyaa launched by root, will exit now'
puts 'please launch as normal user'
exit
end
Commands = {:install => '', :list => '', :cat => '', :search => '', :upgrade => ''}
def curl
'curl -L -s'
end
def get(url)
require 'net/http'
require 'uri'
uri = URI.parse(url)
resp = Net::HTTP.get_response(uri)
end
def address
'https://raw.github.com/nyaa/MacScript/master'
end
def version
"apt-nyaa #{Version}"
end
def commands_list
nil
end
def help
[version, commands_list].join("\n")
end
def second_parametres
dup = ARGV.dup
dup.delete_at(0)
dup
end
def install
dup = second_parametres
puts "You didn't choose what do you want to install" if dup.empty?
dup.each do |i|
url = "#{address}/FirstInstall/#{i}"
puts "installing".colorize(:light_green)+" #{url}"
exec "#{curl} #{url}| bash -s stable"
end
end
def list_txt
list = `#{curl} #{address}/FirstInstall/list.txt`
arr = list.split("\n").sort
end
def search
arr = list_txt
second_parametres.each do |p|
if arr.include?(p)
puts "[OK]".colorize(:light_green)+": #{p}"
else
puts "[FAIL]".colorize(:light_red) +": #{p}"
end
end
end
def cat
puts `#{curl} #{address}/FirstInstall/#{ARGV[1]} | cat`
end
def upgrade
`sudo #{curl} #{address}/apt-nyaa -o /usr/bin/apt-nyaa && sudo chmod +x /usr/bin/apt-nyaa`
end
case ARGV[0]
when 'install'
install
when 'cat'
cat
when 'list'
puts list_txt
when 'search'
search
when 'help'
puts help
when 'version'
puts version
when 'upgrade'
upgrade
when nil
puts help
else
puts "#{ARGV[0]} command not found"
end