summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/graph/json_builder.rb29
-rw-r--r--lib/tasks/gitlab/backup.rake74
-rw-r--r--lib/tasks/gitlab/check.rake101
-rw-r--r--lib/tasks/gitlab/enable_automerge.rake36
-rw-r--r--lib/tasks/gitlab/enable_namespaces.rake28
-rw-r--r--lib/tasks/gitlab/gitolite_rebuild.rake21
-rw-r--r--lib/tasks/gitlab/info.rake26
-rw-r--r--lib/tasks/gitlab/task_helpers.rake39
8 files changed, 189 insertions, 165 deletions
diff --git a/lib/gitlab/graph/json_builder.rb b/lib/gitlab/graph/json_builder.rb
index a5914363393..443704044c7 100644
--- a/lib/gitlab/graph/json_builder.rb
+++ b/lib/gitlab/graph/json_builder.rb
@@ -97,7 +97,7 @@ module Gitlab
if leaves.empty?
return
end
- space = find_free_space(leaves.last.time..leaves.first.time)
+ space = find_free_space(leaves, map)
leaves.each{|l| l.space = space}
# and mark it as reserved
min_time = leaves.last.time
@@ -119,7 +119,7 @@ module Gitlab
# Visit branching chains
leaves.each do |l|
- parents = l.parents.collect.select{|p| map.include? p.id and map[p.id].space == 0}
+ parents = l.parents.collect.select{|p| map.include? p.id and map[p.id].space.zero?}
for p in parents
place_chain(map[p.id], map, l.time)
end
@@ -132,18 +132,29 @@ module Gitlab
end
end
- def find_free_space(time_range)
+ def find_free_space(leaves, map)
+ time_range = leaves.last.time..leaves.first.time
reserved = []
for day in time_range
reserved += @_reserved[day]
end
- space = 1
+ space = base_space(leaves, map)
while reserved.include? space do
space += 1
end
space
end
+ def base_space(leaves, map)
+ parents = []
+ leaves.each do |l|
+ parents.concat l.parents.collect.select{|p| map.include? p.id and map[p.id].space.nonzero?}
+ end
+
+ space = parents.map{|p| map[p.id].space}.max || 0
+ space += 1
+ end
+
# Takes most left subtree branch of commits
# which don't have space mark yet.
#
@@ -156,13 +167,13 @@ module Gitlab
leaves.push(commit) if commit.space.zero?
while true
- parent = commit.parents.collect.select do |p|
- map.include? p.id and map[p.id].space == 0
- end
+ return leaves if commit.parents.count.zero?
+ return leaves unless map.include? commit.parents.first.id
+
+ commit = map[commit.parents.first.id]
- return leaves if parent.count.zero?
+ return leaves unless commit.space.zero?
- commit = map[parent.first.id]
leaves.push(commit)
end
end
diff --git a/lib/tasks/gitlab/backup.rake b/lib/tasks/gitlab/backup.rake
index 44da6d671e0..3595ba222a2 100644
--- a/lib/tasks/gitlab/backup.rake
+++ b/lib/tasks/gitlab/backup.rake
@@ -5,6 +5,8 @@ namespace :gitlab do
# Create backup of GitLab system
desc "GITLAB | Create a backup of the GitLab system"
task :create => :environment do
+ warn_user_is_not_gitlab
+
Rake::Task["gitlab:backup:db:create"].invoke
Rake::Task["gitlab:backup:repo:create"].invoke
@@ -22,23 +24,23 @@ namespace :gitlab do
end
# create archive
- print "Creating backup archive: #{Time.now.to_i}_gitlab_backup.tar "
+ print "Creating backup archive: #{Time.now.to_i}_gitlab_backup.tar ... "
if Kernel.system("tar -cf #{Time.now.to_i}_gitlab_backup.tar repositories/ db/ backup_information.yml")
- puts "[DONE]".green
+ puts "done".green
else
- puts "[FAILED]".red
+ puts "failed".red
end
# cleanup: remove tmp files
- print "Deleting tmp directories..."
+ print "Deleting tmp directories ... "
if Kernel.system("rm -rf repositories/ db/ backup_information.yml")
- puts "[DONE]".green
+ puts "done".green
else
- puts "[FAILED]".red
+ puts "failed".red
end
# delete backups
- print "Deleting old backups... "
+ print "Deleting old backups ... "
if Gitlab.config.backup.keep_time > 0
file_list = Dir.glob("*_gitlab_backup.tar").map { |f| f.split(/_/).first.to_i }
file_list.sort.each do |timestamp|
@@ -46,15 +48,17 @@ namespace :gitlab do
%x{rm #{timestamp}_gitlab_backup.tar}
end
end
- puts "[DONE]".green
+ puts "done".green
else
- puts "[SKIPPING]".yellow
+ puts "skipping".yellow
end
end
# Restore backup of GitLab system
desc "GITLAB | Restore a previously created backup"
task :restore => :environment do
+ warn_user_is_not_gitlab
+
Dir.chdir(Gitlab.config.backup.path)
# check for existing backups in the backup dir
@@ -63,22 +67,22 @@ namespace :gitlab do
if file_list.count > 1 && ENV["BACKUP"].nil?
puts "Found more than one backup, please specify which one you want to restore:"
puts "rake gitlab:backup:restore BACKUP=timestamp_of_backup"
- exit 1;
+ exit 1
end
tar_file = ENV["BACKUP"].nil? ? File.join("#{file_list.first}_gitlab_backup.tar") : File.join(ENV["BACKUP"] + "_gitlab_backup.tar")
unless File.exists?(tar_file)
puts "The specified backup doesn't exist!"
- exit 1;
+ exit 1
end
- print "Unpacking backup... "
+ print "Unpacking backup ... "
unless Kernel.system("tar -xf #{tar_file}")
- puts "[FAILED]".red
+ puts "failed".red
exit 1
else
- puts "[DONE]".green
+ puts "done".green
end
settings = YAML.load_file("backup_information.yml")
@@ -86,7 +90,7 @@ namespace :gitlab do
# restoring mismatching backups can lead to unexpected problems
if settings[:gitlab_version] != %x{git rev-parse HEAD}.gsub(/\n/,"")
- puts "gitlab_version mismatch:".red
+ puts "GitLab version mismatch:".red
puts " Your current HEAD differs from the HEAD in the backup!".red
puts " Please switch to the following revision and try again:".red
puts " revision: #{settings[:gitlab_version]}".red
@@ -97,11 +101,11 @@ namespace :gitlab do
Rake::Task["gitlab:backup:repo:restore"].invoke
# cleanup: remove tmp files
- print "Deleting tmp directories..."
+ print "Deleting tmp directories ... "
if Kernel.system("rm -rf repositories/ db/ backup_information.yml")
- puts "[DONE]".green
+ puts "done".green
else
- puts "[FAILED]".red
+ puts "failed".red
end
end
@@ -114,26 +118,26 @@ namespace :gitlab do
task :create => :environment do
backup_path_repo = File.join(Gitlab.config.backup.path, "repositories")
FileUtils.mkdir_p(backup_path_repo) until Dir.exists?(backup_path_repo)
- puts "Dumping repositories:"
+ puts "Dumping repositories ..."
project = Project.all.map { |n| [n.path, n.path_to_repo] }
project << ["gitolite-admin.git", File.join(Gitlab.config.git_base_path, "gitolite-admin.git")]
project.each do |project|
- print "- Dumping repository #{project.first}... "
+ print "#{project.first.yellow} ... "
if Kernel.system("cd #{project.second} > /dev/null 2>&1 && git bundle create #{backup_path_repo}/#{project.first}.bundle --all > /dev/null 2>&1")
- puts "[DONE]".green
+ puts "done".green
else
- puts "[FAILED]".red
+ puts "failed".red
end
end
end
task :restore => :environment do
backup_path_repo = File.join(Gitlab.config.backup.path, "repositories")
- puts "Restoring repositories:"
+ puts "Restoring repositories ... "
project = Project.all.map { |n| [n.path, n.path_to_repo] }
- project << ["gitolite-admin.git", File.join(File.dirname(project.first.second), "gitolite-admin.git")]
+ project << ["gitolite-admin.git", File.join(Gitlab.config.git_base_path, "gitolite-admin.git")]
project.each do |project|
- print "- Restoring repository #{project.first}... "
+ print "#{project.first.yellow} ... "
FileUtils.rm_rf(project.second) if File.dirname(project.second) # delete old stuff
if Kernel.system("cd #{File.dirname(project.second)} > /dev/null 2>&1 && git clone --bare #{backup_path_repo}/#{project.first}.bundle #{project.first}.git > /dev/null 2>&1")
permission_commands = [
@@ -141,9 +145,9 @@ namespace :gitlab do
"sudo chown -R #{Gitlab.config.ssh_user}:#{Gitlab.config.ssh_user} #{Gitlab.config.git_base_path}"
]
permission_commands.each { |command| Kernel.system(command) }
- puts "[DONE]".green
+ puts "done".green
else
- puts "[FAILED]".red
+ puts "failed".red
end
end
end
@@ -156,9 +160,9 @@ namespace :gitlab do
backup_path_db = File.join(Gitlab.config.backup.path, "db")
FileUtils.mkdir_p(backup_path_db) unless Dir.exists?(backup_path_db)
- puts "Dumping database tables:"
+ puts "Dumping database tables ... "
ActiveRecord::Base.connection.tables.each do |tbl|
- print "- Dumping table #{tbl}... "
+ print "#{tbl.yellow} ... "
count = 1
File.open(File.join(backup_path_db, tbl + ".yml"), "w+") do |file|
ActiveRecord::Base.connection.select_all("SELECT * FROM `#{tbl}`").each do |line|
@@ -167,25 +171,25 @@ namespace :gitlab do
file << output.to_yaml.gsub(/^---\n/,'') + "\n"
count += 1
end
- puts "[DONE]".green
+ puts "done".green
end
end
end
- task :restore=> :environment do
+ task :restore => :environment do
backup_path_db = File.join(Gitlab.config.backup.path, "db")
- puts "Restoring database tables:"
+ puts "Restoring database tables (loading fixtures) ... "
Rake::Task["db:reset"].invoke
Dir.glob(File.join(backup_path_db, "*.yml") ).each do |dir|
fixture_file = File.basename(dir, ".*" )
- print "- Loading fixture #{fixture_file}..."
+ print "#{fixture_file.yellow} ... "
if File.size(dir) > 0
ActiveRecord::Fixtures.create_fixtures(backup_path_db, fixture_file)
- puts "[DONE]".green
+ puts "done".green
else
- puts "[SKIPPING]".yellow
+ puts "skipping".yellow
end
end
end
diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake
index 5f1ed080fa5..72111f87567 100644
--- a/lib/tasks/gitlab/check.rake
+++ b/lib/tasks/gitlab/check.rake
@@ -48,7 +48,7 @@ namespace :gitlab do
see_database_guide,
"http://guides.rubyonrails.org/getting_started.html#configuring-a-database"
)
- check_failed
+ fix_and_rerun
end
end
@@ -65,7 +65,7 @@ namespace :gitlab do
"https://github.com/gitlabhq/gitlabhq/wiki/Migrate-from-SQLite-to-MySQL",
see_database_guide
)
- check_failed
+ fix_and_rerun
end
end
@@ -85,7 +85,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "GitLab"
)
- check_failed
+ fix_and_rerun
end
end
@@ -110,7 +110,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "GitLab"
)
- check_failed
+ fix_and_rerun
end
end
@@ -129,7 +129,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Install Init Script"
)
- check_failed
+ fix_and_rerun
end
end
@@ -155,7 +155,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Install Init Script"
)
- check_failed
+ fix_and_rerun
end
end
@@ -171,7 +171,7 @@ namespace :gitlab do
try_fixing_it(
"sudo -u gitlab -H bundle exec rake db:migrate"
)
- check_failed
+ fix_and_rerun
end
end
@@ -201,7 +201,7 @@ namespace :gitlab do
for_more_information(
"doc/raketasks/maintenance.md "
)
- check_failed
+ fix_and_rerun
end
end
end
@@ -222,7 +222,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "GitLab"
)
- check_failed
+ fix_and_rerun
end
end
@@ -242,7 +242,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "GitLab"
)
- check_failed
+ fix_and_rerun
end
end
end
@@ -290,7 +290,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "GitLab"
)
- check_failed
+ fix_and_rerun
end
end
@@ -308,7 +308,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "System Users"
)
- check_failed
+ fix_and_rerun
end
end
@@ -332,7 +332,7 @@ namespace :gitlab do
see_installation_guide_section("Gitolite"),
"https://github.com/gitlabhq/gitlabhq/issues/1059"
)
- check_failed
+ fix_and_rerun
end
end
@@ -352,7 +352,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Packages / Dependencies"
)
- check_failed
+ fix_and_rerun
end
end
@@ -378,7 +378,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Packages / Dependencies"
)
- check_failed
+ fix_and_rerun
end
end
end
@@ -434,7 +434,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
- check_failed
+ fix_and_rerun
end
# assumes #check_can_clone_gitolite_admin has been run before
@@ -466,7 +466,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
- check_failed
+ fix_and_rerun
ensure
FileUtils.rm_rf("/tmp/gitolite_gitlab_test")
end
@@ -488,7 +488,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
- check_failed
+ fix_and_rerun
end
end
@@ -511,7 +511,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
- check_failed
+ fix_and_rerun
end
end
@@ -537,7 +537,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
- check_failed
+ fix_and_rerun
end
end
@@ -582,7 +582,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
- check_failed
+ fix_and_rerun
end
end
@@ -611,7 +611,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
- check_failed
+ fix_and_rerun
end
end
@@ -635,7 +635,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Setup GitLab Hooks"
)
- check_failed
+ fix_and_rerun
end
end
@@ -666,7 +666,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Setup GitLab Hooks"
)
- check_failed
+ fix_and_rerun
end
end
@@ -688,7 +688,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
- check_failed
+ fix_and_rerun
end
end
@@ -712,7 +712,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
- check_failed
+ fix_and_rerun
end
end
@@ -738,7 +738,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
- check_failed
+ fix_and_rerun
end
end
@@ -772,7 +772,7 @@ namespace :gitlab do
for_more_information(
"doc/raketasks/maintenance.md"
)
- check_failed
+ fix_and_rerun
end
end
end
@@ -808,7 +808,7 @@ namespace :gitlab do
for_more_information(
"lib/support/rewrite-hooks.sh"
)
- check_failed
+ fix_and_rerun
next
end
@@ -822,7 +822,7 @@ namespace :gitlab do
for_more_information(
"lib/support/rewrite-hooks.sh"
)
- check_failed
+ fix_and_rerun
end
end
end
@@ -880,7 +880,7 @@ namespace :gitlab do
see_installation_guide_section("Install Init Script"),
"see log/resque.log for possible errors"
)
- check_failed
+ fix_and_rerun
end
end
end
@@ -889,7 +889,7 @@ namespace :gitlab do
# Helper methods
##########################
- def check_failed
+ def fix_and_rerun
puts " Please #{"fix the error above"} and rerun the checks.".red
end
@@ -908,29 +908,6 @@ namespace :gitlab do
puts ""
end
- # Runs the given command
- #
- # Returns nil if the command was not found
- # Returns the output of the command otherwise
- #
- # see also #run_and_match
- def run(command)
- unless `#{command} 2>/dev/null`.blank?
- `#{command}`
- end
- end
-
- # Runs the given command and matches the output agains the given pattern
- #
- # Returns nil if nothing matched
- # Retunrs the MatchData if the pattern matched
- #
- # see also #run
- # see also String#match
- def run_and_match(command, pattern)
- run(command).try(:match, pattern)
- end
-
def see_database_guide
"doc/install/databases.md"
end
@@ -952,18 +929,4 @@ namespace :gitlab do
puts " #{step}"
end
end
-
- def warn_user_is_not_gitlab
- unless @warned_user_not_gitlab
- current_user = run("whoami").chomp
- unless current_user == "gitlab"
- puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}"
- puts " You are running as user #{current_user.magenta}, we hope you know what you are doing."
- puts " Some tests may pass\/fail for the wrong reason."
- puts " For meaningful results you should run this as user #{"gitlab".magenta}."
- puts ""
- end
- @warned_user_not_gitlab = true
- end
- end
end
diff --git a/lib/tasks/gitlab/enable_automerge.rake b/lib/tasks/gitlab/enable_automerge.rake
index ed3d6368a99..d412f8b3837 100644
--- a/lib/tasks/gitlab/enable_automerge.rake
+++ b/lib/tasks/gitlab/enable_automerge.rake
@@ -1,16 +1,42 @@
namespace :gitlab do
desc "GITLAB | Enable auto merge"
task :enable_automerge => :environment do
+ warn_user_is_not_gitlab
+
+ puts "Updating repo permissions ..."
Gitlab::Gitolite.new.enable_automerge
+ puts "... #{"done".green}"
+ puts ""
+
+ print "Creating satellites for ..."
+ unless Project.count > 0
+ puts "skipping, because you have no projects".magenta
+ return
+ end
+ puts ""
+
+ Project.find_each(batch_size: 100) do |project|
+ print "#{project.name_with_namespace.yellow} ... "
- Project.find_each do |project|
- if project.repo_exists? && !project.satellite.exists?
- puts "Creating satellite for #{project.name}...".green
+ unless project.repo_exists?
+ puts "skipping, because the repo is empty".magenta
+ next
+ end
+
+ if project.satellite.exists?
+ puts "exists already".green
+ else
+ puts ""
project.satellite.create
+
+ print "... "
+ if $?.success?
+ puts "created".green
+ else
+ puts "error".red
+ end
end
end
-
- puts "Done!".green
end
namespace :satellites do
diff --git a/lib/tasks/gitlab/enable_namespaces.rake b/lib/tasks/gitlab/enable_namespaces.rake
index 1be9ba6469d..81b86d56eb3 100644
--- a/lib/tasks/gitlab/enable_namespaces.rake
+++ b/lib/tasks/gitlab/enable_namespaces.rake
@@ -1,7 +1,9 @@
namespace :gitlab do
desc "GITLAB | Enable usernames and namespaces for user projects"
task enable_namespaces: :environment do
- print "\nUsernames for users:".yellow
+ warn_user_is_not_gitlab
+
+ print "Generate usernames for users without one: "
User.find_each(batch_size: 500) do |user|
next if user.namespace
@@ -16,7 +18,8 @@ namespace :gitlab do
end
end
- print "\n\nDirs for groups:".yellow
+ puts ""
+ print "Create directories for groups: "
Group.find_each(batch_size: 500) do |group|
if group.ensure_dir_exist
@@ -25,43 +28,44 @@ namespace :gitlab do
print 'F'.red
end
end
+ puts ""
- print "\n\nMove projects from groups under groups dirs:".yellow
git_path = Gitlab.config.gitolite.repos_path
-
+ puts ""
+ puts "Move projects in groups into respective directories ... "
Project.where('namespace_id IS NOT NULL').find_each(batch_size: 500) do |project|
next unless project.group
group = project.group
- puts "\n"
- print " * #{project.name}: "
+ print "#{project.name_with_namespace.yellow} ... "
new_path = File.join(git_path, project.path_with_namespace + '.git')
if File.exists?(new_path)
- print "ok. already at #{new_path}".cyan
+ puts "already at #{new_path}".green
next
end
old_path = File.join(git_path, project.path + '.git')
unless File.exists?(old_path)
- print "missing. not found at #{old_path}".red
+ puts "couldn't find it at #{old_path}".red
next
end
begin
Gitlab::ProjectMover.new(project, '', group.path).execute
- print "ok. Moved to #{new_path}".green
+ puts "moved to #{new_path}".green
rescue
- print "Failed moving to #{new_path}".red
+ puts "failed moving to #{new_path}".red
end
end
- print "\n\nRebuild gitolite:".yellow
+ puts ""
+ puts "Rebuild Gitolite ... "
gitolite = Gitlab::Gitolite.new
gitolite.update_repositories(Project.where('namespace_id IS NOT NULL'))
- puts "\n"
+ puts "... #{"done".green}"
end
end
diff --git a/lib/tasks/gitlab/gitolite_rebuild.rake b/lib/tasks/gitlab/gitolite_rebuild.rake
index fce10eb5b69..af2a2127ee2 100644
--- a/lib/tasks/gitlab/gitolite_rebuild.rake
+++ b/lib/tasks/gitlab/gitolite_rebuild.rake
@@ -1,24 +1,27 @@
namespace :gitlab do
namespace :gitolite do
- desc "GITLAB | Rebuild each project at gitolite config"
+ desc "GITLAB | Rebuild each project in Gitolite config"
task :update_repos => :environment do
- puts "Starting Projects"
+ warn_user_is_not_gitlab
+
+ puts "Rebuilding projects ... "
Project.find_each(:batch_size => 100) do |project|
- puts "\n=== #{project.name}"
+ puts "#{project.name_with_namespace.yellow} ... "
project.update_repository
- puts
+ puts "... #{"done".green}"
end
- puts "Done with projects"
end
- desc "GITLAB | Rebuild each key at gitolite config"
+ desc "GITLAB | Rebuild each user key in Gitolite config"
task :update_keys => :environment do
- puts "Starting Key"
+ warn_user_is_not_gitlab
+
+ puts "Rebuilding keys ... "
Key.find_each(:batch_size => 100) do |key|
+ puts "#{key.identifier.yellow} ... "
Gitlab::Gitolite.new.set_key(key.identifier, key.key, key.projects)
- print '.'
+ puts "... #{"done".green}"
end
- puts "Done with keys"
end
end
end
diff --git a/lib/tasks/gitlab/info.rake b/lib/tasks/gitlab/info.rake
index 85458fe2c43..3fbedda7721 100644
--- a/lib/tasks/gitlab/info.rake
+++ b/lib/tasks/gitlab/info.rake
@@ -80,31 +80,5 @@ namespace :gitlab do
puts "Git:\t\t#{Gitlab.config.git.bin_path}"
end
-
-
- # Helper methods
-
- # Runs the given command and matches the output agains the given pattern
- #
- # Returns nil if nothing matched
- # Retunrs the MatchData if the pattern matched
- #
- # see also #run
- # see also String#match
- def run_and_match(command, regexp)
- run(command).try(:match, regexp)
- end
-
- # Runs the given command
- #
- # Returns nil if the command was not found
- # Returns the output of the command otherwise
- #
- # see also #run_and_match
- def run(command)
- unless `#{command} 2>/dev/null`.blank?
- `#{command}`
- end
- end
end
end
diff --git a/lib/tasks/gitlab/task_helpers.rake b/lib/tasks/gitlab/task_helpers.rake
new file mode 100644
index 00000000000..c9635f058ee
--- /dev/null
+++ b/lib/tasks/gitlab/task_helpers.rake
@@ -0,0 +1,39 @@
+namespace :gitlab do
+
+ # Runs the given command and matches the output agains the given pattern
+ #
+ # Returns nil if nothing matched
+ # Retunrs the MatchData if the pattern matched
+ #
+ # see also #run
+ # see also String#match
+ def run_and_match(command, regexp)
+ run(command).try(:match, regexp)
+ end
+
+ # Runs the given command
+ #
+ # Returns nil if the command was not found
+ # Returns the output of the command otherwise
+ #
+ # see also #run_and_match
+ def run(command)
+ unless `#{command} 2>/dev/null`.blank?
+ `#{command}`
+ end
+ end
+
+ def warn_user_is_not_gitlab
+ unless @warned_user_not_gitlab
+ current_user = run("whoami").chomp
+ unless current_user == "gitlab"
+ puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}"
+ puts " You are running as user #{current_user.magenta}, we hope you know what you are doing."
+ puts " Things may work\/fail for the wrong reasons."
+ puts " For correct results you should run this as user #{"gitlab".magenta}."
+ puts ""
+ end
+ @warned_user_not_gitlab = true
+ end
+ end
+end