Skip to content

Instantly share code, notes, and snippets.

@alakra
Created February 11, 2011 17:02
Show Gist options
  • Save alakra/822664 to your computer and use it in GitHub Desktop.
Save alakra/822664 to your computer and use it in GitHub Desktop.
checking for sudo access (from bundler gem)
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