diff --git a/mithril-aggregator-fake/README.md b/mithril-aggregator-fake/README.md index e47487a4491..e5488f60038 100644 --- a/mithril-aggregator-fake/README.md +++ b/mithril-aggregator-fake/README.md @@ -30,17 +30,32 @@ For each file, the identifiers of the corresponding artifacts are extracted and If a file is missing or incomplete, the software will stop with an error message. +This project comes with a shell script that reads data from a given Mithril Aggregator URL and creates the data files in a directory: + +``` +./scripts/import.sh some/data/directory http://valid.mithril.url/aggregator +``` + ## Command line synopsis -Usage: `mithril-fake-aggregator [OPTIONS]` +Usage: `mithril-aggregator-fake [OPTIONS]` Options: ``` -d, --data-directory Directory where the response files are located - -v, --verbose... Verbose mode (-q, -v, -vv, -vvv, etc) + -v, --verbose... Verbose mode (-v, -vv, -vvv, etc) + -q, --quiet Quiet mode. Suppress all outputs. -p, --tcp-port TCP port to listen on [default: 80] -i, --ip-address IP Address to bind server to [default: 127.0.0.1] -h, --help Print help -V, --version Print version ``` + +## Examples + +Launching the fake Aggregator on `127.0.0.1:80` (requires root privileges) using builtin data with the ERROR verbose level: +`./mithril-aggregator-fake` + +Launching the fake Aggregator on `127.0.0.1:8000` reading data from `some/data/directory` subdirectory with the INFO verbose level: +`./mithril-aggregator-fake -p 8000 -d some/data/directory -vv` diff --git a/mithril-aggregator-fake/scripts/import.sh b/mithril-aggregator-fake/scripts/import.sh index 2f7f73feb5c..9915f9fb2bb 100755 --- a/mithril-aggregator-fake/scripts/import.sh +++ b/mithril-aggregator-fake/scripts/import.sh @@ -1,9 +1,26 @@ #!/usr/bin/env bash set +a -eu -o pipefail -#set -v +#set -vx + +check_requirements() { + which wget >/dev/null || + error "It seems 'wget' is not installed or not in the path."; +} + +display_help() { + if [ -n "${1-""}" ]; then echo "ERROR: ${1}"; echo; fi + echo "HELP" + echo $0 + echo + echo "Import and save data from a given Mithril Aggregator." + echo + echo "Usage: $0 DATA_DIRECTORY URL" + echo + exit 1; +} error() { - echo $1; + echo "ERROR: $1"; exit 1; } @@ -63,14 +80,18 @@ download_certificate_chain() { # MAIN execution -declare -r DATA_DIR=${1:?"No data directory given to download JSON files."}; -declare -r BASE_URL=${2:?"No Mithril Aggregator URL given."}; +if [ -z "${1-""}" ]; then display_help "No data directory given to download JSON files."; fi; +if [ -z "${2-""}" ]; then display_help "No Mithril Aggregator URL given."; fi; + +declare -r DATA_DIR=$1; +declare -r BASE_URL=$2; if [ ! -d "$DATA_DIR" ]; then error "Specified directory '${DATA_DIR}' is not a directory."; fi -wget --quiet --server-response --spider $BASE_URL || error "Could not reach URL '${BASE_URL}'."; +wget --quiet --server-response --spider $BASE_URL 2>/dev/null || error "Could not reach URL '${BASE_URL}'."; export DATA_DIR URL; +check_requirements; clean_directory; download_list "$BASE_URL/certificates" "certificates"