45 lines
1.4 KiB
Ruby
Raw Normal View History

2016-09-24 13:52:43 +02:00
module Hbc
module Caskroom
module_function
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def migrate_caskroom_from_repo_to_prefix
repo_caskroom = Hbc.homebrew_repository.join("Caskroom")
return if Hbc.caskroom.exist?
return unless repo_caskroom.directory?
2016-09-21 17:34:15 +02:00
2016-09-24 13:52:43 +02:00
ohai "Moving Caskroom from HOMEBREW_REPOSITORY to HOMEBREW_PREFIX"
2016-09-20 15:11:33 +02:00
2016-09-24 13:52:43 +02:00
if Hbc.caskroom.parent.writable?
FileUtils.mv repo_caskroom, Hbc.caskroom
else
opoo "#{Hbc.caskroom.parent} is not writable, sudo is needed to move the Caskroom."
command "/bin/mv", repo_caskroom, Hbc.caskroom.parent, :use_sudo => true
2016-09-24 13:52:43 +02:00
end
end
2016-09-24 13:52:43 +02:00
def ensure_caskroom_exists
return if Hbc.caskroom.exist?
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
ohai "Creating Caskroom at #{Hbc.caskroom}"
ohai "We'll set permissions properly so we won't need sudo in the future"
use_sudo = !Hbc.caskroom.parent.writable?
command "/bin/mkdir", "-p", Hbc.caskroom, :use_sudo => use_sudo
command "/bin/chmod", "g+rwx", Hbc.caskroom, :use_sudo => use_sudo
command "/usr/sbin/chown", Utils.current_user, Hbc.caskroom, :use_sudo => use_sudo
command "/usr/bin/chgrp", "admin", Hbc.caskroom, :use_sudo => use_sudo
end
def command(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
if options[:use_sudo]
args.unshift "/usr/bin/sudo"
end
ohai args.join(" ")
system *args
2016-08-18 22:11:42 +03:00
end
end
end