Skip to content

Commit eca4a0c

Browse files
committed
Install on macosx working
1 parent aff673d commit eca4a0c

File tree

3 files changed

+78
-30
lines changed

3 files changed

+78
-30
lines changed

bin/download

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@ set -euo pipefail
44

55
current_script_path=${BASH_SOURCE[0]}
66
plugin_dir=$(dirname "$(dirname "$current_script_path")")
7+
sub_toolname=$(basename "$plugin_dir")
78

89
# shellcheck source=../lib/utils.bash
910
source "${plugin_dir}/lib/utils.bash"
1011

1112
mkdir -p "$ASDF_DOWNLOAD_PATH"
1213

13-
# TODO: Adapt this to proper extension and adapt extracting strategy.
14-
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz"
14+
# TODO:: remove this?
15+
release_file="${ASDF_DOWNLOAD_PATH}/${sub_toolname}-${ASDF_INSTALL_VERSION}"
1516

16-
# Download tar.gz file to the download directory
17-
download_release "$ASDF_INSTALL_VERSION" "$release_file"
18-
19-
# Extract contents of tar.gz file into the download directory
20-
tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file"
21-
22-
# Remove the tar.gz file since we don't need to keep it
23-
rm "$release_file"
17+
download_release "$sub_toolname" "$ASDF_INSTALL_VERSION" "$release_file"

bin/install

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ set -euo pipefail
44

55
current_script_path=${BASH_SOURCE[0]}
66
plugin_dir=$(dirname "$(dirname "$current_script_path")")
7-
toolname=$(basename "$plugin_dir")
7+
sub_toolname=$(basename "$plugin_dir")
88

99
# shellcheck source=../lib/utils.bash
1010
source "${plugin_dir}/lib/utils.bash"
1111

12-
install_version "${toolname}" "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
12+
install_version "$sub_toolname" "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"

lib/utils.bash

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ TOOL_TEST="clang-format"
1010
USE_KERNEL=
1111
USE_ARCH=
1212
USE_PLATFORM=
13+
YES_REGEX='^[Yy](E|e)?(S|s)?$'
1314

1415
fail() {
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+
3035
curl_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

5459
validate_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

100105
download_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

112132
install_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

Comments
 (0)