Skip to content

Instantly share code, notes, and snippets.

@Leechael
Created August 26, 2012 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Leechael/3478555 to your computer and use it in GitHub Desktop.
Save Leechael/3478555 to your computer and use it in GitHub Desktop.
Build Ruby 1.9.3-p194 deb package
#!/usr/bin/env bash
# ----------------------------------------------------------------------------
#
# Test under 64-bit Debian Squeeze
#
# Thanks follow up posts:
#
# - Ruby 1.8.2 and Checkinstall 1.6.0:
# http://checkinstall.izto.org/cklist/msg00770.html
# - Debian squeezeのCheckinstallバグを回避する
# http://qiita.com/items/a8477746550f87cd5229
# - Ruby 1.9.2 on Ubuntu 11.04
# http://threebrothers.org/brendan/blog/ruby-1-9-2-on-ubuntu-11-04/
#
# ----------------------------------------------------------------------------
if [ `whoami` != 'root' ]; then
echo 'Please run as root.'
exit 1
fi
# Installing dependencies
echo 'Updating and installing dependency packages...'
apt-get update -qq
apt-get -y -qq \
install zlib1g-dev \
libssl-dev \
libreadline5-dev \
libffi5 \
libffi-dev \
libyaml-dev \
build-essential \
bison \
ruby # For psych compiling
if [[ ! $? -eq 0 ]]; then
echo 'Dependency packages install failed.'
exit 1
fi
# Compile it in /tmp/ruby-chroot
mkdir /tmp/ruby-chroot
cd /tmp/ruby-chroot
if [[ ! -e "ruby-1.9.3-p0.tar.bz2" ]]; then
#wget -q http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.bz2
# Use ruby.taobao.org if you are in Mainland China
echo 'Downloading ruby...'
wget -q http://ruby.taobao.org/mirrors/ruby/ruby-1.9.3-p194.tar.bz2
fi
echo 'Building ruby...'
tar xf ruby-1.9.3-p194.tar.bz2 && cd ruby-1.9.3-p194
./configure --prefix=/usr --program-suffix=1.9.3 --with-ruby-version=1.9.3 > /tmp/ruby-chroot/ruby_conf.log
make > /tmp/ruby-chroot/ruby_make.log
# Use chroot for files collecting
echo 'Prepare chroot environment...'
cd /tmp/ruby-chroot
mkdir ./{sys,proc,lib,lib64,bin,dev}
mount -o bind /sys sys
mount -o bind /proc proc
mount -o bind /lib lib
mount -o bind /lib64 lib64
mount -o bind /bin bin
mount -o bind /dev dev
mkdir -p usr/bin usr/lib
cp /usr/bin/make usr/bin
cp /usr/lib/libyaml* usr/lib/
echo 'Installing under chroot...'
chroot /tmp/ruby-chroot make -C /ruby-1.9.3-p194 install > install.log
ruby ruby-1.9.3-p194/ext/psych/extconf.rb > psych_conf.log
chroot /tmp/ruby-chroot make -C /ruby-1.9.3-p194/ext/psych > psych_make.log
chroot /tmp/ruby-chroot make -C /ruby-1.9.3-p194/ext/psych install > psych_install.log
echo 'Clear up chroot...'
for d in sys proc lib lib64 bin dev; do
d='/tmp/ruby-chroot/'$d
umount $d
done
rm usr/bin/make usr/lib/libyaml*
# Rebuild package via offical ruby1.9.1
echo 'Building package...'
cd /tmp/ruby-chroot
apt-get -dy -qq install ruby1.9.1
if [[ ! -f /var/cache/apt/archives/ruby1.9.1_1.9.2.0-2_amd64.deb ]]; then
echo 'Unable fetch back ruby1.9.1_1.9.2.0-2_amd64.deb, abort.'
exit 1
fi
cp /var/cache/apt/archives/ruby1.9.1_1.9.2.0-2_amd64.deb ./
if [[ -e ruby ]]; then
rm -rf ruby
fi
mkdir ruby
cp -r usr ruby/
dpkg -e ruby*.deb ruby/DEBIAN
cat <<-FILE > ruby/DEBIAN/control
Package: ruby1.9.3
Version: 1.9.3-p194
Architecture: amd64
Maintainer: Leechael Yim <yanleech@gmail.com>
Installed-Size: 864
Provides: irb1.9.3, rdoc1.9.3, ruby1.9.3, rubygems1.9.3, ri1.9.3, erb1.9.3, rake1.9.3, testrb1.9.3
Section: ruby
Priority: optional
Homepage: http://www.ruby-lang.org/
Description: Interpreter of object-oriented scripting language Ruby 1.9.2
Ruby is the interpreted scripting language for quick and easy
object-oriented programming. It has many features to process text
files and to do system management tasks (as in perl). It is simple,
straight-forward, and extensible.
FILE
cat <<-SCRIPT >> ruby/DEBIAN/postinst
update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.3 400 \
--slave /usr/share/man/man1/ruby.1.gz ruby.1.gz /usr/share/man/man1/ruby1.9.3.1 \
--slave /usr/bin/ri ri /usr/bin/ri1.9.3 \
--slave /usr/bin/erb erb /usr/bin/erb1.9.3 \
--slave /usr/bin/irb irb /usr/bin/irb1.9.3 \
--slave /usr/bin/rake rake /usr/bin/rake1.9.3 \
--slave /usr/bin/rdoc rdoc /usr/bin/rdoc1.9.3 \
--slave /usr/bin/testrb testrb /usr/bin/testrb1.9.3
update-alternatives --install /usr/bin/gem gem /usr/bin/gem1.9.3 400
SCRIPT
dpkg -b ruby ruby1.9.3_p194-0_amd64.deb
echo 'DONE.'
echo 'See `/tmp/ruby-chroot/ruby1.9.3_p194-0_amd64.deb`.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment