Skip to content

Commit

Permalink
Enable install in non-standard directory
Browse files Browse the repository at this point in the history
  • Loading branch information
DoomHammer committed May 16, 2016
1 parent b772f99 commit 503e481
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 31 deletions.
93 changes: 62 additions & 31 deletions brewstrap.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
#!/bin/sh
VERSION=0.1
ORIGWD=`pwd`
BREWSTRAP_DIR=$HOME/.linuxbrew/Cellar/brewstrap/$VERSION
HOMEBREW_DIR=${HOMEBREW_DIR:-$HOME}
BREWSTRAP_DIR=$HOMEBREW_DIR/.linuxbrew/Cellar/brewstrap/$VERSION

set -e
set -x

before_extraction() {
mkdir -p $BREWSTRAP_DIR
cd $BREWSTRAP_DIR
}

after_extraction() {
# Do not verify certs as they are unavailable
[ -e $HOME/.curlrc ] && cp $HOME/.curlrc $HOME/.curlrc.bak
echo '\n-k' >> $HOME/.curlrc
# Restore original `.curlrc` after completion
trap "[ -e $HOME/.curlrc.bak ] && mv $HOME/.curlrc.bak $HOME/.curlrc" EXIT
cd $BREWSTRAP_DIR/bin
sed -i -e "s@/bin/bash@$BREWSTRAP_DIR/bin/bash@" *
# `/bin/bash` may not be available
find -type f | xargs sed -i -e "s@/bin/bash@$BREWSTRAP_DIR/bin/bash@"
# Install self. Not the best way possible, but should suffice until a better
# one is suggested.
cp $1 ./brewstrap
chmod +x brewstrap
# Download Linuxbrew installer
$BREWSTRAP_DIR/bin/ruby <<-EORUBY
require 'open-uri'
open('linuxbrew-install', 'wb') do |file|
file << open('https://raw.githubusercontent.com/Linuxbrew/install/master/install').read
end
EORUBY
# Substitute system paths with those provided by brewstrap
sed -i -e "s@/bin/bash@$BREWSTRAP_DIR/bin/bash@" \
-e "s@/usr/bin/curl@$BREWSTRAP_DIR/bin/curl@" \
-e "s@/usr/bin/which@$(which which)@" \
Expand All @@ -28,35 +42,52 @@ EORUBY
export PATH=$PATH:$BREWSTRAP_DIR/bin
export MAGIC=$BREWSTRAP_DIR/share/file/magic.mgc
export TERMINFO=$BREWSTRAP_DIR/usr/share/terminfo
ruby linuxbrew-install
# Hack to install Linuxbrew inside an arbitrary directory
HOME=$HOMEBREW_DIR ruby linuxbrew-install
export PATH=$HOMEBREW_DIR/.linuxbrew/bin:$PATH
# tmpfs may be noexec, better stick to something else
export HOMEBREW_TEMP=$HOMEBREW_DIR/.tmp
mkdir -p $HOMEBREW_TEMP
# Necessary to use dupes bottled for Linuxbrew
brew tap homebrew/dupes git://github.com/Linuxbrew/homebrew-dupes.git
# Following https://github.com/Linuxbrew/brew/issues/32
# tput from minos returns error which may be misinterpreted in Homebrew when
# backticks are used. Using brewed ncurses we are safe(r).
brew install homebrew/dupes/ncurses
sed -i -e "s@$BREWSTRAP_DIR/usr/bin/tput@$HOME/.linuxbrew/bin/tput@" \
$HOME/.linuxbrew/Library/Homebrew/utils.rb
# List of essentials following https://github.com/Linuxbrew/brew/issues/32
brew install \
bash \
binutils \
gcc \
linux-headers || brew postinstall gcc
# glibc is unlinked since an older loader (the one in bottles) cannot work
# with newer glibc
brew install --force-bottle glibc || brew unlink glibc
# Enable use of keg_only glibc
sed -i.bak -e 's/\(.*prepend_path "LIBRARY_PATH".*\)/\1\nprepend_path "LIBRARY_PATH", Formula["glibc"].lib/' \
$HOMEBREW_DIR/.linuxbrew/Library/Homebrew/extend/ENV/std.rb
specfile=$(find -L $(brew --prefix gcc) -name specs|sed -ne '/\/lib\//p')
sed -i.brewstrap -e 's@\(.*-isystem.*\)@\1 -I'"$HOMEBREW_DIR/.linuxbrew/Cellar/glibc/$(brew info glibc|sed -ne 's/glibc: stable \(.*\)/\1/p')/include@" $specfile
# Perl needs this hack to compile on a system lacking /usr/include
sed -i -e 's@-Dprefix=#{prefix}@-Dprefix=#{prefix}\n-Dlocincpth=#{Formula["glibc"].include}@' \
$HOMEBREW_DIR/.linuxbrew/Library/Taps/homebrew/homebrew-core/Formula/perl.rb
env
# perl tests tend to fail, probably a FIXME
brew install perl --without-test
# gawk tests require working en_US.UTF-8 locale, another FIXME
yes 2|brew install --debug gawk
# `libblkid` requires libudev.h which is a part of `systemd` formula that depends on `util-linux` (circular dependency)
# `setpriv` requires cap-ng.h which is a port of `libcap-ng` that lacks formula
sed -i.bak -e 's/\(.*"--disable-kill".*\)/\1,\n"--disable-libblkid",\n"--disable-setpriv"/' \
$HOMEBREW_DIR/.linuxbrew/Library/Taps/homebrew/homebrew-core/Formula/util-linux.rb
brew install \
bash \
coreutils \
diffutils \
file-formula \
findutils \
gawk \
gcc \
glibc \
gnu-sed \
gnu-tar \
gnu-which \
grep \
linux-headers \
make \
util-linux
# Perl needs this hack to compile on a system lacking /usr/include
sed -i -e 's@-Dprefix=#{prefix}@-Dprefix=#{prefix}\n-Dlocincpth=#{Formula["glibc"].include}@' \
$HOME/.linuxbrew/Library/Taps/homebrew/homebrew-core/Formula/perl.rb
brew install perl --without-test
# The following depend on openssl which in turn depends on perl but doesn't
# want to admit it (though see: https://github.com/Linuxbrew/homebrew-core/pull/232)
# The following depend on openssl which in turn depends on perl
brew install \
curl \
git \
Expand All @@ -71,11 +102,11 @@ fix_paths() {
-e "s@/usr/bin/tput@$(brew --prefix ncurses)/bin/tput@" \
-e "s@/usr/bin/which@$(brew --prefix gnu-which)/bin/which@" \
-e "s@/usr/bin/awk@$(brew --prefix gawk)/bin/awk@" \
$HOME/.linuxbrew/bin/brew \
$HOME/.linuxbrew/Library/brew.sh \
$HOME/.linuxbrew/Library/ENV/scm/git \
$HOME/.linuxbrew/Library/Homebrew/utils.rb \
$HOME/.linuxbrew/Library/Homebrew/keg_relocate.rb
$HOMEBREW_DIR/.linuxbrew/bin/brew \
$HOMEBREW_DIR/.linuxbrew/Library/brew.sh \
$HOMEBREW_DIR/.linuxbrew/Library/ENV/scm/git \
$HOMEBREW_DIR/.linuxbrew/Library/Homebrew/utils.rb \
$HOMEBREW_DIR/.linuxbrew/Library/Homebrew/keg_relocate.rb
}
if [ "\$1" == "update" ]; then
trap "fix_paths" EXIT
Expand All @@ -98,13 +129,13 @@ fix_paths() {
-e "s@/usr/bin/tput@$BREWSTRAP_DIR/usr/bin/tput@" \
-e "s@/usr/bin/which@$(which which)@" \
-e "s@/usr/bin/awk@$(which awk)@" \
$HOME/.linuxbrew/bin/brew \
$HOME/.linuxbrew/Library/brew.sh \
$HOME/.linuxbrew/Library/ENV/scm/git \
$HOME/.linuxbrew/Library/Homebrew/utils.rb \
$HOME/.linuxbrew/Library/Homebrew/keg_relocate.rb
$HOMEBREW_DIR/.linuxbrew/bin/brew \
$HOMEBREW_DIR/.linuxbrew/Library/brew.sh \
$HOMEBREW_DIR/.linuxbrew/Library/ENV/scm/git \
$HOMEBREW_DIR/.linuxbrew/Library/Homebrew/utils.rb \
$HOMEBREW_DIR/.linuxbrew/Library/Homebrew/keg_relocate.rb
sed -i.bak -e '/default_remote/N;s@https://@git://@' \
$HOME/.linuxbrew/Library/Homebrew/tap.rb
$HOMEBREW_DIR/.linuxbrew/Library/Homebrew/tap.rb
}

if [ "x$1" = "x--fixpaths" ]; then
Expand Down
2 changes: 2 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ download_deps() {
get_minos_resource bin/bash bash
get_minos_resource bin/curl curl
get_minos_resource bin/file file
get_minos_resource bin/gawk gawk
get_minos_resource bin/git git
get_minos_resource bin/make make
get_minos_resource usr/bin/tput ncurses-bin
get_minos_resource bin/tar tar
get_minos_resource usr/share/terminfo terminfo
Expand Down

0 comments on commit 503e481

Please sign in to comment.