Sha256: 6ac969e6b4a94c3d7b1367cb39a92842bd221d9edaa449ecccd785c42ab1284f

Contents?: true

Size: 1009 Bytes

Versions: 18

Compression:

Stored size: 1009 Bytes

Contents

require 'Yk/shellquote'


if !defined? CYGWIN
	CYGWIN = (`uname` =~ /CYGWIN/)
end
if CYGWIN
	if !defined?(CYGADMIN)
		begin
			testFName = "/var/tmp/__test_admin__#{rand(10000000000)}"
			File.open testFName, "w" do |fw|
				File.chmod 0666, testFName
			end
			isAdmin = false
			begin
				require 'etc'
				File.chown Etc.getpwnam("SYSTEM").uid, Etc.getgrnam("Administrators").gid, testFName
				isAdmin = true
			rescue
			end
			CYGADMIN = isAdmin
		ensure
			File.delete testFName
		end
	end
end


if !CYGWIN
	if Process.euid != 0
		if (File.executable?(tmp = "/usr/sbin/cansudo") && system(tmp) && $? == 0 && STDIN.tty?) or "/etc/group".read =~ /\nwheel|sudo:.*\b(#{Regexp.escape Etc.getpwuid(Process.euid).name})\b/
				exec "sudo", $0, *ARGV
		else
			exec "su",  "-c",  "#{$0} #{ARGV.condSQuote}"
		end
	end
else
	if !CYGADMIN
		if File.executable?(tmp = "/usr/bin/cygsu")
			exec "cygsu #{$0} #{ARGV.condSQuote}"
		else
			raise Exception.new("cannot execute as an administrator")
		end
	end
end


Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
YkLib-0.1.8.8 lib/Yk/rootexec.rb
YkLib-0.1.8.7 lib/Yk/rootexec.rb
YkLib-0.1.8.6 lib/Yk/rootexec.rb
YkLib-0.1.8.5 lib/Yk/rootexec.rb
YkLib-0.1.8.4 lib/Yk/rootexec.rb
YkLib-0.1.8.3 lib/Yk/rootexec.rb
YkLib-0.1.8.2 lib/Yk/rootexec.rb
YkLib-0.1.8.1 lib/Yk/rootexec.rb
YkLib-0.1.8 lib/Yk/rootexec.rb
YkLib-0.1.7.1 lib/Yk/rootexec.rb
YkLib-0.1.7 lib/Yk/rootexec.rb
YkLib-0.1.6 lib/Yk/rootexec.rb
YkLib-0.1.5 lib/Yk/rootexec.rb
YkLib-0.1.4 lib/Yk/rootexec.rb
YkLib-0.1.3 lib/Yk/rootexec.rb
YkLib-0.1.2 lib/Yk/rootexec.rb
YkLib-0.1.1 lib/Yk/rootexec.rb
YkLib-0.1.0 lib/YkLib/Yk/rootexec.rb