ruby-build/libexec/ruby-package-install

54 lines
1 KiB
Text
Raw Permalink Normal View History

2011-10-18 14:07:05 -05:00
#!/usr/bin/env bash
set -e
usage() {
2011-10-19 13:45:55 -05:00
echo "usage: ruby-package install [--fail-silently] PACKAGE DESTINATION" >&2
2011-10-18 14:07:05 -05:00
exit 1
}
cleanup_packages() {
if [ -n "$package_root" ]; then
2011-10-18 14:18:14 -05:00
rm -rf "${package_root%/*}"
2011-10-18 14:07:05 -05:00
fi
if [ -n "$package_file" ]; then
if [ "$package" != "$package_file" ]; then
rm -rf "$package_file"
fi
fi
}
2011-10-19 13:45:55 -05:00
fail_silently=""
if [ "$1" = "--fail-silently" ]; then
fail_silently=1
shift
fi
2011-10-18 14:07:05 -05:00
package="$1"
if [ -z "$package" ]; then
usage
fi
destination="$2"
if [ -z "$destination" ]; then
usage
fi
if [ -f "$package" ]; then
package_file="$package"
else
2011-10-19 13:45:55 -05:00
if [ -n "$fail_silently" ]; then
ruby-package fetch --check "$package" 2>/dev/null
fi
2011-10-18 14:07:05 -05:00
package_file="$(ruby-package fetch "$package")"
fi
trap cleanup_packages SIGINT SIGTERM EXIT
package_root="$(ruby-package unpack "$package_file")"
2011-10-19 13:34:55 -05:00
package_name="$(cat "${package_root}/metadata/package")"
2011-10-18 14:07:05 -05:00
2011-10-19 13:34:55 -05:00
echo "Installing ${package_name}..." >&2
2011-10-18 14:07:05 -05:00
"${package_root}/bin/ruby-package-install" "$destination"
2011-10-19 13:34:55 -05:00
echo "Installed ${package_name} to ${destination}" >&2