Skip to content

Commit

Permalink
fix: shellcheck errors (#263)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <[email protected]>
  • Loading branch information
Chumper and viceice authored Jan 26, 2022
1 parent 119a7de commit 2c1ac4e
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/usr/local/bin/install-buildpack
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ apt_install \

# check for /usr/local/share/ca-certificates/*.crt

if [[ "$(find /usr/local/share/ca-certificates/ -name *.crt -type f -printf '.' | wc -c)" -gt 0 ]]; then
if [[ "$(find /usr/local/share/ca-certificates/ -name "*.crt" -type f -printf '.' | wc -c)" -gt 0 ]]; then
echo "Found user certs, calling update-ca-certificates"
update-ca-certificates
fi
Expand Down
4 changes: 2 additions & 2 deletions src/usr/local/buildpack/tools/dotnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ if [[ -d "${DOTNET_INSTALL_DIR}/sdk/${TOOL_VERSION}" ]]; then
exit 0
fi

VERSION_CODENAME=$(. /etc/os-release && echo "${VERSION_CODENAME}")
version_codename=$(get_distro)

case "$VERSION_CODENAME" in
case "$version_codename" in
"bionic") apt_install libc6 libgcc1 libgssapi-krb5-2 libicu60 libssl1.1 libstdc++6 zlib1g;;
"focal") apt_install libc6 libgcc1 libgssapi-krb5-2 libicu66 libssl1.1 libstdc++6 zlib1g;;
esac
Expand Down
5 changes: 3 additions & 2 deletions src/usr/local/buildpack/tools/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
set -e

require_root
VERSION_CODENAME=$(. /etc/os-release && echo "${VERSION_CODENAME}")

echo "deb http://ppa.launchpad.net/git-core/ppa/ubuntu ${VERSION_CODENAME} main" | tee /etc/apt/sources.list.d/git.list
version_codename=$(get_distro)

echo "deb http://ppa.launchpad.net/git-core/ppa/ubuntu ${version_codename} main" | tee /etc/apt/sources.list.d/git.list
curl -sSL \
'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xE1DD270288B4E6030699E45FA1715D88E1DF1F24' \
| apt-key add -
Expand Down
1 change: 1 addition & 0 deletions src/usr/local/buildpack/tools/java-jre.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -e

check_semver "$TOOL_VERSION"

# shellcheck disable=SC2153
if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" ]]; then
echo Invalid version: "${TOOL_VERSION}"
exit 1
Expand Down
1 change: 1 addition & 0 deletions src/usr/local/buildpack/tools/java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -e

check_semver "$TOOL_VERSION"

# shellcheck disable=SC2153
if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" ]]; then
echo Invalid version: "${TOOL_VERSION}"
exit 1
Expand Down
8 changes: 6 additions & 2 deletions src/usr/local/buildpack/tools/node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ PREFIX="${USER_HOME}/.npm-global"


