Skip to content

Commit

Permalink
fetch-configlet: allow running from the bin directory (#284)
Browse files Browse the repository at this point in the history
This commit improves the `fetch-configlet` script in two ways:

1. It allows `fetch-configlet` to be run from the `bin` directory itself, instead of requiring it to be run from the repo's root directory.
2. It will output an error if the repo root does not have a `bin` directory.

Co-authored-by: Isaac Good <[email protected]>
  • Loading branch information
IsaacG and Isaac Good authored Apr 29, 2021
1 parent 237e841 commit 3815d7a
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions scripts/fetch-configlet
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,26 @@ get_download_url() {
cut -d'"' -f4
}

download_url="$(get_download_url)"
output_dir="bin"
output_path="${output_dir}/latest-configlet.${ext}"
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"

case "${ext}" in
*zip) unzip "${output_path}" -d "${output_dir}" ;;
*) tar xzf "${output_path}" -C "${output_dir}" ;;
esac
main () {
if [[ -d ./bin ]]; then
output_dir="./bin"
elif [[ $PWD = */bin ]]; then
output_dir="$PWD"
else
echo "Error: no ./bin directory found. This script should be ran from a repo root." >&2
return 1
fi

download_url="$(get_download_url)"
output_path="${output_dir}/latest-configlet.${ext}"
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"

case "${ext}" in
*zip) unzip "${output_path}" -d "${output_dir}" ;;
*) tar xzf "${output_path}" -C "${output_dir}" ;;
esac

rm -f "${output_path}"
}

rm -f "${output_path}"
main

0 comments on commit 3815d7a

Please sign in to comment.