Created
February 11, 2011 17:02
-
-
Save alakra/822664 to your computer and use it in GitHub Desktop.
checking for sudo access (from bundler gem)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def requires_sudo? | |
return @requires_sudo if @checked_for_sudo | |
path = bundle_path | |
path = path.parent until path.exist? | |
sudo_present = !(`which sudo` rescue '').empty? | |
@checked_for_sudo = true | |
@requires_sudo = settings.allow_sudo? && !File.writable?(path) && sudo_present | |
end | |
def mkdir_p(path) | |
if requires_sudo? | |
sudo "mkdir -p '#{path}'" unless File.exist?(path) | |
else | |
FileUtils.mkdir_p(path) | |
end | |
end | |
def sudo(str) | |
`sudo -p 'Enter your password to install the bundled RubyGems to your system: ' #{str}` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment