Created
December 16, 2020 16:58
-
-
Save fidelix/dab6865e7cf1176e9c724aff6bc6ffc4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| run() { | |
| # Run the compilation process. | |
| cd $PLATFORM_CACHE_DIR || exit 1; | |
| if [ ! -d "${PLATFORM_CACHE_DIR}/.linuxbrew/opt/ruby@$1" ]; then | |
| echo "Ruby not found in cache, installing" | |
| install_brew | |
| install_ruby $1 | |
| copy_lib_to_cache | |
| else | |
| copy_lib_from_cache | |
| fi | |
| write_profile $1 | |
| } | |
| copy_lib_to_cache() { | |
| echo "Copy to cache..." | |
| rsync -ahr $PLATFORM_APP_DIR/.linuxbrew $PLATFORM_CACHE_DIR | |
| } | |
| copy_lib_from_cache() { | |
| echo "Copy from cache..." | |
| rsync -ahr $PLATFORM_CACHE_DIR/.linuxbrew $PLATFORM_APP_DIR | |
| } | |
| write_profile() { | |
| touch ~/.environment | |
| echo "export PATH=\"/app/.linuxbrew/bin:/app/.linuxbrew/opt/ruby@$1/bin:$PATH\"" >> ~/.environment | |
| echo 'eval $(/app/.linuxbrew/bin/brew shellenv)' >>~/.environment | |
| ruby_dir=$(ls ~/.linuxbrew/Cellar/ruby@$1) | |
| echo "export LD_LIBRARY_PATH=/app/.linuxbrew/Cellar/ruby@$1/$ruby_dir/lib/" >> ~/.environment | |
| } | |
| install_brew() { | |
| echo "Installing homebrew" | |
| bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" | |
| eval $(/app/.linuxbrew/bin/brew shellenv) | |
| brew analytics off | |
| } | |
| install_ruby() { | |
| echo "Installing ruby with command: brew install ruby@$1" | |
| brew install ruby@"$1" | |
| rename 's/.reinstall//' /app/.linuxbrew/Cellar/ruby@$1/*.reinstall | |
| } | |
| ensure_environment() { | |
| # If not running in a Platform.sh build environment, do nothing. | |
| if [ -z "${PLATFORM_CACHE_DIR}" ]; then | |
| echo "Not running in a Platform.sh build environment. Aborting installation." | |
| exit 0; | |
| fi | |
| } | |
| ensure_arguments() { | |
| # If no version was specified, don't try to guess. | |
| if [ -z $1 ]; then | |
| echo "No version specified. You must specify a tagged version on the command line." | |
| exit 1; | |
| fi | |
| echo "Version was specified as $1" | |
| } | |
| ensure_environment | |
| ensure_arguments "$1" | |
| run "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment