Skip to content

Instantly share code, notes, and snippets.

@mik-laj
Created January 6, 2022 11:51
Show Gist options
  • Save mik-laj/8537099be477dd62cd23c8f608a52791 to your computer and use it in GitHub Desktop.
Save mik-laj/8537099be477dd62cd23c8f608a52791 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
set -euo pipefail
INSTALL_DIR="/src/opt/java"
BIN_PATH="/src/bin/java"
if [[ $# != "0" && ${1} == "--reinstall" ]]; then
rm -rf "${INSTALL_DIR}"
rm -f "${BIN_PATH}"
fi
hash -r
if command -v java; then
echo 'The "java" command found. Installation not needed. Run with --reinstall to reinstall'
exit 1
fi
DOWNLOAD_URL='https://download.java.net/openjdk/jdk8u41/ri/openjdk-8u41-b04-linux-x64-14_jan_2020.tar.gz'
if [[ -e ${INSTALL_DIR} ]]; then
echo "The install directory (${INSTALL_DIR}) already exists. This may mean java is already installed."
echo "Run with --reinstall to reinstall."
exit 1
fi
TMP_DIR="$(mktemp -d)"
# shellcheck disable=SC2064
trap "rm -rf ${TMP_DIR}" EXIT
mkdir -p "${INSTALL_DIR}"
echo "Downloading from ${DOWNLOAD_URL}"
curl -# --fail "${DOWNLOAD_URL}" --output "${TMP_DIR}/openjdk.tar.gz"
echo "Extracting archive"
tar xzf "${TMP_DIR}/openjdk.tar.gz" -C "${INSTALL_DIR}" --strip-components=1
BIN_DIR=$(dirname "${BIN_PATH}")
echo "Symlinking executables files to ${BIN_DIR}"
mkdir -p "${BIN_DIR}"
while IPS='' read -r line; do
BIN_NAME="$(basename "${line}")"
ln -s "${line}" "${BIN_DIR}/${BIN_NAME}"
done < <(find "${INSTALL_DIR}/bin/" -type f)
# Coherence check
if ! command -v java > /dev/null; then
echo 'Installation failed. The command "java" was not found.'
exit 1
fi
echo 'Installation complete.'
#!/usr/bin/env bash
set -euox pipefail
docker run -ti --rm -v "$PWD:/src" -w "/src" python:3.9-slim-buster bash verify.sh
#!/usr/bin/env bash
set -euox pipefail
apt update && apt install -y subversion gnupg libdigest-sha-perl curl
export PATH="/src/bin/:$PATH"
if ! command -v java > /dev/null; then
echo "Not installed"
./install_java.sh
else
echo "Installed"
fi
if ! java -jar /src/opt/apache-rat-0.13/apache-rat-0.13.jar --help > /dev/null; then
curl -o '/tmp/apache-rat-0.13-bin.tar.gz' https://dlcdn.apache.org//creadur/apache-rat-0.13/apache-rat-0.13-bin.tar.gz
tar xzf "/tmp/apache-rat-0.13-bin.tar.gz" -C "/src/opt/"
if ! java -jar /src/opt/apache-rat-0.13/apache-rat-0.13.jar --help > /dev/null; then
echo "Apache RAT cann't be installed"
fi
fi
curl -O 'https://dist.apache.org/repos/dist/release/airflow/KEYS'
gpg --import KEYS
gpg --list-keys --fingerprint --with-colons | grep fpr | cut -d ":" -f 10 | xargs -n 1 -I {} echo "{}:5:" | gpg --import-ownertrust
curl -O 'https://raw.githubusercontent.com/apache/airflow/main/.rat-excludes'
svn co 'https://dist.apache.org/repos/dist/dev/airflow/'
cd airflow
svn update .
function verify_gpg() {
gpg --verify "${1}" &> /dev/null && echo "Success: ${1}" || echo "Fail: ${1}"
}
export -f verify_gpg
find . -name '*.asc' -exec bash -c "verify_gpg \"{}\"" \;
function verify_sha() {
(
cd "$(dirname "${1}")"
shasum -a 512 "$(basename "${1}" .sha512)" | diff - "$(basename "${1}")" && echo "Success: ${1}" || echo "Fail: ${1}"
)
}
export -f verify_sha
find . -name '*.sha512' -exec bash -c "verify_sha \"{}\"" \;
function verify_licence() {
filename=$(basename -- "$1")
filename="${filename%.*}"
mkdir -p "/tmp/${filename}"
tar xzf "${1}" -C "/tmp/${filename}" --strip-components=1
(
cd "/tmp/${filename}"
java -jar /src/opt/apache-rat-0.13/apache-rat-0.13.jar -E /src/.rat-excludes -d .
)
}
export -f verify_licence
find . -name '*.tar.gz' -exec bash -x -c "verify_licence \"{}\"" \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment