Skip to content

Commit

Permalink
Merge pull request #26 from lf-lang/specify-version
Browse files Browse the repository at this point in the history
Add option to specify version + better error handling
  • Loading branch information
lhstrh authored Jan 31, 2025
2 parents 54977a0 + 32688ad commit 6c46081
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ jobs:
lff --version
which epoch
shell: bash
- name: Install specific version of cli
run: |
bash install.sh cli v0.8.1
lfc --version
lfd --version
lff --version
shell: bash
59 changes: 36 additions & 23 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set -eo pipefail
# Author: [email protected]
# License: BSD-2

version="0.1.0-beta-1"
tools=("cli" "epoch")
selected=()
timestamp=$(date '+%Y%m%d%H%M%S')
Expand All @@ -21,7 +20,7 @@ if [[ "$OSTYPE" == "linux"* ]]; then
elif [[ "$OSTYPE" == "darwin"* ]]; then
os="MacOS"
else
echo "Unsupported operating system: $OSTYPE"
echo "Error: Unsupported operating system: $OSTYPE" >&2
exit 1
fi

Expand Down Expand Up @@ -104,43 +103,51 @@ case $i in
if [[ -z $kind ]]; then
kind="nightly"
else
echo "You can only use one qualifier; choose 'stable' or 'nightly'."
echo "Error: You can only use one qualifier; choose 'stable' or 'nightly'" >&2
exit 1
fi
;;
stable)
if [[ -z $kind ]]; then
kind="stable"
kind="latest"
else
echo "You can only use one qualifier; choose 'stable' or 'nightly'."
echo "Error: You can only use one qualifier; choose 'stable' or 'nightly'"
exit 1
fi
;;
v[0-9]*.[0-9]*.[0-9]*|[0-9]*.[0-9]*.[0-9]*)
if [[ -n $kind ]]; then
echo "Error: Either use a version number or a qualifier ('stable' or 'nightly'), not both" >&2
exit 1
fi
version=${i#v}
supported="^(0\.([5-9][0-9]*|[1-9][0-9]+)\.[0-9]+)|(([1-9][0-9]*)\.[0-9]+\.[0-9]+)$"
if ! [[ $version =~ $supported ]]; then
echo "Error: Only versions 0.5.0 and up can be installed using this script" >&2
exit 1
fi
;;
*)
echo "Unknown option: $i"
echo "Error: Unknown option: $i"
exit 1
;;
esac
done

# Use stable by default
if [[ -z $kind ]]; then
kind="stable"
fi

if [[ "$kind" == "nightly" ]]; then
suffix="tags/nightly"
# Either use the supplied version, nightly, or latest.
if [[ -n $version ]]; then
suffix="tags/v${version}"
else
suffix="latest"
if [[ "$kind" == "nightly" ]]; then
suffix="tags/nightly"
else
suffix="latest"
fi
fi

# Use ~/.local default prefix
if [[ -z $prefix ]]; then
if [[ "$os" == "MacOS" ]]; then
prefix=/usr/local
else
prefix=~/.local
fi
prefix=~/.local
fi

# Use /tmp as the default temporary storage
Expand All @@ -155,7 +162,7 @@ bin="$prefix/bin"

# Require a tool to be selected
if [ ${#selected[@]} -eq 0 ]; then
echo "Please specify a tool to install. To install all tools, use 'all'."
echo "Error: Please specify a tool to install. To install all tools, use 'all'." >&2
exit 1
fi

Expand All @@ -176,7 +183,10 @@ for tool in "${selected[@]}"; do
cli)
description="CLI tools"
rel="https://api.github.com/repos/lf-lang/lingua-franca/releases/$suffix"
kvp=$(curl -L -H "Accept: application/vnd.github+json" $rel 2>&1 | grep download_url | grep $os-$arch.tar.gz)
if ! kvp=$(curl -L -s -f -H "Accept: application/vnd.github+json" $rel 2>&1 | grep download_url | grep $os-$arch.tar.gz); then
echo "Error: Failed to fetch data from $rel" >&2
exit 1
fi
arr=($kvp)
url="${arr[1]//\"/}"
file=$(echo $url | grep -o '[^/]*\.tar.gz')
Expand All @@ -190,7 +200,10 @@ for tool in "${selected[@]}"; do
os_abbr="mac"
fi
rel="https://api.github.com/repos/lf-lang/epoch/releases/$suffix"
kvp=$(curl -L -H "Accept: application/vnd.github+json" $rel 2>&1 | grep "download_url" | grep "$arch" | grep "$os_abbr")
if ! kvp=$(curl -L -H "Accept: application/vnd.github+json" $rel 2>&1 | grep "download_url" | grep "$arch" | grep "$os_abbr"); then
echo "Error: Failed to fetch data from $rel" >&2
exit 1
fi
arr=($kvp)
url="${arr[1]//\"/}"
if [[ "$os" == "MacOS" ]]; then
Expand All @@ -205,7 +218,7 @@ for tool in "${selected[@]}"; do
;;
esac

echo "> Installing the latest $kind release of $description..."
echo "> Installing the ${kind:-$version} release for $os-$arch of $description..."
echo ""

# Download
Expand Down

0 comments on commit 6c46081

Please sign in to comment.