Skip to content

Commit 5b53c84

Browse files
kytrinyxkotp
authored andcommitted
Update bin/fetch-configlet script
The script has been tweaked to work better across all platforms.
1 parent 8871a8e commit 5b53c84

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

bin/fetch-configlet

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/usr/bin/env bash
22

3+
# This file is a copy of the
4+
# https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet file.
5+
# Please submit bugfixes/improvements to the above file to ensure that all tracks benefit from the changes.
6+
37
set -eo pipefail
48

59
readonly LATEST='https://api.github.com/repos/exercism/configlet/releases/latest'
@@ -45,14 +49,26 @@ get_download_url() {
4549
cut -d'"' -f4
4650
}
4751

48-
download_url="$(get_download_url)"
49-
output_dir="bin"
50-
output_path="${output_dir}/latest-configlet.${ext}"
51-
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
52+
main() {
53+
if [[ -d ./bin ]]; then
54+
output_dir="./bin"
55+
elif [[ $PWD == */bin ]]; then
56+
output_dir="$PWD"
57+
else
58+
echo "Error: no ./bin directory found. This script should be ran from a repo root." >&2
59+
return 1
60+
fi
5261

53-
case "${ext}" in
54-
*zip) unzip "${output_path}" -d "${output_dir}" ;;
55-
*) tar xzf "${output_path}" -C "${output_dir}" ;;
56-
esac
62+
download_url="$(get_download_url)"
63+
output_path="${output_dir}/latest-configlet.${ext}"
64+
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
65+
66+
case "${ext}" in
67+
*zip) unzip "${output_path}" -d "${output_dir}" ;;
68+
*) tar xzf "${output_path}" -C "${output_dir}" ;;
69+
esac
70+
71+
rm -f "${output_path}"
72+
}
5773

58-
rm -f "${output_path}"
74+
main

0 commit comments

Comments
 (0)