1bf215546Sopenharmony_ci#!/bin/bash
2bf215546Sopenharmony_ci
3bf215546Sopenharmony_ciset +e
4bf215546Sopenharmony_ciset -o xtrace
5bf215546Sopenharmony_ci
6bf215546Sopenharmony_ci# if we run this script outside of gitlab-ci for testing, ensure
7bf215546Sopenharmony_ci# we got meaningful variables
8bf215546Sopenharmony_ciCI_PROJECT_DIR=${CI_PROJECT_DIR:-$(mktemp -d)/$CI_PROJECT_NAME}
9bf215546Sopenharmony_ci
10bf215546Sopenharmony_ciif [[ -e $CI_PROJECT_DIR/.git ]]
11bf215546Sopenharmony_cithen
12bf215546Sopenharmony_ci    echo "Repository already present, skip cache download"
13bf215546Sopenharmony_ci    exit
14bf215546Sopenharmony_cifi
15bf215546Sopenharmony_ci
16bf215546Sopenharmony_ciTMP_DIR=$(mktemp -d)
17bf215546Sopenharmony_ci
18bf215546Sopenharmony_ciecho "Downloading archived master..."
19bf215546Sopenharmony_ci/usr/bin/wget -O $TMP_DIR/$CI_PROJECT_NAME.tar.gz \
20bf215546Sopenharmony_ci              https://${MINIO_HOST}/git-cache/${FDO_UPSTREAM_REPO}/$CI_PROJECT_NAME.tar.gz
21bf215546Sopenharmony_ci
22bf215546Sopenharmony_ci# check wget error code
23bf215546Sopenharmony_ciif [[ $? -ne 0 ]]
24bf215546Sopenharmony_cithen
25bf215546Sopenharmony_ci    echo "Repository cache not available"
26bf215546Sopenharmony_ci    exit
27bf215546Sopenharmony_cifi
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ciset -e
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_cirm -rf "$CI_PROJECT_DIR"
32bf215546Sopenharmony_ciecho "Extracting tarball into '$CI_PROJECT_DIR'..."
33bf215546Sopenharmony_cimkdir -p "$CI_PROJECT_DIR"
34bf215546Sopenharmony_citar xzf "$TMP_DIR/$CI_PROJECT_NAME.tar.gz" -C "$CI_PROJECT_DIR"
35bf215546Sopenharmony_cirm -rf "$TMP_DIR"
36bf215546Sopenharmony_cichmod a+w "$CI_PROJECT_DIR"
37