Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pear enhancements #358

Merged
merged 4 commits into from
Feb 8, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions lib/fpm/package/pear.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@ class FPM::Package::PEAR < FPM::Package
option "--channel", "CHANNEL_URL",
"The pear channel url to use instead of the default."

option "--channel-update", :flag,
option "--channel-update", :flag,
"call 'pear channel-update' prior to installation"

option "--bin-dir", "BIN_DIR",
"Directory to put binaries in"

option "--php-bin", "PHP_BIN",
"Specify php executable path if differs from the os used for packaging"

option "--php-dir", "PHP_DIR",
"Specify php dir relative to prefix if differs from pear default (pear/php)"

# Input a PEAR package.
#
# The parameter is a PHP PEAR package name.
#
# Attributes that affect behavior here:
# * :prefix - changes the install root, default is /usr/share
# * :pear_package_name_prefix - changes the
# * :pear_package_name_prefix - changes the
def input(input_package)
if !program_in_path?("pear")
raise ExecutableNotFound.new("pear")
Expand All @@ -34,10 +43,22 @@ def input(input_package)
installroot = attributes[:prefix] || "/usr/share"
safesystem("pear", "config-create", staging_path(installroot), config)

if attributes[:pear_php_dir]
@logger.info("Setting php_dir", :php_dir => attributes[:pear_php_dir])
safesystem("pear", "-c", config, "config-set", "php_dir", "#{staging_path(installroot)}/#{attributes[:pear_php_dir]}")
end

bin_dir = attributes[:pear_bin_dir] || "usr/bin"
@logger.info("Setting bin_dir", :bin_dir => bin_dir)
safesystem("pear", "-c", config, "config-set", "bin_dir", bin_dir)

php_bin = attributes[:pear_php_bin] || "/usr/bin/php"
@logger.info("Setting php_bin", :php_bin => php_bin)
safesystem("pear", "-c", config, "config-set", "php_bin", php_bin)

# try channel-discover
if !attributes[:pear_channel].nil?
@logger.info("Custom channel specified", :channel => attributes[:pear_channel])
p ["pear", "-c", config, "channel-discover", attributes[:pear_channel]]
safesystem("pear", "-c", config, "channel-discover", attributes[:pear_channel])
input_package = "#{attributes[:pear_channel]}/#{input_package}"
@logger.info("Prefixing package name with channel", :package => input_package)
Expand All @@ -64,11 +85,17 @@ def input(input_package)
self.description = %x{#{pear_cmd} | sed -ne '/^Summary\s*/s/^Summary\s*//p'}.chomp
@logger.debug("Package info", :name => self.name, :version => self.version,
:description => self.description)

# Remove the stuff we don't want
delete_these = [".depdb", ".depdblock", ".filemap", ".lock", ".channel"]
delete_these = [".depdb", ".depdblock", ".filemap", ".lock", ".channel", "cache", "temp", "download", ".channels", ".registry"]
Find.find(staging_path) do |path|
if File.file?(path) && File.executable?(path)
@logger.info("replacing pear_dir in binary", :binary => path)
content = File.read(path).gsub(/#{staging_path}/, "")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.gsub(staging_path, "") is sufficient, otherwise staging_path could be interpreted as a regexp, not a string.

File.open(path, "w") { |file| file.puts content }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use File.write(path, content) instead if you wish.

end
FileUtils.rm_r(path) if delete_these.include?(File.basename(path))
end

end # def input
end # class FPM::Package::PEAR