|
| 1 | +#!/bin/bash |
| 2 | +set -uex |
| 3 | + |
| 4 | +# This script is used by dockerfiles to optionally use |
| 5 | +# a local repository instead of a distro provided repository. |
| 6 | +# It will also optionally allow running a /tmp/install script |
| 7 | +# for custom packages if present. |
| 8 | + |
| 9 | +: "${REPO_FILE_URL:=}" |
| 10 | +: "${HTTPS_PROXY:=}" |
| 11 | +: "${DAOS_LAB_CA_FILE_UR:=}" |
| 12 | +: "${REPOSITORY_NAME:=artifactory}" |
| 13 | + |
| 14 | +disable_repos () { |
| 15 | + if [ -e /etc/apt/sources.list.d/ubuntu.sources ];then |
| 16 | + mv /etc/apt/sources.list.d/ubuntu.sources \ |
| 17 | + etc/apt/sources.list.d/ubuntu.sources.disabled |
| 18 | + elif [ -e /etc/apt/sources.list ];then |
| 19 | + mv /etc/apt/sources.list \ |
| 20 | + etc/apt/sources.list.disabled |
| 21 | + fi |
| 22 | +} |
| 23 | + |
| 24 | +# Use local repo server if present |
| 25 | +install_curl() { |
| 26 | + |
| 27 | + if command -v curl; then |
| 28 | + echo "found curl!" |
| 29 | + return |
| 30 | + else |
| 31 | + apt-get update |
| 32 | + apt-get install curl ca-certificates gpg gpg-agent |
| 33 | + fi |
| 34 | + |
| 35 | + if command -v wget; then |
| 36 | + echo "found wget!" |
| 37 | + return |
| 38 | + fi |
| 39 | + # If we don't find one of these, we are basically sunk for using |
| 40 | + # a local repository mirror. |
| 41 | +} |
| 42 | + |
| 43 | +# Use local repo server if present |
| 44 | +install_optional_ca() { |
| 45 | + ca_storage="/usr/local/share/ca-certificates/" |
| 46 | + if [ -n "$DAOS_LAB_CA_FILE_URL" ]; then |
| 47 | + curl -k --noproxy '*' -sSf -o "${ca_storage}lab_ca_file.crt" \ |
| 48 | + "$DAOS_LAB_CA_FILE_URL" |
| 49 | + update-ca-certificates |
| 50 | + fi |
| 51 | +} |
| 52 | + |
| 53 | +echo "APT::Get::Assume-Yes \"true\";" > /etc/apt/apt.conf.d/no-prompt |
| 54 | +echo "APT::Install-Recommends \"false\";" > /etc/apt/apt.conf.d/no-recommends |
| 55 | +if [ -n "$HTTPS_PROXY" ];then |
| 56 | + apt_proxy="http://${HTTPS_PROXY##*//}" |
| 57 | + echo "Acquire::http::Proxy \"$apt_proxy\";" > \ |
| 58 | + /etc/apt/apt.conf.d/local_proxy |
| 59 | + if [ -n "$REPO_FILE_URL" ]; then |
| 60 | + direct="${REPO_FILE_URL##*//}" |
| 61 | + direct="${direct%%/*}" |
| 62 | + echo "Acquire::http::Proxy { $direct DIRECT; };" >> \ |
| 63 | + /etc/apt/apt.conf.d/local_proxy |
| 64 | + fi |
| 65 | +fi |
| 66 | + |
| 67 | +# Use local repo server if present |
| 68 | +# if a local repo server is present and the distro repo server can not |
| 69 | +# be reached, have to bootstrap in an environment to get curl installed |
| 70 | +# to then install the pre-built repo file. |
| 71 | +DISTRO_VERSION="${BASE_DISTRO##*:}" |
| 72 | +if [ -n "$REPO_FILE_URL" ]; then |
| 73 | + install_curl |
| 74 | + install_optional_ca |
| 75 | + curl -k --noproxy '*' -sSf \ |
| 76 | + -o "daos_ci-ubuntu${DISTRO_VERSION}-${REPOSITORY_NAME}.list" \ |
| 77 | + "${REPO_FILE_URL}daos_ci-ubuntu${DISTRO_VERSION}-${REPOSITORY_NAME}.list" |
| 78 | + disable_repos |
| 79 | + mkdir -p /usr/local/share/keyrings/ |
| 80 | + curl --noproxy '*' -sSf -O "${REPO_FILE_URL}esad_repo.key" |
| 81 | + gpg --no-default-keyring --keyring ./temp-keyring.gpg \ |
| 82 | + --import esad_repo.key |
| 83 | + gpg --no-default-keyring --keyring ./temp-keyring.gpg --export \ |
| 84 | + --output /usr/local/share/keyrings/daos-stack-public.gpg |
| 85 | +fi |
| 86 | + |
| 87 | +apt-get update |
| 88 | +apt-get upgrade |
| 89 | +apt-get install gpg-agent software-properties-common |
| 90 | +add-apt-repository ppa:longsleep/golang-backports |
| 91 | +apt-get update |
| 92 | +chmod +x /tmp/install.sh |
| 93 | +/tmp/install.sh |
| 94 | +apt-get clean all |
0 commit comments