function update_env () {
local tool_env

reset_tool_env

link_wrapper "${TOOL_NAME}" "$tool_path/bin"
Expand All @@ -24,7 +26,9 @@ function update_env () {

export_tool_path "${PREFIX}/bin"

cat >> $(find_tool_env) <<- EOM
tool_env=$(find_tool_env)

cat >> "$tool_env" <<- EOM
# openshift override unknown user home
if [ "\${EUID}" != 0 ] && [ "\${EUID}" != ${USER_ID} ]; then
export NPM_CONFIG_PREFIX="${PREFIX}"
Expand All @@ -47,7 +51,7 @@ function prepare_global_config () {

function prepare_user_config () {
local prefix=${1}
if [[ -r "${USER_HOME}/.npmrc" && $(cat "${USER_HOME}/.npmrc" | grep 'prefix') ]]; then
if grep 'prefix' "${USER_HOME}/.npmrc"; then
return
fi

Expand Down
7 changes: 4 additions & 3 deletions src/usr/local/buildpack/tools/php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ if [[ -z "${tool_path}" ]]; then
file=/tmp/php.tar.xz

ARCH=$(uname -p)
CODENAME=$(. /etc/os-release && echo "${VERSION_CODENAME}")
BASE_URL="https://github.com/containerbase/php-prebuild/releases/download"

version_codename=$(get_distro)

# TODO: extract to separate preparation tool
require_root
case "$CODENAME" in
case "$version_codename" in
"bionic") apt_install \
libjpeg-turbo8 \
libmcrypt4 \
Expand All @@ -48,7 +49,7 @@ if [[ -z "${tool_path}" ]]; then
;;
esac

curl -sSfLo ${file} "${BASE_URL}/${TOOL_VERSION}/php-${TOOL_VERSION}-${CODENAME}-${ARCH}.tar.xz"
curl -sSfLo ${file} "${BASE_URL}/${TOOL_VERSION}/php-${TOOL_VERSION}-${version_codename}-${ARCH}.tar.xz"

if [[ -f ${file} ]]; then
echo 'Using prebuild php'
Expand Down
4 changes: 2 additions & 2 deletions src/usr/local/buildpack/tools/powershell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ if [[ -z "${tool_path}" ]]; then
base_path=${INSTALL_DIR}/${TOOL_NAME}
tool_path=${base_path}/${TOOL_VERSION}

VERSION_CODENAME=$(. /etc/os-release && echo "${VERSION_CODENAME}")
version_codename=$(get_distro)

case "$VERSION_CODENAME" in
case "$version_codename" in
"bionic") apt_install libc6 libgcc1 libgssapi-krb5-2 libicu60 libssl1.1 libstdc++6 zlib1g;;
"focal") apt_install libc6 libgcc1 libgssapi-krb5-2 libicu66 libssl1.1 libstdc++6 zlib1g;;
esac
Expand Down
11 changes: 7 additions & 4 deletions src/usr/local/buildpack/tools/python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ if [[ -z "${tool_path}" ]]; then
file=/tmp/python.tar.xz

ARCH=$(uname -p)
CODENAME=$(. /etc/os-release && echo "${VERSION_CODENAME}")
PYTHON_URL="https://github.com/containerbase/python-prebuild/releases/download"

curl -sSfLo ${file} "${PYTHON_URL}/${TOOL_VERSION}/python-${TOOL_VERSION}-${CODENAME}-${ARCH}.tar.xz" || echo 'Ignore download error'
version_codename=$(get_distro)

curl -sSfLo ${file} "${PYTHON_URL}/${TOOL_VERSION}/python-${TOOL_VERSION}-${version_codename}-${ARCH}.tar.xz" || echo 'Ignore download error'

if [[ -f ${file} ]]; then
echo 'Using prebuild python'
Expand Down Expand Up @@ -56,7 +57,9 @@ if [[ -z "${tool_path}" ]]; then
fi

fix_python_shebangs() {
for file in $(find "${tool_path}/bin" -type f -exec grep -Iq . {} \; -print); do
# https://github.com/koalaman/shellcheck/wiki/SC2044
while IFS= read -r -d '' file
do
case "$(head -1 "${file}")" in
"#!"*"/bin/python" )
sed -i "1 s:.*:#\!${tool_path}\/bin\/python:" "${file}"
Expand All @@ -68,7 +71,7 @@ if [[ -z "${tool_path}" ]]; then
sed -i "1 s:.*:#\!${tool_path}\/bin\/python${MAJOR}.${MINOR}:" "${file}"
;;
esac
done
done < <(find "${tool_path}/bin" -type f -exec grep -Iq . {} \; -print0)
}

fix_python_shebangs
Expand Down
7 changes: 4 additions & 3 deletions src/usr/local/buildpack/tools/ruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ if [[ ! -d "$tool_path" ]]; then
mkdir -p "$base_path"

ARCH=$(uname -p)
CODENAME=$(. /etc/os-release && echo "${VERSION_CODENAME}")
RUBY_URL="https://github.com/containerbase/ruby-prebuild/releases/download"

curl -sSfLo ruby.tar.xz "${RUBY_URL}/${TOOL_VERSION}/ruby-${TOOL_VERSION}-${CODENAME}-${ARCH}.tar.xz" || echo 'Ignore download error'
version_codename=$(get_distro)

curl -sSfLo ruby.tar.xz "${RUBY_URL}/${TOOL_VERSION}/ruby-${TOOL_VERSION}-${version_codename}-${ARCH}.tar.xz" || echo 'Ignore download error'

if [[ -f ruby.tar.xz ]]; then
echo "Using prebuild ruby for ${CODENAME}"
echo "Using prebuild ruby for ${version_codename}"
apt_install \
build-essential \
libffi-dev \
Expand Down
7 changes: 5 additions & 2 deletions src/usr/local/buildpack/tools/swift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ base_path=/usr/local/buildpack/${TOOL_NAME}
tool_path=$base_path/$TOOL_VERSION

if [[ ! -d "${tool_path}" ]]; then
VERSION_CODENAME=$(. /etc/os-release && echo "${VERSION_CODENAME}")

version_codename=$(get_distro)

# shellcheck source=/dev/null
VERSION_ID=$(. /etc/os-release && echo "${VERSION_ID}")

# https://swift.org/getting-started/#on-linux
# already installed: git

case "$VERSION_CODENAME" in
case "${version_codename}" in
"bionic")
apt_install \
binutils \
Expand Down
6 changes: 6 additions & 0 deletions src/usr/local/buildpack/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ function require_distro () {
esac
}

function get_distro() {
require_distro
# shellcheck source=/dev/null disable=SC2005
echo "$(. /etc/os-release && echo "${VERSION_CODENAME}")"
}

function require_root () {
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" >&2
Expand Down

0 comments on commit 2c1ac4e

Please sign in to comment.