From fee9572a3205dbf32ade5df6a01704dbdfb1770d Mon Sep 17 00:00:00 2001 From: Piotr Gaczkowski Date: Fri, 13 May 2016 09:09:11 +0200 Subject: [PATCH] Enable install in non-standard directory --- brewstrap.sh | 93 ++++++++++++++++++++++++++++++++++------------------ deploy.sh | 2 ++ 2 files changed, 64 insertions(+), 31 deletions(-) diff --git a/brewstrap.sh b/brewstrap.sh index 316c89a..4f370e6 100755 --- a/brewstrap.sh +++ b/brewstrap.sh @@ -1,7 +1,11 @@ #!/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 @@ -9,16 +13,27 @@ before_extraction() { } after_extraction() { + # Do not verify certs as they are unavailable + [ -e $HOME/.curlrc ] && cp $HOME/.curlrc $HOME/.curlrc.bak + touch $HOME/.curlrc + cat $HOME/.curlrc.bak|awk '{print};END {print "-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)@" \ @@ -28,35 +43,51 @@ 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: [a-z]\+ \([^ ]*\).*/\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 + # 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 \ @@ -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 @@ -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 diff --git a/deploy.sh b/deploy.sh index 8564694..51e7b5e 100755 --- a/deploy.sh +++ b/deploy.sh @@ -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