Create caskroom without sudo in writable parent.
In case the parent directory of Caskroom is writable for the user, we don't need to use `sudo` to execute commands. Make a generic method to run commands that has an option to switch sudo so that we can run commands with and without sudo.
This commit is contained in:
parent
d00f35b8c4
commit
d51cd15e0c
@ -13,7 +13,7 @@ module Hbc
|
|||||||
FileUtils.mv repo_caskroom, Hbc.caskroom
|
FileUtils.mv repo_caskroom, Hbc.caskroom
|
||||||
else
|
else
|
||||||
opoo "#{Hbc.caskroom.parent} is not writable, sudo is needed to move the Caskroom."
|
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
|
command "/bin/mv", repo_caskroom, Hbc.caskroom.parent, :use_sudo => true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -22,16 +22,23 @@ module Hbc
|
|||||||
|
|
||||||
ohai "Creating Caskroom at #{Hbc.caskroom}"
|
ohai "Creating Caskroom at #{Hbc.caskroom}"
|
||||||
ohai "We'll set permissions properly so we won't need sudo in the future"
|
ohai "We'll set permissions properly so we won't need sudo in the future"
|
||||||
|
use_sudo = !Hbc.caskroom.parent.writable?
|
||||||
|
|
||||||
sudo "/bin/mkdir", "-p", Hbc.caskroom
|
command "/bin/mkdir", "-p", Hbc.caskroom, :use_sudo => use_sudo
|
||||||
sudo "/bin/chmod", "g+rwx", Hbc.caskroom
|
command "/bin/chmod", "g+rwx", Hbc.caskroom, :use_sudo => use_sudo
|
||||||
sudo "/usr/sbin/chown", Utils.current_user, Hbc.caskroom
|
command "/usr/sbin/chown", Utils.current_user, Hbc.caskroom, :use_sudo => use_sudo
|
||||||
sudo "/usr/bin/chgrp", "admin", Hbc.caskroom
|
command "/usr/bin/chgrp", "admin", Hbc.caskroom, :use_sudo => use_sudo
|
||||||
end
|
end
|
||||||
|
|
||||||
def sudo(*args)
|
def command(*args)
|
||||||
ohai "/usr/bin/sudo #{args.join(" ")}"
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
||||||
system "/usr/bin/sudo", *args
|
|
||||||
|
if options[:use_sudo]
|
||||||
|
args.unshift "/usr/bin/sudo"
|
||||||
|
end
|
||||||
|
|
||||||
|
ohai args.join(" ")
|
||||||
|
system *args
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user