runner/helpers/linux-install-tools

74 lines
2.3 KiB
Bash

#!/bin/bash
IFS=$'\n'
for tool in $(jq -cr '.[]' ./toolchain.json); do
TOOL_NAME=$(echo "$tool" | jq -r '.name')
[ -z "$TOOL_NAME" ] && echo "Invalid syntax" && exit 1
echo "=============================="
echo "Installing $TOOL_NAME..."
echo "=============================="
TOOL_MANIFEST_URL=$(echo "$tool" | jq -r '.url')
if [ -z "$TOOL_MANIFEST_URL" ]; then
echo "No manifest found, skipping tool"
continue
fi
TOOL_MANIFEST=$(curl -s $TOOL_MANIFEST_URL)
for version in $(echo "$tool" | jq -r '.versions[]'); do
echo "Installing version $version"
found=false
for check_version in $(echo "$TOOL_MANIFEST" | jq -cr '.[]'); do
if [[ "$(echo "$check_version" | jq -r '.version')" != $version ]]; then
continue
fi
for check_file in $(echo "$check_version" | jq -cr '.files[]'); do
TOOL_PLATFORM=$(echo "$tool" | jq -r '.platform')
TOOL_ARCH=$(echo "$tool" | jq -r '.arch')
TOOL_PLATFORM_VERSION=$(echo "$tool" | jq -r '.platform_version')
if [ -n "$TOOL_PLATFORM" ]; then
[ $TOOL_PLATFORM != $(echo "$check_file" | jq -r '.platform') ] && continue
fi
if [ -n "$TOOL_ARCH" ]; then
[ $TOOL_ARCH != $(echo "$check_file" | jq -r '.arch') ] && continue
fi
if [ -n "$TOOL_PLATFORM_VERSION" ]; then
[ $TOOL_PLATFORM_VERSION != $(echo "$check_file" | jq -r '.platform_version') ] && continue
fi
found=true
FILENAME=$(echo "$check_file" | jq -r '.filename')
DOWNLOAD_URL=$(echo "$check_file" | jq -r '.download_url')
echo "Downloading package from $DOWNLOAD_URL"
curl -sL -o /tmp/build/$FILENAME $DOWNLOAD_URL
if [ $? -ne 0 ]; then
echo "Unable to download package" && exit 1
fi
mkdir -p /tmp/build/$FILENAME-dir
tar -xzf /tmp/build/$FILENAME -C /tmp/build/$FILENAME-dir
if [ $? -ne 0 ]; then
echo "Unable to extract package" && exit 1
fi
rm /tmp/build/$FILENAME
cd /tmp/build/$FILENAME-dir
echo "Setting up package $FILENAME"
bash ./setup.sh
cd ..
rm -rf $FILENAME-dir
break
done
break
done
[ $found == false ] && echo "Unable to find package" && exit 1
done
done
exit 0