mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-17 15:57:21 +03:00
Better error handling in get-daml.sh (#1121)
* Better error handling in get-daml.sh * Use set -eu * Review suggestions * ORIGDIR is unused.
This commit is contained in:
parent
186cf14729
commit
f72fdf3552
@ -4,21 +4,24 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#
|
||||
# DAML is an open-source privacy-aware smart contract language.
|
||||
# This script downloads and installs the DAML SDK on Linux and macOS.
|
||||
# This will overwrite any existing installation in ~/.daml
|
||||
# For more information please visit https://daml.com/ and https://docs.daml.com/
|
||||
#
|
||||
|
||||
readonly ORIGDIR="$(pwd)"
|
||||
cleanup () {
|
||||
set -eu
|
||||
cleanup() {
|
||||
echo "$(tput setaf 3)FAILED TO INSTALL!$(tput sgr 0)"
|
||||
cd $ORIGDIR
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
readonly TMPDIR="$(mktemp -d)"
|
||||
cd $TMPDIR
|
||||
|
||||
#
|
||||
# Check if curl and tar are available.
|
||||
#
|
||||
if [ -x "$(command -v curl)" ]; then
|
||||
MISSING=""
|
||||
else
|
||||
@ -36,14 +39,20 @@ if [ -n "$MISSING" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#
|
||||
# Determine latest SDK version
|
||||
#
|
||||
echo "Determining latest SDK version..."
|
||||
readonly VERSION="$(curl -sS https://github.com/digital-asset/daml/releases/latest | sed 's/^.*github.com\/digital-asset\/daml\/releases\/tag\/v//' | sed 's/".*$//')"
|
||||
if [ -z "$VERSION" ] ; then
|
||||
echo "Failed to determine latest SDK version."
|
||||
exit 1
|
||||
fi
|
||||
echo "Latest SDK version is $VERSION."
|
||||
|
||||
|
||||
echo "Determining latest DAML version..."
|
||||
readonly VERSION="$(curl -s https://github.com/digital-asset/daml/releases/latest | sed 's/^.*github.com\/digital-asset\/daml\/releases\/tag\/v//' | sed 's/".*$//')"
|
||||
echo "Latest DAML version is $VERSION."
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Determine operating system.
|
||||
#
|
||||
readonly OSNAME="$(uname -s)"
|
||||
if [ "$OSNAME" = "Linux" ] ; then
|
||||
OS="linux"
|
||||
@ -55,12 +64,22 @@ else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#
|
||||
# Download SDK tarball
|
||||
#
|
||||
readonly TARBALL="daml-sdk-$VERSION-$OS.tar.gz"
|
||||
readonly URL="https://github.com/digital-asset/daml/releases/download/v$VERSION/$TARBALL"
|
||||
|
||||
echo "$(tput setaf 3)Downloading latest DAML SDK. This may take a while.$(tput sgr 0)"
|
||||
curl -L $URL --output $TARBALL --progress-bar
|
||||
if [ ! -f $TARBALL ] ; then
|
||||
echo "Failed to download SDK tarball."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#
|
||||
# Remove existing installation.
|
||||
#
|
||||
readonly DAML_HOME="$HOME/.daml"
|
||||
if [ -d $DAML_HOME ] ; then
|
||||
echo "Removing existing installation."
|
||||
@ -68,12 +87,20 @@ if [ -d $DAML_HOME ] ; then
|
||||
rm -rf $DAML_HOME
|
||||
fi
|
||||
|
||||
#
|
||||
# Extract and install SDK tarball.
|
||||
#
|
||||
echo "Extracting SDK release tarball."
|
||||
mkdir -p $TMPDIR/sdk
|
||||
tar xzf $TARBALL -C $TMPDIR/sdk --strip-components 1
|
||||
$TMPDIR/sdk/install.sh
|
||||
if [ ! -d $DAML_HOME ] ; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd $ORIGDIR
|
||||
#
|
||||
# Done.
|
||||
#
|
||||
trap - EXIT
|
||||
echo "$(tput setaf 3)Successfully installed DAML.$(tput sgr 0)"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user