diff --git a/dockerfile_functions.sh b/dockerfile_functions.sh index e5bf7896..83317c94 100755 --- a/dockerfile_functions.sh +++ b/dockerfile_functions.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# shellcheck disable=SC1083,SC2086,SC2154 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,7 +16,7 @@ # Generate the common license and copyright header print_legal() { - cat > $1 <<-EOI + cat > "$1" <<-EOI # ------------------------------------------------------------------------------ # NOTE: THIS DOCKERFILE IS GENERATED VIA "build_latest.sh" or "update_multiarch.sh" # @@ -42,7 +43,7 @@ print_legal() { print_ubuntu_ver() { os_version="18.04" - cat >> $1 <<-EOI + cat >> "$1" <<-EOI FROM ubuntu:${os_version} EOI @@ -52,7 +53,7 @@ print_ubuntu_ver() { print_debian_ver() { os_version="buster" - cat >> $1 <<-EOI + cat >> "$1" <<-EOI FROM debian:${os_version} EOI @@ -62,7 +63,7 @@ print_debian_ver() { print_debianslim_ver() { os_version="buster-slim" - cat >> $1 <<-EOI + cat >> "$1" <<-EOI FROM debian:${os_version} EOI @@ -71,7 +72,7 @@ print_debianslim_ver() { print_ubi_ver() { os_version="8.1" - cat >> $1 <<-EOI + cat >> "$1" <<-EOI FROM registry.access.redhat.com/ubi8/ubi:${os_version} EOI @@ -80,7 +81,7 @@ print_ubi_ver() { print_ubi-minimal_ver() { os_version="8.1" - cat >> $1 <<-EOI + cat >> "$1" <<-EOI FROM registry.access.redhat.com/ubi8/ubi-minimal:${os_version} EOI @@ -89,7 +90,7 @@ print_ubi-minimal_ver() { print_centos_ver() { os_version="7" - cat >> $1 <<-EOI + cat >> "$1" <<-EOI FROM centos:${os_version} EOI @@ -98,7 +99,7 @@ print_centos_ver() { print_clefos_ver() { os_version="7" - cat >> $1 <<-EOI + cat >> "$1" <<-EOI FROM clefos:${os_version} EOI @@ -113,15 +114,15 @@ print_windows_ver() { *1809) os_version="1809" ;; esac - servertype=$(echo $file | cut -f4 -d"/") + servertype=$(echo "$file" | cut -f4 -d"/") nanoserver_pat="nanoserver.*" if [[ "$servertype" =~ ${nanoserver_pat} ]]; then - cat >> $1 <<-EOI + cat >> "$1" <<-EOI FROM mcr.microsoft.com/powershell:nanoserver-${os_version} EOI else - cat >> $1 <<-EOI + cat >> "$1" <<-EOI FROM mcr.microsoft.com/windows/servercore:${os_version} EOI @@ -131,7 +132,7 @@ EOI # Print the supported Alpine OS print_alpine_ver() { - cat >> $1 <<-EOI + cat >> "$1" <<-EOI FROM alpine:3.11 EOI @@ -140,8 +141,8 @@ print_alpine_ver() { # Print the locale and language print_lang_locale() { os=$2 - if [ $os != "windows" ]; then - cat >> $1 <<-EOI + if [ "$os" != "windows" ]; then + cat >> "$1" <<-EOI ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8' EOI @@ -150,7 +151,7 @@ print_lang_locale() { # Select the ubuntu OS packages print_ubuntu_pkg() { - cat >> $1 <<'EOI' + cat >> "$1" <<'EOI' RUN apt-get update \ && apt-get install -y --no-install-recommends curl ca-certificates fontconfig locales \ && echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \ @@ -160,23 +161,23 @@ EOI } print_debian_pkg() { - print_ubuntu_pkg $1 + print_ubuntu_pkg "$1" } print_debianslim_pkg() { - print_ubuntu_pkg $1 + print_ubuntu_pkg "$1" } print_windows_pkg() { - servertype=$(echo $file | cut -f4 -d"/") + servertype=$(echo "$file" | cut -f4 -d"/") nanoserver_pat="nanoserver.*" if [[ "$servertype" =~ ${nanoserver_pat} ]]; then - cat >> $1 <<'EOI' + cat >> "$1" <<'EOI' # $ProgressPreference: https://github.com/PowerShell/PowerShell/issues/2138#issuecomment-251261324 SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] EOI else - cat >> $1 <<'EOI' + cat >> "$1" <<'EOI' # $ProgressPreference: https://github.com/PowerShell/PowerShell/issues/2138#issuecomment-251261324 SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] EOI @@ -186,7 +187,7 @@ EOI # Select the alpine OS packages. # Install GNU glibc as this OpenJDK build is compiled against glibc and not musl. print_alpine_pkg() { - cat >> $1 <<'EOI' + cat >> "$1" <<'EOI' RUN apk add --no-cache --virtual .build-deps curl binutils \ && GLIBC_VER="2.30-r0" \ && ALPINE_GLIBC_REPO="https://github.com/sgerrand/alpine-pkg-glibc/releases/download" \ @@ -223,7 +224,7 @@ EOI # Select the ubi OS packages. print_ubi_pkg() { - cat >> $1 <<'EOI' + cat >> "$1" <<'EOI' RUN dnf install -y openssl curl ca-certificates fontconfig glibc-langpack-en gzip tar \ && dnf update; dnf clean all EOI @@ -232,7 +233,7 @@ EOI # Select the ubi OS packages. print_ubi-minimal_pkg() { - cat >> $1 <<'EOI' + cat >> "$1" <<'EOI' RUN microdnf install openssl curl ca-certificates fontconfig glibc-langpack-en gzip tar \ && microdnf update; microdnf clean all EOI @@ -240,7 +241,7 @@ EOI # Select the CentOS packages. print_centos_pkg() { - cat >> $1 <<'EOI' + cat >> "$1" <<'EOI' RUN yum install -y openssl curl ca-certificates fontconfig gzip tar \ && yum update; yum clean all EOI @@ -249,18 +250,20 @@ EOI # Select the ClefOS packages. print_clefos_pkg() { - print_centos_pkg $1 + print_centos_pkg "$1" } # Print the Java version that is being installed here print_env() { + # shellcheck disable=SC2154 shasums="${package}"_"${vm}"_"${version}"_"${build}"_sums - jverinfo=${shasums}[version] + jverinfo="${shasums}[version]" + # shellcheck disable=SC1083,SC2086 # TODO not sure about intention here eval jver=\${$jverinfo} - + jver="${jver}" # to satifsy shellcheck SC2154 # Print additional label for UBI alone if [ "${os}" == "ubi-minimal" ] || [ "${os}" == "ubi" ]; then - cat >> $1 <<-EOI + cat >> "$1" <<-EOI LABEL name="AdoptOpenJDK Java" \\ vendor="AdoptOpenJDK" \\ @@ -272,7 +275,7 @@ LABEL name="AdoptOpenJDK Java" \\ EOI fi - cat >> $1 <<-EOI + cat >> "$1" <<-EOI ENV JAVA_VERSION ${jver} @@ -288,59 +291,59 @@ print_java_install_pre() { if [ "${vm}" != "hotspot" ]; then reldir="${reldir}-${vm}"; fi - supported_arches=$(get_arches ${shasums} | sort) + supported_arches=$(get_arches "${shasums}" | sort) for sarch in ${supported_arches} do if [ "${sarch}" == "aarch64" ]; then - JAVA_URL=$(get_v2_url info ${bld} ${vm} ${pkg} latest aarch64); - cat >> $1 <<-EOI + JAVA_URL=$(get_v2_url info "${bld}" "${vm}" "${pkg}" latest aarch64); + cat >> "$1" <<-EOI aarch64|arm64) \\ - ESUM='$(sarray=${shasums}[aarch64]; eval esum=\${$sarray}; echo ${esum})'; \\ - BINARY_URL='$(get_binary_url ${JAVA_URL})'; \\ + ESUM='$(sarray="${shasums}[aarch64]"; eval esum=\${$sarray}; echo "${esum}")'; \\ + BINARY_URL='$(get_binary_url "${JAVA_URL}")'; \\ ;; \\ EOI elif [ "${sarch}" == "armv7l" ]; then - JAVA_URL=$(get_v2_url info ${bld} ${vm} ${pkg} latest arm); - cat >> $1 <<-EOI + JAVA_URL=$(get_v2_url info "${bld}" "${vm}" "${pkg}" latest arm); + cat >> "$1" <<-EOI armhf|armv7l) \\ - ESUM='$(sarray=${shasums}[armv7l]; eval esum=\${$sarray}; echo ${esum})'; \\ - BINARY_URL='$(get_binary_url ${JAVA_URL})'; \\ + ESUM='$(sarray="${shasums}[armv7l]"; eval esum=\${$sarray}; echo "${esum}")'; \\ + BINARY_URL='$(get_binary_url "${JAVA_URL}")'; \\ ;; \\ EOI elif [ "${sarch}" == "ppc64le" ]; then - JAVA_URL=$(get_v2_url info ${bld} ${vm} ${pkg} latest ppc64le); - cat >> $1 <<-EOI + JAVA_URL=$(get_v2_url info "${bld}" "${vm}" "${pkg}" latest ppc64le); + cat >> "$1" <<-EOI ppc64el|ppc64le) \\ - ESUM='$(sarray=${shasums}[ppc64le]; eval esum=\${$sarray}; echo ${esum})'; \\ - BINARY_URL='$(get_binary_url ${JAVA_URL})'; \\ + ESUM='$(sarray="${shasums}[ppc64le]"; eval esum=\${$sarray}; echo "${esum}")'; \\ + BINARY_URL='$(get_binary_url "${JAVA_URL}")'; \\ ;; \\ EOI elif [ "${sarch}" == "s390x" ]; then - JAVA_URL=$(get_v2_url info ${bld} ${vm} ${pkg} latest s390x); - cat >> $1 <<-EOI + JAVA_URL=$(get_v2_url info "${bld}" "${vm}" "${pkg}" latest s390x); + cat >> "$1" <<-EOI s390x) \\ - ESUM='$(sarray=${shasums}[s390x]; eval esum=\${$sarray}; echo ${esum})'; \\ - BINARY_URL='$(get_binary_url ${JAVA_URL})'; \\ + ESUM='$(sarray="${shasums}[s390x]"; eval esum=\${$sarray}; echo "${esum}")'; \\ + BINARY_URL='$(get_binary_url "${JAVA_URL}")'; \\ ;; \\ EOI elif [ "${sarch}" == "x86_64" ]; then - JAVA_URL=$(get_v2_url info ${bld} ${vm} ${pkg} latest x64); - cat >> $1 <<-EOI + JAVA_URL=$(get_v2_url info "${bld}" "${vm}" "${pkg}" latest x64); + cat >> "$1" <<-EOI amd64|x86_64) \\ - ESUM='$(sarray=${shasums}[x86_64]; eval esum=\${$sarray}; echo ${esum})'; \\ - BINARY_URL='$(get_binary_url ${JAVA_URL})'; \\ + ESUM='$(sarray="${shasums}[x86_64]"; eval esum=\${$sarray}; echo "${esum}")'; \\ + BINARY_URL='$(get_binary_url "${JAVA_URL}")'; \\ ;; \\ EOI fi done - cat >> $1 <<-EOI + cat >> "$1" <<-EOI *) \\ echo "Unsupported arch: \${ARCH}"; \\ exit 1; \\ ;; \\ esac; \\ EOI - cat >> $1 <<'EOI' + cat >> "$1" <<'EOI' curl -LfsSo /tmp/openjdk.tar.gz ${BINARY_URL}; \ echo "${ESUM} */tmp/openjdk.tar.gz" | sha256sum -c -; \ mkdir -p /opt/java/openjdk; \ @@ -350,7 +353,7 @@ EOI } print_java_install_post() { - cat >> $1 <<-EOI + cat >> "$1" <<-EOI rm -rf /tmp/openjdk.tar.gz; EOI } @@ -359,7 +362,7 @@ EOI # Install binutils for this phase as we need the "strip" command # Uninstall once done print_ubuntu_slim_package() { - cat >> $1 <<-EOI + cat >> "$1" <<-EOI export PATH="${jhome}/bin:\$PATH"; \\ apt-get update; apt-get install -y --no-install-recommends binutils; \\ /usr/local/bin/slim-java.sh ${jhome}; \\ @@ -369,14 +372,14 @@ EOI } print_debianslim_package() { - print_ubuntu_slim_package $1 + print_ubuntu_slim_package "$1" } # Call the script to create the slim package for Alpine # Install binutils for this phase as we need the "strip" command # Uninstall once done print_alpine_slim_package() { - cat >> $1 <<-EOI + cat >> "$1" <<-EOI export PATH="${jhome}/bin:\$PATH"; \\ apk add --no-cache --virtual .build-deps bash binutils; \\ /usr/local/bin/slim-java.sh ${jhome}; \\ @@ -390,24 +393,24 @@ print_ubuntu_java_install() { pkg=$2 bld=$3 btype=$4 - cat >> $1 <<-EOI + cat >> "$1" <<-EOI RUN set -eux; \\ ARCH="\$(dpkg --print-architecture)"; \\ case "\${ARCH}" in \\ EOI - print_java_install_pre ${file} ${pkg} ${bld} ${btype} + print_java_install_pre "${file}" "${pkg}" "${bld}" "${btype}" if [ "${btype}" == "slim" ]; then - print_ubuntu_slim_package $1 + print_ubuntu_slim_package "$1" fi - print_java_install_post $1 + print_java_install_post "$1" } print_debian_java_install() { - print_ubuntu_java_install $1 $2 $3 $4 + print_ubuntu_java_install "$1" "$2" "$3" "$4" } print_debianslim_java_install() { - print_ubuntu_java_install $1 $2 $3 $4 + print_ubuntu_java_install "$1" "$2" "$3" "$4" } # Print the main RUN command that installs Java on ubuntu. @@ -416,14 +419,14 @@ print_windows_java_install() { bld=$3 btype=$4 - servertype=$(echo $file | cut -f4 -d"/" | cut -f1 -d"-") - version=$(echo $file | cut -f1 -d "/") + servertype=$(echo "$file" | cut -f4 -d"/" | cut -f1 -d"-") + version=$(echo "$file" | cut -f1 -d "/") if [ "$servertype" == "windowsservercore" ]; then - JAVA_URL=$(get_v2_url info ${bld} ${vm} ${pkg} latest windows-amd); - ESUM=$(sarray=${shasums}[windows-amd]; eval esum=\${$sarray}; echo ${esum}); - BINARY_URL=$(get_instaler_url ${JAVA_URL}); + JAVA_URL=$(get_v2_url info "${bld}" "${vm}" "${pkg}" latest windows-amd); + ESUM=$(sarray="${shasums}[windows-amd]"; eval esum=\${$sarray}; echo "${esum}"); + BINARY_URL=$(get_instaler_url "${JAVA_URL}"); - cat >> $1 <<-EOI + cat >> "$1" <<-EOI RUN Write-Host ('Downloading ${BINARY_URL} ...'); \\ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \\ wget ${BINARY_URL} -O 'openjdk.msi'; \\ @@ -443,11 +446,12 @@ RUN Write-Host ('Downloading ${BINARY_URL} ...'); \\ Remove-Item -Path C:\temp -Recurse | Out-Null; EOI else - JAVA_URL=$(get_v2_url info ${bld} ${vm} ${pkg} latest windows-nano); - ESUM=$(sarray=${shasums}[windows-nano]; eval esum=\${$sarray}; echo ${esum}); - BINARY_URL=$(get_binary_url ${JAVA_URL}); + JAVA_URL=$(get_v2_url info "${bld}" "${vm}" "${pkg}" latest windows-nano); + # shellcheck disable=SC1083 + ESUM=$(sarray="${shasums}[windows-nano]"; eval esum=\${"$sarray"}; echo "${esum}"); + BINARY_URL=$(get_binary_url "${JAVA_URL}"); - cat >> $1 <<-EOI + cat >> "$1" <<-EOI USER ContainerAdministrator RUN Write-Host ('Downloading ${BINARY_URL} ...'); \\ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \\ @@ -474,21 +478,21 @@ print_alpine_java_install() { pkg=$2 bld=$3 btype=$4 - cat >> $1 <<-EOI + cat >> "$1" <<-EOI RUN set -eux; \\ apk add --no-cache --virtual .fetch-deps curl; \\ ARCH="\$(apk --print-arch)"; \\ case "\${ARCH}" in \\ EOI - print_java_install_pre ${file} ${pkg} ${bld} ${btype} + print_java_install_pre "${file}" "${pkg}" "${bld}" "${btype}" if [ "${btype}" == "slim" ]; then - print_alpine_slim_package $1 + print_alpine_slim_package "$1" fi - cat >> $1 <<-EOI + cat >> "$1" <<-EOI apk del --purge .fetch-deps; \\ rm -rf /var/cache/apk/*; \\ EOI - print_java_install_post $1 + print_java_install_post "$1" } # Print the main RUN command that installs Java on ubi @@ -496,18 +500,18 @@ print_ubi_java_install() { pkg=$2 bld=$3 btype=$4 - cat >> $1 <<-EOI + cat >> "$1" <<-EOI RUN set -eux; \\ ARCH="\$(uname -m)"; \\ case "\${ARCH}" in \\ EOI - print_java_install_pre ${file} ${pkg} ${bld} ${btype} - print_java_install_post $1 + print_java_install_pre "${file}" "${pkg}" "${bld}" "${btype}" + print_java_install_post "$1" } # Print the main RUN command that installs Java on ubi-minimal print_ubi-minimal_java_install() { - print_ubi_java_install $1 $2 $3 $4 + print_ubi_java_install "$1" "$2" "$3" "$4" } # Print the main RUN command that installs Java on CentOS @@ -515,37 +519,37 @@ print_centos_java_install() { pkg=$2 bld=$3 btype=$4 - cat >> $1 <<-EOI + cat >> "$1" <<-EOI RUN set -eux; \\ ARCH="\$(uname -m)"; \\ case "\${ARCH}" in \\ EOI - print_java_install_pre ${file} ${pkg} ${bld} ${btype} - print_java_install_post $1 + print_java_install_pre "${file}" "${pkg}" "${bld}" "${btype}" + print_java_install_post "$1" } # Print the main RUN command that installs Java on ClefOS print_clefos_java_install() { - print_centos_java_install $1 $2 $3 $4 + print_centos_java_install "$1" "$2" "$3" "$4" } # Print the JAVA_HOME and PATH. # Currently Java is installed at a fixed path "/opt/java/openjdk" print_java_env() { # e.g 11 or 8 - version=$(echo $file | cut -f1 -d"/") + version=$(echo "$file" | cut -f1 -d"/") os=$4 if [ "$os" != "windows" ]; then - cat >> $1 <<-EOI + cat >> "$1" <<-EOI ENV JAVA_HOME=${jhome} \\ PATH="${jhome}/bin:\$PATH" EOI else - servertype=$(echo $file | cut -f4 -d"/") + servertype=$(echo "$file" | cut -f4 -d"/") nanoserver_pat="nanoserver.*" if [[ "$servertype" =~ ${nanoserver_pat} ]]; then - cat >> $1 <<-EOI + cat >> "$1" <<-EOI ENV JAVA_HOME=C:\\\\openjdk-${version} \\ ProgramFiles="C:\\\\Program Files" \\ WindowsPATH="C:\\\\Windows\\\\system32;C:\\\\Windows" @@ -573,8 +577,8 @@ print_java_options() { ;; esac - if [ ! -z "${JOPTS}" ]; then - cat >> $1 <<-EOI + if [ -n "${JOPTS}" ]; then + cat >> "$1" <<-EOI ENV JAVA_TOOL_OPTIONS="${JOPTS}" EOI fi @@ -583,7 +587,7 @@ EOI # For slim builds copy the slim script and related config files. copy_slim_script() { if [ "${btype}" == "slim" ]; then - cat >> $1 <<-EOI + cat >> "$1" <<-EOI COPY slim-java* /usr/local/bin/ EOI @@ -594,7 +598,7 @@ print_cmd() { # for version > 8, set CMD["jshell"] in the Dockerfile above_8="^(9|[1-9][0-9]+)$" if [[ "${version}" =~ ${above_8} && "${package}" == "jdk" ]]; then - cat >> $1 <<-EOI + cat >> "$1" <<-EOI CMD ["jshell"] EOI fi @@ -617,21 +621,21 @@ generate_dockerfile() { jhome="/opt/java/openjdk" - mkdir -p `dirname ${file}` 2>/dev/null + mkdir -p "$(dirname "${file}")" 2>/dev/null echo echo -n "Writing ${file} ... " - print_legal ${file}; - print_${os_family}_ver ${file} ${bld} ${btype} ${os}; - print_lang_locale ${file} ${os_family}; - print_${os_family}_pkg ${file}; - print_env ${file} ${bld} ${btype}; - copy_slim_script ${file}; - print_${os_family}_java_install ${file} ${pkg} ${bld} ${btype}; - print_java_env ${file} ${bld} ${btype} ${os_family}; - print_java_options ${file} ${bld} ${btype}; - print_cmd ${file}; + print_legal "${file}"; + print_"${os_family}"_ver "${file}" "${bld}" "${btype}" "${os}"; + print_lang_locale "${file}" "${os_family}"; + print_"${os_family}"_pkg "${file}"; + print_env "${file}" "${bld}" "${btype}"; + copy_slim_script "${file}"; + print_"${os_family}"_java_install "${file}" "${pkg}" "${bld}" "${btype}"; + print_java_env "${file}" "${bld}" "${btype}" "${os_family}"; + print_java_options "${file}" "${bld}" "${btype}"; + print_cmd "${file}"; echo "done" echo # Reset os back to the value of disto - os_family=$os + os_family="$os" }