Skip to content

Commit

Permalink
feat!: use links and move binaries (#223)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: moved binaries to new paths
  • Loading branch information
viceice authored Jan 11, 2022
1 parent 9742089 commit 1117271
Show file tree
Hide file tree
Showing 30 changed files with 286 additions and 320 deletions.
7 changes: 5 additions & 2 deletions src/usr/local/bin/install-buildpack
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fi

# env helper, loads tool specific env
cat >> $ENV_FILE <<- EOM
export BUILDPACK=1 USER_NAME="${USER_NAME}" USER_ID="${USER_ID}" USER_HOME="/home/${USER_NAME}" PATH="/home/${USER_NAME}/bin:\${PATH}"
export BUILDPACK=1 USER_NAME="${USER_NAME}" USER_ID="${USER_ID}" USER_HOME="/home/${USER_NAME}"
# openshift override unknown user home
if [ "\${EUID}" != 0 ]; then
Expand Down Expand Up @@ -74,10 +74,13 @@ useradd --uid ${USER_ID} --gid 0 --groups ${USER_NAME} --shell /bin/bash --creat
mkdir /usr/local/env.d
su ${USER_NAME} -c 'mkdir -p /home/${USER_NAME}/{env.d,bin}'

if [[ "$PATH" =~ (^|:)"/home/${USER_NAME}/bin"(:|$) ]]; then
echo "export PATH=\"/home/${USER_NAME}/bin:\${PATH}\"" >> $ENV_FILE
fi

# OpenShift
chmod g+w /home/${USER_NAME}/{,env.d,bin}


export_env DEBIAN_FRONTEND "noninteractive"
export_env LC_ALL "C.UTF-8"
export_env LANG "C.UTF-8"
Expand Down
4 changes: 0 additions & 4 deletions src/usr/local/bin/install-gem
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,5 @@ set -e
require_tool "$@"
check_command gem

if [[ $EUID -eq 0 ]]; then
unset GEM_HOME
fi

echo "Installing gem ${TOOL_NAME} v${TOOL_VERSION}"
gem install ${TOOL_NAME} -v ${TOOL_VERSION}
8 changes: 1 addition & 7 deletions src/usr/local/buildpack/tools/composer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ fi

tool_path=$(find_tool_path)

function update_env () {
PATH="${1}/bin:${PATH}"
link_wrapper ${TOOL_NAME}
}


if [[ -z "${tool_path}" ]]; then
INSTALL_DIR=$(get_install_dir)
base_path=${INSTALL_DIR}/${TOOL_NAME}
Expand All @@ -41,6 +35,6 @@ if [[ -z "${tool_path}" ]]; then
chmod +x ${tool_path}/bin/composer
fi

update_env ${tool_path}
link_wrapper ${TOOL_NAME} ${tool_path}/bin

composer --version
1 change: 0 additions & 1 deletion src/usr/local/buildpack/tools/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ set -e

require_root


if [[ -d "/usr/local/bin/${TOOL_NAME}" ]]; then
echo "Skipping, already installed"
exit 0
Expand Down
16 changes: 8 additions & 8 deletions src/usr/local/buildpack/tools/dotnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" ]]; then
exit 1
fi

DOTNET_INSTALL_DIR=/usr/local/${TOOL_NAME}
DOTNET_INSTALL_DIR=/usr/local/buildpack/${TOOL_NAME}

if [[ -d "${DOTNET_INSTALL_DIR}/sdk/${TOOL_VERSION}" ]]; then
echo "Skipping, already installed"
Expand All @@ -27,18 +27,18 @@ esac

mkdir -p $DOTNET_INSTALL_DIR

export_path "${DOTNET_INSTALL_DIR}"
export_env DOTNET_ROOT "${DOTNET_INSTALL_DIR}"
export_env DOTNET_CLI_TELEMETRY_OPTOUT "1"
export_env DOTNET_SKIP_FIRST_TIME_EXPERIENCE "1"

if [[ -z "${DOTNET_ROOT+x}" ]]; then
export_env DOTNET_ROOT "${DOTNET_INSTALL_DIR}"
export_env DOTNET_CLI_TELEMETRY_OPTOUT "1"
export_env DOTNET_SKIP_FIRST_TIME_EXPERIENCE "1"
fi

curl -sSL https://dot.net/v1/dotnet-install.sh | bash -s - --install-dir $DOTNET_INSTALL_DIR --no-path -version $TOOL_VERSION

link_wrapper dotnet $DOTNET_INSTALL_DIR

# first time experience
dotnet help > /dev/null
su $USER_NAME -c 'dotnet help' > /dev/null

dotnet --info

shell_wrapper dotnet
23 changes: 11 additions & 12 deletions src/usr/local/buildpack/tools/elixir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ set -e
require_root
check_command erl

if [[ -d "/usr/local/${TOOL_NAME}/${TOOL_VERSION}" ]]; then
echo "Skipping, already installed"
exit 0
fi

curl -sSL https://github.com/elixir-lang/elixir/releases/download/v${TOOL_VERSION}/Precompiled.zip -o elixir.zip
mkdir -p /usr/local/${TOOL_NAME}/${TOOL_VERSION}
unzip -q elixir.zip -d /usr/local/${TOOL_NAME}/${TOOL_VERSION}
rm elixir.zip
base_path=/usr/local/buildpack/${TOOL_NAME}
tool_path=${base_path}/${TOOL_VERSION}

if [[ ! -d "$tool_path" ]]; then
curl -sSL https://github.com/elixir-lang/elixir/releases/download/v${TOOL_VERSION}/Precompiled.zip -o elixir.zip
mkdir -p $tool_path
unzip -q elixir.zip -d $tool_path
rm elixir.zip
fi

export_path "/usr/local/${TOOL_NAME}/${TOOL_VERSION}/bin"
link_wrapper ${TOOL_NAME} ${tool_path}/bin
link_wrapper mix ${tool_path}/bin

elixir --version
mix --version

su -c 'mix local.hex --force' ${USER_NAME}
su -c 'mix local.rebar --force' ${USER_NAME}

shell_wrapper elixir
shell_wrapper mix
51 changes: 28 additions & 23 deletions src/usr/local/buildpack/tools/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,41 @@ if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" ]]; then
exit 1
fi

if [[ -d "/usr/local/go/${TOOL_VERSION}" ]]; then
echo "Skipping, already installed"
exit 0
fi

# fix version
GOLANG_FILE_VERSION=${TOOL_VERSION}
if [[ "${PATCH}" == "0" ]]; then
GOLANG_FILE_VERSION="${MAJOR}.${MINOR}"
fi
base_path=/usr/local/buildpack/go
tool_path=${base_path}/${TOOL_VERSION}

if [[ ! -d "$tool_path" ]]; then

# go suggests: git svn bzr mercurial
apt_install bzr mercurial
# fix version
GOLANG_FILE_VERSION=${TOOL_VERSION}
if [[ "${PATCH}" == "0" ]]; then
GOLANG_FILE_VERSION="${MAJOR}.${MINOR}"
fi

mkdir -p /usr/local/go/${TOOL_VERSION}
curl -sSL https://dl.google.com/go/go${GOLANG_FILE_VERSION}.linux-amd64.tar.gz --output go.tgz
tar --strip 1 -C /usr/local/go/${TOOL_VERSION} -xzf go.tgz
rm go.tgz
# go suggests: git svn bzr mercurial
apt_install bzr mercurial

export_env GOPATH "/go"
export_env CGO_ENABLED 0
export_env GOSUMDB off
export_path "/usr/local/go/${TOOL_VERSION}/bin:\$GOPATH/bin"
mkdir -p $tool_path
curl -sSL https://dl.google.com/go/go${GOLANG_FILE_VERSION}.linux-amd64.tar.gz --output go.tgz
tar --strip 1 -C $tool_path -xzf go.tgz
rm go.tgz

mkdir -p "$GOPATH/src" "$GOPATH/bin" "$GOPATH/pkg"
if [[ ! -d "${GOPATH}" ]]; then
export_env GOPATH "/go"
export_env CGO_ENABLED 0
export_env GOSUMDB off
export_path "\$GOPATH/bin"

mkdir -p "$GOPATH/src" "$GOPATH/bin" "$GOPATH/pkg"

chown -R ${USER_ID} $GOPATH
chmod -R g+w $GOPATH
fi
fi

chown -R ${USER_ID} $GOPATH
chmod -R g+w $GOPATH
link_wrapper go $tool_path/bin

go version
go env

shell_wrapper go
13 changes: 2 additions & 11 deletions src/usr/local/buildpack/tools/gradle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ fi

tool_path=$(find_tool_path)

function update_env () {
reset_tool_env
export_tool_path "${1}/bin"
}

function create_gradle_settings() {
if [[ -f ${USER_HOME}/.gradle/gradle.properties ]]; then
echo 'Gradle settings already found'
Expand Down Expand Up @@ -77,12 +72,8 @@ if [[ -z "${tool_path}" ]]; then
unzip -q -d ${base_path} ${file}
rm ${file}
mv ${base_path}/${TOOL_NAME}-${TOOL_VERSION} ${tool_path}

update_env ${tool_path}
shell_wrapper gradle
else
echo "Already installed, resetting env"
update_env ${tool_path}
fi

link_wrapper gradle $tool_path/bin

gradle --version
7 changes: 1 addition & 6 deletions src/usr/local/buildpack/tools/helm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ fi

tool_path=$(find_tool_path)

function update_env () {
PATH="${1}/bin:${PATH}"
link_wrapper ${TOOL_NAME}
}

if [[ -z "${tool_path}" ]]; then
INSTALL_DIR=$(get_install_dir)
base_path=${INSTALL_DIR}/${TOOL_NAME}
Expand All @@ -31,6 +26,6 @@ if [[ -z "${tool_path}" ]]; then
rm ${file}
fi

update_env ${tool_path}
link_wrapper ${TOOL_NAME} ${tool_path}/bin

helm version
7 changes: 1 addition & 6 deletions src/usr/local/buildpack/tools/jb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ fi

tool_path=$(find_tool_path)

function update_env () {
PATH="${1}/bin:${PATH}"
link_wrapper ${TOOL_NAME}
}

if [[ -z "${tool_path}" ]]; then
INSTALL_DIR=$(get_install_dir)
base_path=${INSTALL_DIR}/${TOOL_NAME}
Expand All @@ -32,6 +27,6 @@ if [[ -z "${tool_path}" ]]; then
chmod +x ${tool_path}/bin/${TOOL_NAME}
fi

update_env ${tool_path}
link_wrapper ${TOOL_NAME} ${tool_path}/bin

jb --version
7 changes: 1 addition & 6 deletions src/usr/local/buildpack/tools/lerna.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ check_command node

tool_path=$(find_tool_path)

function update_env () {
PATH="${1}/bin:${PATH}"
link_wrapper ${TOOL_NAME}
}

if [[ -z "${tool_path}" ]]; then
INSTALL_DIR=$(get_install_dir)
base_path=${INSTALL_DIR}/${TOOL_NAME}
Expand All @@ -26,6 +21,6 @@ if [[ -z "${tool_path}" ]]; then
rm -rf $HOME/.cache /tmp/empty-cache
fi

update_env ${tool_path}
link_wrapper ${TOOL_NAME} $tool_path/bin

lerna --version
3 changes: 1 addition & 2 deletions src/usr/local/buildpack/tools/maven.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ tool_path=$(find_tool_path)
function update_env () {
reset_tool_env
export_tool_env MAVEN_HOME "${1}"
PATH="${1}/bin:${PATH}"
link_wrapper mvn
link_wrapper mvn $tool_path/bin
}

if [[ -z "${tool_path}" ]]; then
Expand Down
11 changes: 3 additions & 8 deletions src/usr/local/buildpack/tools/npm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ fi
tool_path=$(find_tool_path)
npm=$(command -v npm)

function update_env () {
PATH="${1}/bin:${PATH}"
link_wrapper ${TOOL_NAME}
link_wrapper npx
hash -d ${TOOL_NAME} npx 2>/dev/null || true
}

if [[ -z "${tool_path}" ]]; then
INSTALL_DIR=$(get_install_dir)
base_path=${INSTALL_DIR}/${TOOL_NAME}
Expand All @@ -42,6 +35,8 @@ if [[ -z "${tool_path}" ]]; then
rm -rf $HOME/.cache /tmp/empty-cache
fi

update_env ${tool_path}
link_wrapper ${TOOL_NAME} $tool_path/bin
link_wrapper npx $tool_path/bin
hash -d ${TOOL_NAME} npx 2>/dev/null || true

npm --version
7 changes: 1 addition & 6 deletions src/usr/local/buildpack/tools/php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ fi

tool_path=$(find_tool_path)

function update_env () {
PATH="${1}/bin:${PATH}"
link_wrapper ${TOOL_NAME}
}

if [[ -z "${tool_path}" ]]; then
INSTALL_DIR=$(get_install_dir)
base_path=${INSTALL_DIR}/${TOOL_NAME}
Expand Down Expand Up @@ -65,6 +60,6 @@ if [[ -z "${tool_path}" ]]; then
fi
fi

update_env ${tool_path}
link_wrapper ${TOOL_NAME} ${tool_path}/bin

php --version
7 changes: 1 addition & 6 deletions src/usr/local/buildpack/tools/pnpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ check_command node

tool_path=$(find_tool_path)

function update_env () {
PATH="${1}/bin:${PATH}"
link_wrapper ${TOOL_NAME}
}

if [[ -z "${tool_path}" ]]; then
INSTALL_DIR=$(get_install_dir)
base_path=${INSTALL_DIR}/${TOOL_NAME}
Expand All @@ -26,6 +21,6 @@ if [[ -z "${tool_path}" ]]; then
rm -rf $HOME/.cache /tmp/empty-cache
fi

update_env ${tool_path}
link_wrapper ${TOOL_NAME} $tool_path/bin

pnpm --version
7 changes: 1 addition & 6 deletions src/usr/local/buildpack/tools/poetry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ POETRY_URL=https://raw.githubusercontent.com/python-poetry/poetry/master/install

tool_path=$(find_tool_path)

function update_env () {
PATH="${1}/bin:${PATH}"
link_wrapper ${TOOL_NAME}
}

if [[ -z "${tool_path}" ]]; then
INSTALL_DIR=$(get_install_dir)
tool_path=${INSTALL_DIR}/${TOOL_NAME}/${TOOL_VERSION}
Expand All @@ -39,6 +34,6 @@ if [[ -z "${tool_path}" ]]; then
fi
fi

update_env ${tool_path}
link_wrapper ${TOOL_NAME} ${tool_path}/bin

poetry --version
3 changes: 1 addition & 2 deletions src/usr/local/buildpack/tools/powershell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ if [[ -z "${tool_path}" ]]; then
rm ${TOOL_NAME}.tgz
fi

PATH="${tool_path}/bin:${PATH}"
link_wrapper pwsh
link_wrapper pwsh ${tool_path}/bin

pwsh -Version
Loading

0 comments on commit 1117271

Please sign in to comment.