@@ -10,6 +10,7 @@ TOOL_TEST="clang-format"
1010USE_KERNEL=
1111USE_ARCH=
1212USE_PLATFORM=
13+ YES_REGEX=' ^[Yy](E|e)?(S|s)?$'
1314
1415fail () {
1516 echo -e " asdf-$TOOL_NAME : $* "
@@ -27,6 +28,10 @@ validate_deps() {
2728 done
2829}
2930
31+ log () {
32+ echo -e " asdf-$TOOL_NAME : $* "
33+ }
34+
3035curl_opts=(-fsSL)
3136
3237# NOTE: You might want to remove this if clang-tools-static is not hosted on GitHub releases.
@@ -53,7 +58,7 @@ fetch_all_assets() {
5358
5459validate_platform () {
5560
56- if [ -n " ${ USE_PLATFORM} " ]; then
61+ if [ -n " $USE_PLATFORM " ]; then
5762 return
5863 fi
5964
@@ -98,38 +103,87 @@ list_all_versions() {
98103}
99104
100105download_release () {
101- local version filename url
102- version=" $1 "
103- filename=" $2 "
106+ local toolname version filename url
107+ toolname=" $1 "
108+ version=" $2 "
109+ filename=" $3 "
110+
111+ validate_platform
112+
113+ # TODO: split output without piping to awk
114+ url=$( fetch_all_assets |
115+ grep " ^${toolname} -${version} _${USE_PLATFORM} \s" |
116+ awk ' {print $2}' )
117+
118+ (
119+ cd " ${ASDF_DOWNLOAD_PATH} " || exit 1
104120
105- # TODO: Adapt the release URL convention for clang-tools-static
106- url=" $GH_REPO_URL /archive/v${version} .tar.gz"
121+ echo " * Downloading $toolname release $version ..."
122+ # curl "${curl_opts[@]}" -o "$filename" "$url" || fail "Could not download $url"
123+ curl " ${curl_opts[@]} " -O " $url " || fail " Could not download $url "
124+ # TODO: range request ('-C -') does not seem to work
107125
108- echo " * Downloading $TOOL_NAME release $version ..."
109- curl " ${curl_opts[@]} " -o " $filename " -C - " $url " || fail " Could not download $url "
126+ # Download checksum
127+ # curl "${curl_opts[@]}" -o "${filename}.sha512sum" "${url}.sha512sum" || fail "Could not download $url"
128+ curl " ${curl_opts[@]} " -O " ${url} .sha512sum" || fail " Could not download $url "
129+ )
110130}
111131
112132install_version () {
113- local install_type=" $1 "
114- local version=" $2 "
115- local install_path=" $3 "
133+ local toolname=" $1 "
134+ local install_type=" $2 "
135+ local version=" $3 "
136+ local install_path=" $4 "
137+
138+ validate_platform
116139
117140 if [ " $install_type " != " version" ]; then
118141 fail " asdf-$TOOL_NAME supports release installs only"
119142 fi
120143
144+ if command -v sha512sum > /dev/null; then
145+ (
146+ log " Checking sha512 sum..."
147+ cd " ${ASDF_DOWNLOAD_PATH} " || exit 1
148+ sha512sum -c ./* .sha512sum
149+ )
150+ else
151+ log " WARNING: sha512sum program not found - unable to checksum. Proceed with caution."
152+ fi
153+
121154 (
122- mkdir -p " $install_path "
123- cp -r " $ASDF_DOWNLOAD_PATH " /* " $install_path "
155+ local asset_path full_tool_cmd tool_cmd
156+ asset_path=" $install_path /assets"
157+
158+ mkdir -p " $asset_path "
159+ cp -r " $ASDF_DOWNLOAD_PATH " /* " $asset_path "
160+
161+ # TODO: detect this instead of hard-coding in case the format changes?
162+ full_tool_cmd=${toolname} -${version} _${USE_PLATFORM}
163+ tool_cmd=" $( echo " $toolname " | cut -d' ' -f1) "
164+
165+ chmod +x " ${asset_path} /${full_tool_cmd} "
166+
167+ mkdir -p " ${install_path} /bin" || true
168+ ln -s " ${asset_path} /${full_tool_cmd} " " $install_path /bin/$tool_cmd "
169+
170+ if [ " $USE_KERNEL " == " macosx" ]; then
171+ log " $toolname needs to be un-quarantined to run:\n\n"
172+ echo -e " xattr -dr com.apple.quarantine \" ${asset_path} /${full_tool_cmd} \" "
173+ echo -e -n " \n\nProceed? [y/N] "
174+ read -r reply
175+ if [[ $reply =~ $YES_REGEX ]]; then
176+ xattr -dr com.apple.quarantine " ${asset_path} /${full_tool_cmd} "
177+ else
178+ exit 1
179+ fi
180+ fi
124181
125- # TODO: Asert clang-tools-static executable exists.
126- local tool_cmd
127- tool_cmd=" $( echo " $TOOL_TEST " | cut -d' ' -f1) "
128182 test -x " $install_path /bin/$tool_cmd " || fail " Expected $install_path /bin/$tool_cmd to be executable."
129183
130- echo " $TOOL_NAME $version installation was successful!"
184+ echo " $toolname $version installation was successful!"
131185 ) || (
132186 rm -rf " $install_path "
133- fail " An error ocurred while installing $TOOL_NAME $version ."
187+ fail " An error ocurred while installing $toolname $version ."
134188 )
135189}
0 commit comments