UNCLASSIFIED - NO CUI

Skip to content
Snippets Groups Projects
importArtifacts.sh 2.39 KiB
Newer Older
Scott Stroud's avatar
Scott Stroud committed

#!/bin/bash

start=`date +%s`

if [[ -f .env ]]; then
    echo "Loading in '.env' for values ..."
    export $(grep -v '^#' .env | xargs)
    echo " "
fi

SCRIPTS_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PROJECT_HOME=${PROJECT_HOME:-'../'}
PROJECT_HOME=$(realpath $PROJECT_HOME)
RESOURCE_HOME=${RESOURCE_HOME:-'../../resources'}
RESOURCE_HOME=$(realpath $RESOURCE_HOME)

importArtifacts() {
    
    manifestPath=$1
    httpdomain=$2
    resourceDir=$3

    echo -e "\nImporting ${httpdomain} artifacts ..."

    maniDir=$(dirname "$manifestPath")

    # (re)set the filelist.txt
    mkdir -p $resourceDir    
    prefix="url: "
    pushd $resourceDir
        grep $httpdomain $manifestPath | while read -r line ; do
            url=${line##*$prefix}
            filename=$(basename "$url")
            
            local=$(find $RESOURCE_HOME -name $filename)
            echo "local $local"

            if [[ -f "$filename" ]]; then
                echo "AA"
                echo "Using existing $filename. Run ./clean.sh if thats not desired."
            elif [[ ! -z "$local" ]]; then
                echo "BB"
                echo "Using existing $local. Run ./clean.sh if thats not desired."
                cp $local $maniDir/
            else
                echo "downloading ${url} ..."
                wget $url            
            fi

            if [[ ! -f "$maniDir/$filename" ]]; then
                echo "copying ${filename} into ${maniDir} ..."
                cp $filename $maniDir/
            fi
        done
    popd
}
    
mani=$(realpath "../hardening_manifest.yaml")

importArtifacts $mani 'ironbank-files.s3.amazonaws.com' "$RESOURCE_HOME/ironbank-files"
importArtifacts $mani 'packages.confluent.io' "$RESOURCE_HOME/confluent"
importArtifacts $mani 's3.us-west-2.amazonaws.com/staging-confluent-packages' "$RESOURCE_HOME/confluent"
importArtifacts $mani 'files.pythonhosted.org' "$RESOURCE_HOME/pythonhosted"
importArtifacts $mani 'repo1.maven.org' "$RESOURCE_HOME/maven"

# echo "Generating hardening_manifest_template.yaml ..."
# $SCRIPTS_HOME/genManifestTemplate.sh "$RESOURCE_HOME/ironbank-files"
# $SCRIPTS_HOME/genManifestTemplate.sh "$RESOURCE_HOME/confluent"
# $SCRIPTS_HOME/genManifestTemplate.sh "$RESOURCE_HOME/pythonhosted"

end=`date +%s`
duration=$((end-start))
echo "#########################"
echo "All done (${duration} seconds)"
echo "#########################"