77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'ext/cairo/extconf.rb', line 77
def install_missing_native_package(native_package_info)
platform = package_platform
native_package_info = normalize_native_package_info(native_package_info)
package = native_package_info[platform]
return false if package.nil?
need_super_user_priviledge = true
case platform
when :debian
install_command = "apt-get install -V -y #{package}"
when :fedora, :redhat
install_command = "yum install -y #{package}"
when :homebrew
need_super_user_priviledge = false
install_command = "brew install #{package}"
when :macports
install_command = "port install -y #{package}"
else
return false
end
have_priviledge = (not need_super_user_priviledge or super_user?)
unless have_priviledge
sudo = find_executable("sudo")
end
installing_message = "installing '#{package}' native package... "
message("%s", installing_message)
failed_to_get_super_user_priviledge = false
if have_priviledge
succeeded = xsystem(install_command)
else
if sudo
install_command = "#{sudo} #{install_command}"
succeeded = xsystem(install_command)
else
succeeded = false
failed_to_get_super_user_priviledge = true
end
end
if failed_to_get_super_user_priviledge
result_message = "require super user privilege"
else
result_message = succeeded ? "succeeded" : "failed"
end
Logging.postpone do
"#{installing_message}#{result_message}\n"
end
message("#{result_message}\n")
error_message = nil
unless succeeded
if failed_to_get_super_user_priviledge
error_message = <<-EOM
'#{package}' native package is required.
run the following command as super user to install required native package:
\# #{install_command}
EOM
else
error_message = <<-EOM
failed to run '#{install_command}'.
EOM
end
end
if error_message
message("%s", error_message)
Logging.message("%s", error_message)
end
Logging.message("--------------------\n\n")
succeeded
end
|