38 lines
1.1 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."
sudo "/bin/mv", repo_caskroom.to_s, Hbc.caskroom.parent.to_s
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"
sudo "/bin/mkdir", "-p", Hbc.caskroom
sudo "/bin/chmod", "g+rwx", Hbc.caskroom
sudo "/usr/sbin/chown", Utils.current_user, Hbc.caskroom
sudo "/usr/bin/chgrp", "admin", Hbc.caskroom
end
def sudo(*args)
ohai "/usr/bin/sudo #{args.join(" ")}"
system "/usr/bin/sudo", *args
2016-08-18 22:11:42 +03:00
end
end
end