mirror of
https://github.com/rbenv/ruby-build.git
synced 2024-12-29 13:15:33 +01:00
WIP on binary packages
This commit is contained in:
parent
69a4691aba
commit
7311e0dc23
4 changed files with 146 additions and 0 deletions
45
bin/ruby-package
Executable file
45
bin/ruby-package
Executable file
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
definition="$1"
|
||||
if [ -z "$definition" ]; then
|
||||
echo "usage: ruby-package DEFINITION"
|
||||
fi
|
||||
|
||||
package="${definition##*/}"
|
||||
prefix="/tmp/ruby-build/-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------/$package"
|
||||
|
||||
|
||||
# ruby-build "$definition" "$prefix"
|
||||
cwd="$(pwd)"
|
||||
cd "${prefix}/.."
|
||||
|
||||
# FIXME don't assume share is in cwd
|
||||
mkdir -p "${package}.rubypackage/bin"
|
||||
cp "${cwd}/share/ruby-package/"* "${package}.rubypackage/bin"
|
||||
|
||||
mkdir -p "${package}.rubypackage/metadata"
|
||||
echo -n "$prefix" > "${package}.rubypackage/metadata/prefix"
|
||||
echo -n "$package" > "${package}.rubypackage/metadata/package"
|
||||
|
||||
cd "$package"
|
||||
|
||||
while read line; do
|
||||
binary="${line#Binary file }"
|
||||
if [ "$line" = "$binary" ]; then
|
||||
# plain text match
|
||||
text="${line%%:*}"
|
||||
echo "$text" >> "../${package}.rubypackage/metadata/text-files"
|
||||
else
|
||||
# binary match
|
||||
binary="${binary% matches}"
|
||||
echo "$binary" >> "../${package}.rubypackage/metadata/binary-files"
|
||||
fi
|
||||
done < <( grep -m 1 -R "$prefix" * )
|
||||
|
||||
tar cf "../${package}.rubypackage/package.tar" *
|
||||
|
||||
cd ..
|
||||
|
||||
tar czf "${cwd}/${package}.rubypackage.tar.gz" "${package}.rubypackage"
|
||||
rm -fr "${package}.rubypackage"
|
49
share/ruby-package/ruby-package-install
Executable file
49
share/ruby-package/ruby-package-install
Executable file
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
prefix="$1"
|
||||
if [ -z "$prefix" ]; then
|
||||
echo "usage: ruby-package-install PREFIX" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
resolve_link() {
|
||||
$(type -p greadlink readlink | head -1) $1
|
||||
}
|
||||
|
||||
abs_dirname() {
|
||||
local cwd="$(pwd)"
|
||||
local path="$1"
|
||||
|
||||
while [ -n "$path" ]; do
|
||||
cd "${path%/*}"
|
||||
local name="${path##*/}"
|
||||
path="$(resolve_link "$name" || true)"
|
||||
done
|
||||
|
||||
pwd
|
||||
cd "$cwd"
|
||||
}
|
||||
|
||||
bin_root="$(abs_dirname "$0")"
|
||||
package_root="${bin_root}/.."
|
||||
package_prefix="$(cat "${package_root}/metadata/prefix")"
|
||||
package="$(cat "${package_root}/metadata/package")"
|
||||
|
||||
mkdir -p "$prefix"
|
||||
cd "$prefix"
|
||||
prefix="$(pwd)"
|
||||
|
||||
rewrite() {
|
||||
kind="$1"
|
||||
while read file; do
|
||||
path="${prefix}/$file"
|
||||
cp "$path" "${path}.orig"
|
||||
"${bin_root}/ruby-package-rewrite-$kind" "$package_prefix" "$prefix" < "${path}.orig" > "$path"
|
||||
rm "${path}.orig"
|
||||
done < "${package_root}/metadata/${kind}-files"
|
||||
}
|
||||
|
||||
tar xzf "${package_root}/package.tar"
|
||||
rewrite binary
|
||||
rewrite text
|
40
share/ruby-package/ruby-package-rewrite-binary
Executable file
40
share/ruby-package/ruby-package-rewrite-binary
Executable file
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
src_prefix="$1"
|
||||
dst_prefix="$2"
|
||||
|
||||
if [ -z "$src_prefix" ] || [ -z "$dst_prefix" ]; then
|
||||
echo "usage: ruby-package-install-binary SRC_PREFIX DST_PREFIX" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
hexify() {
|
||||
xxd -c 1 -p | sed 's/^00$/,/' | tr ',\n' '\n '
|
||||
}
|
||||
|
||||
search_hex="$(echo -n "$src_prefix" | hexify)"
|
||||
replace_hex="$(echo -n "$dst_prefix" | hexify)"
|
||||
|
||||
hexify |
|
||||
awk '
|
||||
BEGIN {
|
||||
search_hex=" '"$search_hex"'";
|
||||
replace_hex=" '"$replace_hex"'";
|
||||
split(search_hex, search);
|
||||
split(replace_hex, replace);
|
||||
search_len=length(search);
|
||||
replace_len=length(replace);
|
||||
}
|
||||
{ matched=0 }
|
||||
/ '"$search_hex"'/ {
|
||||
result=replace_hex substr($0, length(search_hex) + 1);
|
||||
for (i=length(replace)+1; i<=length(search); i++)
|
||||
result=result "00 ";
|
||||
print result;
|
||||
matched=1
|
||||
}
|
||||
{ if (matched == 0) print $0 }
|
||||
' |
|
||||
sed 's/$/00/' |
|
||||
xxd -p -r
|
12
share/ruby-package/ruby-package-rewrite-text
Executable file
12
share/ruby-package/ruby-package-rewrite-text
Executable file
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
src_prefix="$1"
|
||||
dst_prefix="$2"
|
||||
|
||||
if [ -z "$src_prefix" ] || [ -z "$dst_prefix" ]; then
|
||||
echo "usage: ruby-package-install-text SRC_PREFIX DST_PREFIX" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sed "s:${src_prefix}:${dst_prefix}:g"
|
Loading…
Reference in a new issue