-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from lf-lang/specify-version
Add option to specify version + better error handling
- Loading branch information
Showing
2 changed files
with
43 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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') | ||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
@@ -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 | ||
|
||
|
@@ -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') | ||
|
@@ -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 | ||
|
@@ -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 | ||
|