From 4072d4d1c7b3a47d901b7cbd0efad3867194a7ed Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Wed, 21 Dec 2022 11:50:38 +0100 Subject: [PATCH] feat(powershell): convert to v2 tool --- src/usr/local/buildpack/tools/powershell.sh | 45 ------------------- .../local/buildpack/tools/v2/powershell.sh | 45 +++++++++++++++++++ test/powershell/Dockerfile | 6 ++- 3 files changed, 49 insertions(+), 47 deletions(-) delete mode 100644 src/usr/local/buildpack/tools/powershell.sh create mode 100644 src/usr/local/buildpack/tools/v2/powershell.sh diff --git a/src/usr/local/buildpack/tools/powershell.sh b/src/usr/local/buildpack/tools/powershell.sh deleted file mode 100644 index cea32641a1..0000000000 --- a/src/usr/local/buildpack/tools/powershell.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -set -e - -require_root -check_semver "${TOOL_VERSION}" - -if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" ]]; then - echo Invalid version: "${TOOL_VERSION}" - exit 1 -fi - - -tool_path=$(find_versioned_tool_path) - -if [[ -z "${tool_path}" ]]; then - INSTALL_DIR=$(get_install_dir) - base_path=${INSTALL_DIR}/${TOOL_NAME} - tool_path=${base_path}/${TOOL_VERSION} - - version_codename=$(get_distro) - - 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;; - "jammy") apt_install libc6 libgcc1 libgssapi-krb5-2 libicu70 libssl3 libstdc++6 zlib1g;; - *) - echo "Tool '${TOOL_NAME}' not supported on: ${version_codename}! Please use 'ubuntu' or 'bionic'." >&2 - exit 1 - ;; - esac - - mkdir -p "$tool_path/bin" - curl -sSL "https://github.com/PowerShell/PowerShell/releases/download/v${TOOL_VERSION}/powershell-${TOOL_VERSION}-linux-x64.tar.gz" --output "${TOOL_NAME}".tgz - bsdtar -C "$tool_path/bin" -xzf "${TOOL_NAME}".tgz - rm "${TOOL_NAME}".tgz - if [[ ! -x "${tool_path}/bin/pwsh" ]]; then - echo "fixing missing executable bit" - chmod +x "${tool_path}/bin/pwsh" - fi -fi - -link_wrapper pwsh "${tool_path}/bin" - -pwsh -Version diff --git a/src/usr/local/buildpack/tools/v2/powershell.sh b/src/usr/local/buildpack/tools/v2/powershell.sh new file mode 100644 index 0000000000..0a266fda79 --- /dev/null +++ b/src/usr/local/buildpack/tools/v2/powershell.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +function prepare_tool() { + local version_codename + + version_codename="$(get_distro)" + 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;; + "jammy") apt_install libc6 libgcc1 libgssapi-krb5-2 libicu70 libssl3 libstdc++6 zlib1g;; + *) + echo "Tool '${TOOL_NAME}' not supported on: ${version_codename}! Please use ubuntu 'bionic', 'focal' or 'jammy'." >&2 + exit 1 + ;; + esac + + create_tool_path > /dev/null +} + +function install_tool () { + local file + local versioned_tool_path + + if [[ ! -d "$(find_tool_path)" ]]; then + if [[ $(is_root) -ne 0 ]]; then + echo "${TOOL_NAME} not prepared" + exit 1 + fi + prepare_tool + fi + + versioned_tool_path=$(create_versioned_tool_path) + + file=$(get_from_url "https://github.com/PowerShell/PowerShell/releases/download/v${TOOL_VERSION}/powershell-${TOOL_VERSION}-linux-x64.tar.gz") + bsdtar -C "${versioned_tool_path}" -xzf "${file}" + # Happened on v7.3.0 + if [[ ! -x "${versioned_tool_path}/pwsh" ]]; then + chmod +x "${versioned_tool_path}/pwsh" + fi +} + +function link_tool () { + shell_wrapper pwsh "$(find_versioned_tool_path)" + pwsh -version +} diff --git a/test/powershell/Dockerfile b/test/powershell/Dockerfile index df41da9952..c84a079430 100644 --- a/test/powershell/Dockerfile +++ b/test/powershell/Dockerfile @@ -7,16 +7,18 @@ FROM ${IMAGE} as base RUN touch /.dummy #-------------------------------------- -# test: powershell 7.2 +# test: powershell 7.2 (non-root) #-------------------------------------- FROM base as testa ARG APT_HTTP_PROXY +RUN prepare-tool powershell + +USER 1000 # Don't update RUN install-tool powershell v7.2.8 -USER 1000 RUN set -ex; \ pwsh -Version