2019-04-29 11:13:33 +03:00
#!/bin/sh
2019-04-25 13:33:29 +03:00
2020-01-02 23:21:13 +03:00
# Copyright (c) 2020 The DAML Authors. All rights reserved.
2019-04-25 13:33:29 +03:00
# SPDX-License-Identifier: Apache-2.0
#
2019-05-14 13:54:05 +03:00
# DAML is an open-source privacy-aware smart contract language.
2019-04-25 13:33:29 +03:00
# This script downloads and installs the DAML SDK on Linux and macOS.
# This will overwrite any existing installation in ~/.daml
2019-05-14 13:54:05 +03:00
# For more information please visit https://daml.com/ and https://docs.daml.com/
2019-04-25 13:33:29 +03:00
#
2019-06-03 15:47:27 +03:00
#
# USAGE:
# get-daml.sh Download and install the latest DAML SDK release.
# get-daml.sh VERSION Download and install given version of DAML SDK.
#
2019-05-14 13:54:05 +03:00
set -eu
2019-10-18 19:02:02 +03:00
readonly SWD = " $PWD "
readonly TMPDIR = " $( mktemp -d) "
cd $TMPDIR
2019-05-14 13:54:05 +03:00
cleanup( ) {
2019-04-25 13:33:29 +03:00
echo " $( tput setaf 3) FAILED TO INSTALL! $( tput sgr 0) "
2019-10-18 19:02:02 +03:00
cd $SWD
rm -rf $TMPDIR
2019-04-25 13:33:29 +03:00
}
trap cleanup EXIT
2019-05-14 13:54:05 +03:00
#
2019-04-25 13:33:29 +03:00
# Check if curl and tar are available.
2019-05-14 13:54:05 +03:00
#
2019-04-25 13:33:29 +03:00
if [ -x " $( command -v curl) " ] ; then
MISSING = ""
else
MISSING = "curl"
fi
if [ -x " $( command -v tar) " ] ; then
MISSING = " $MISSING "
elif [ -n " $MISSING " ] ; then
MISSING = " $MISSING , tar "
else
MISSING = "tar"
fi
if [ -n " $MISSING " ] ; then
echo " Missing tools required for DAML installation: $MISSING "
exit 1
fi
2019-05-14 13:54:05 +03:00
#
2019-06-03 15:47:27 +03:00
# Determine SDK version
2019-05-14 13:54:05 +03:00
#
2019-06-03 15:47:27 +03:00
if [ -z " ${ 1 :- } " ] ; then
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 "
else
readonly VERSION = " $1 "
2019-05-14 13:54:05 +03:00
fi
2019-04-25 13:33:29 +03:00
2019-05-14 13:54:05 +03:00
#
# Determine operating system.
#
2019-04-29 11:13:33 +03:00
readonly OSNAME = " $( uname -s) "
if [ " $OSNAME " = "Linux" ] ; then
2019-04-25 13:33:29 +03:00
OS = "linux"
2019-04-29 11:13:33 +03:00
elif [ " $OSNAME " = "Darwin" ] ; then
2019-04-25 13:33:29 +03:00
OS = "macos"
else
echo "Operating system not supported:"
2019-04-29 11:13:33 +03:00
echo " OSNAME = $OSNAME "
2019-04-25 13:33:29 +03:00
exit 1
fi
2019-05-14 13:54:05 +03:00
#
# Download SDK tarball
#
2019-04-25 13:33:29 +03:00
readonly TARBALL = " daml-sdk- $VERSION - $OS .tar.gz "
readonly URL = " https://github.com/digital-asset/daml/releases/download/v $VERSION / $TARBALL "
2019-06-04 10:31:25 +03:00
echo " $( tput setaf 3) Downloading DAML SDK $VERSION . This may take a while. $( tput sgr 0) "
2019-06-03 15:47:27 +03:00
curl -SLf $URL --output $TARBALL --progress-bar
2019-05-14 13:54:05 +03:00
if [ ! -f $TARBALL ] ; then
echo "Failed to download SDK tarball."
exit 1
fi
2019-04-25 13:33:29 +03:00
2019-05-14 13:54:05 +03:00
#
# Remove existing installation.
#
2019-04-29 11:13:33 +03:00
readonly DAML_HOME = " $HOME /.daml "
if [ -d $DAML_HOME ] ; then
echo "Removing existing installation."
chmod -R u+w $DAML_HOME
rm -rf $DAML_HOME
fi
2019-05-14 13:54:05 +03:00
#
# Extract and install SDK tarball.
#
2019-04-25 13:33:29 +03:00
echo "Extracting SDK release tarball."
mkdir -p $TMPDIR /sdk
tar xzf $TARBALL -C $TMPDIR /sdk --strip-components 1
$TMPDIR /sdk/install.sh
2019-05-14 13:54:05 +03:00
if [ ! -d $DAML_HOME ] ; then
exit 1
fi
2019-04-25 13:33:29 +03:00
2019-05-14 13:54:05 +03:00
#
# Done.
#
2019-04-25 13:33:29 +03:00
trap - EXIT
echo " $( tput setaf 3) Successfully installed DAML. $( tput sgr 0) "
2019-10-18 19:02:02 +03:00
cd $SWD
rm -rf $TMPDIR