-
Notifications
You must be signed in to change notification settings - Fork 6
/
package-ruby.sh
72 lines (61 loc) · 2.46 KB
/
package-ruby.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
wantruby=$1
if [ -z "$wantruby" ] ; then
echo "Usage: $0 <ruby>"
echo "Example: $0 jruby"
exit 1
fi
. ./config.rc
if [ ! -f $rvm_path/scripts/rvm ] ; then
# install rvm and retry.
echo "RVM not found; installing now to $rvm_path"
install_rvm
exec bash $0 "$@"
fi
# Run this in a subshell so the rvm loading doesn't infect our current shell.
(
. $rvm_path/scripts/rvm
rvm use $wantruby || rvm install $wantruby
)
rubyinfo="$(. $rvm_path/scripts/rvm; rvm use $wantruby > /dev/null; rvm info | sed -ne '/^ ruby:/,/^ *$/p')"
ruby="$(echo "$rubyinfo" | awk -F\" '/ interpreter:/ { print $2 }')"
version="$(echo "$rubyinfo" | awk -F\" '/ version:/ { print $2 }')"
rubyname="$(. $rvm_path/scripts/rvm; rvm use $wantruby > /dev/null; rvm current)"
echo "rubyinfo: $rubyinfo"
echo "ruby: $ruby"
echo "version: $version"
echo "name: $rubyname"
# DESTDIR comes from 'config.rc'
echo "patching rvm scripts to remove path '$DESTDIR/'"
find $DESTDIR/$PREFIX/{wrappers,environments} -type f -print0 \
| xargs -0n1 sed -i -e "s,$DESTDIR/,,g"
find $DESTDIR/$PREFIX/rubies/${rubyname} -type f -name '*.rb' -print0 \
| xargs -0n1 sed -i -e "s,$DESTDIR/,,g"
find $DESTDIR/$PREFIX/rubies/${rubyname} -type f -name '*.h' -print0 \
| xargs -0n1 sed -i -e "s,$DESTDIR/,,g"
for i in $DESTDIR/$PREFIX/{rubies/${rubyname}/bin,wrappers/${rubyname}}/{erb,gem,irb,rake,rdoc,ri,testrb} ; do
sed -i -e "s,$DESTDIR/,,g" $i
done
# Mangle the 'ruby' binary to fix the RPATH (LD_RUN_PATH) stuff.
rubybin=$DESTDIR/$PREFIX/rubies/${rubyname}/bin/ruby
echo "Checking if we need to patch the ruby binary; $rubybin"
if readelf -d $rubybin | grep RPATH | grep -qF $DESTDIR ; then
echo "patching ruby binary to use correct library path"
old_libpath=$(readelf -d $rubybin | grep RPATH | sed -re 's/.*\[(.*)\]/\1/')
fixed_libpath=$(echo "$old_libpath" | sed -e "s,$DESTDIR/,,g")
echo "Old: ${old_libpath}"
echo "New: ${fixed_libpath}"
export old_libpath
export fixed_libpath
# Replace the ld libpath with the fixed libpath, padded by nulls
ruby -p -e '
$_.gsub!(ENV["old_libpath"]) do |s|
ENV["fixed_libpath"] + ("\0" * (ENV["old_libpath"].size - ENV["fixed_libpath"].size))
end
' $rubybin > $rubybin.patched
fi
# skip the 'src' dir, too, we don't want it.
echo "Packaging up $ruby-$version"
[ -z "$iteration" ] && iteration=3
fpm -s dir -t deb -C ./build -n rvm-${ruby}-${version} -v ${version}-${iteration} \
opt/rvm/{gems,rubies,wrappers,environments,log,bin}/${rubyname}