git-svn-id: https://beef.googlecode.com/svn/trunk@975 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
114 lines
3.3 KiB
Ruby
114 lines
3.3 KiB
Ruby
#!/usr/bin/env ruby
|
|
require 'rubygems'
|
|
|
|
puts "\nWelcome to the BEeF installer!"
|
|
|
|
puts "\nPlease make sure you have installed SQLite before proceeding. For instructions on how to do this please see the README file"
|
|
|
|
# array of required gems - add to as needed (specify a version if needed eg "gem_name, =x.x.x")
|
|
$gems_required = ["ansi", "term-ansicolor", "dm-core", "json", "data_objects", "do_sqlite3", "sqlite3", "dm-sqlite-adapter",
|
|
"parseconfig", "erubis", "dm-migrations"]
|
|
|
|
# array of missing non-version specific gems installed
|
|
$gems_missing = Array.new
|
|
|
|
# array of missing version specific gems installed
|
|
$gems_missing_version = Array.new
|
|
|
|
# check all required gems (dependencies) are present
|
|
def dep_check
|
|
$gems_required.each do |current_gem|
|
|
begin
|
|
if current_gem.include? ","
|
|
tokens = current_gem.split(",")
|
|
gem tokens[0], tokens[1]
|
|
else
|
|
gem current_gem
|
|
end
|
|
rescue Gem::LoadError
|
|
if current_gem.include? ","
|
|
$gems_missing_version << current_gem
|
|
else
|
|
$gems_missing << current_gem
|
|
end
|
|
end
|
|
end
|
|
if $gems_missing.length == 0 && $gems_missing_version.length == 0
|
|
return true
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
|
|
# display install options
|
|
def display_opts
|
|
puts "\n1) Install all required gems automatically\n" + "2) List required gems and exit so they can be installed manually\n" + "3) Exit installer\n\n"
|
|
option = gets
|
|
return option
|
|
end
|
|
|
|
# generate install command for missing gems
|
|
def install_command
|
|
if (RUBY_PLATFORM =~ /linux/ or RUBY_PLATFORM =~ /darwin/) and Process.uid != 0
|
|
cmd = "sudo gem install"
|
|
$gems_missing.each do |current_gem|
|
|
cmd = cmd + " #{current_gem}"
|
|
end
|
|
if $gems_missing_version.length != 0
|
|
$gems_missing_version.each do |current_gem|
|
|
if cmd == "sudo gem install"
|
|
cmd = cmd + " #{current_gem}"
|
|
else
|
|
cmd = cmd + " && sudo gem install #{current_gem}"
|
|
end
|
|
end
|
|
end
|
|
else
|
|
cmd = "gem install"
|
|
$gems_missing.each do |current_gem|
|
|
cmd = cmd + " #{current_gem}"
|
|
end
|
|
if $gems_missing_version.length != 0
|
|
$gems_missing_version.each do |current_gem|
|
|
if cmd == "gem install"
|
|
cmd = cmd + " #{current_gem}"
|
|
else
|
|
cmd = cmd + " & gem install #{current_gem}"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
cmd = cmd.delete "," "'"
|
|
cmd = cmd.gsub("=", "-v")
|
|
return cmd
|
|
end
|
|
|
|
# install missing gems
|
|
def install_gems
|
|
puts install_command + "\n"
|
|
system(install_command)
|
|
end
|
|
|
|
dep_met = dep_check()
|
|
|
|
if dep_met == false
|
|
puts "\nSome gems required by BEeF are not present on your system please select an option to continue:"
|
|
option = display_opts
|
|
while option != "1\n" and option != "2\n" and option != "3\n"
|
|
puts "\nInvalid option entered, please select a valid option to continue:"
|
|
option = display_opts
|
|
end
|
|
if option == "1\n"
|
|
install_gems
|
|
elsif option == "2\n"
|
|
cmd = install_command
|
|
puts "\nPlease run the following command to update and install all required gems:\n\n" + cmd + "\n\n"
|
|
elsif option == "3\n"
|
|
puts "\nExiting...\n\n"
|
|
end
|
|
else
|
|
puts "\nAll required gems are present - please run 'ruby beef' to start using BEeF\n\n"
|
|
puts "\nThe Default username/password are beef/beef\n\n"
|
|
puts "\nAll feedback welcome - http://beef.googlecode.com/\n\n"
|
|
end
|