2019-04-29 11:13:33 +03:00
|
|
|
#!/bin/sh
|
2019-04-25 13:33:29 +03:00
|
|
|
|
2024-01-15 22:27:42 +03:00
|
|
|
# Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
2019-04-25 13:33:29 +03:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
#
|
2021-01-08 15:50:15 +03:00
|
|
|
# Daml is an open-source privacy-aware smart contract language.
|
2020-10-08 17:57:43 +03:00
|
|
|
# This script downloads and installs the SDK on Linux and macOS.
|
2019-04-25 13:33:29 +03:00
|
|
|
# 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:
|
2020-10-08 17:57:43 +03:00
|
|
|
# get-daml.sh Download and install the latest SDK release.
|
|
|
|
# get-daml.sh VERSION Download and install given version of SDK.
|
2019-06-03 15:47:27 +03:00
|
|
|
#
|
|
|
|
|
2019-05-14 13:54:05 +03:00
|
|
|
set -eu
|
2020-12-16 20:15:01 +03:00
|
|
|
readonly INSTALL_MINSIZE=1000000
|
2022-01-19 20:15:34 +03:00
|
|
|
if [ -z "${TEMPDIR:-}" ]; then
|
2020-12-16 20:15:01 +03:00
|
|
|
readonly TMPDIR="$(mktemp -d)"
|
|
|
|
else
|
|
|
|
readonly TMPDIR=$TEMPDIR
|
2022-01-19 20:15:34 +03:00
|
|
|
if [ ! -d "$TEMPDIR" ] ; then
|
|
|
|
mkdir $TEMPDIR
|
|
|
|
fi
|
2020-12-16 20:15:01 +03:00
|
|
|
fi
|
2019-10-18 19:02:02 +03:00
|
|
|
|
2020-12-16 20:15:01 +03:00
|
|
|
# Don't remove user specified temporary directory on cleanup.
|
|
|
|
rmTmpDir() {
|
2022-01-19 20:15:34 +03:00
|
|
|
if [ -z "${TEMPDIR:-}" ]; then
|
2020-12-16 20:15:01 +03:00
|
|
|
rm -rf $TMPDIR
|
|
|
|
else
|
2021-01-08 15:50:15 +03:00
|
|
|
echo "You may now remove the Daml installation files from $TEMPDIR"
|
2020-12-16 20:15:01 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
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)"
|
2020-12-16 20:15:01 +03:00
|
|
|
rmTmpDir
|
2019-04-25 13:33:29 +03:00
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
2020-12-16 20:15:01 +03:00
|
|
|
|
|
|
|
#
|
|
|
|
# Check that the temporary directory has enough space for the installation
|
|
|
|
#
|
2022-01-19 20:15:34 +03:00
|
|
|
if [ -x "$(command -v df)" -a -x "$(command -v awk)" ]; then
|
|
|
|
if [ "$(df $TMPDIR | tail -1 | awk '{print $4}')" -lt "$INSTALL_MINSIZE" ]; then
|
2021-01-08 15:50:15 +03:00
|
|
|
echo "Not enough disk space available to extract Daml SDK in $TMPDIR."
|
2020-12-16 20:15:01 +03:00
|
|
|
echo ""
|
|
|
|
echo "You can specify an alternative extraction directory by"
|
|
|
|
echo "setting the TEMPDIR environment variable."
|
|
|
|
exit 1
|
2022-01-19 20:15:34 +03:00
|
|
|
fi
|
2020-12-16 20:15:01 +03:00
|
|
|
fi
|
|
|
|
|
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
|
2021-01-08 15:50:15 +03:00
|
|
|
echo "Missing tools required for Daml installation: $MISSING"
|
2019-04-25 13:33:29 +03:00
|
|
|
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..."
|
2021-01-05 16:31:41 +03:00
|
|
|
readonly VERSION="$(curl -sS https://docs.daml.com/latest)"
|
2019-06-03 15:47:27 +03:00
|
|
|
if [ -z "$VERSION" ] ; then
|
|
|
|
echo "Failed to determine latest SDK version."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "Latest SDK version is $VERSION"
|
|
|
|
else
|
2024-02-07 19:31:07 +03:00
|
|
|
# ignore first v character, so that `v2.0.0` works as well as `2.0.0`
|
|
|
|
readonly VERSION="${1#v}"
|
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
|
|
|
|
|
2024-03-13 15:57:57 +03:00
|
|
|
#
|
|
|
|
# Determine platform suffix
|
|
|
|
#
|
|
|
|
major=$(echo "$VERSION" | awk -F. '{print $1}')
|
|
|
|
minor=$(echo "$VERSION" | awk -F. '{print $2}')
|
|
|
|
|
|
|
|
if [ "$major" -le "1" ]; then
|
|
|
|
platform=
|
|
|
|
elif [ "$major" = "2" ] && [ "$minor" -le "8" ]; then
|
|
|
|
platform=
|
|
|
|
elif [ "$major" = "2" ] && [ "$minor" -ge "9" ]; then
|
|
|
|
case "$OS-$(uname -m)" in
|
|
|
|
macos-arm64)
|
|
|
|
# TODO
|
|
|
|
#platform=-aarch64
|
|
|
|
platform=
|
|
|
|
;;
|
|
|
|
macos-x86_64)
|
|
|
|
platform=
|
|
|
|
;;
|
|
|
|
linux-aarch64)
|
|
|
|
platform=-aarch64
|
|
|
|
;;
|
|
|
|
linux-x86_64)
|
|
|
|
platform=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unsupported architecture: $(uname -m) for $VERSION on $OS."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
elif [ "$major" -ge "3" ]; then
|
|
|
|
case "$OS-$(uname -m)" in
|
|
|
|
macos-arm64)
|
|
|
|
# TODO
|
|
|
|
#platform=-aarch64
|
|
|
|
platform=-x86_64
|
|
|
|
;;
|
|
|
|
macos-x86_64)
|
|
|
|
# TODO
|
|
|
|
platform=-x86_64
|
|
|
|
;;
|
|
|
|
linux-aarch64)
|
|
|
|
platform=-aarch64
|
|
|
|
;;
|
|
|
|
linux-x86_64)
|
|
|
|
platform=-x86_64
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unsupported architecture: $(uname -m) for $VERSION on $OS."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2019-05-14 13:54:05 +03:00
|
|
|
#
|
|
|
|
# Download SDK tarball
|
|
|
|
#
|
2023-10-11 19:14:56 +03:00
|
|
|
# Can't assume jq
|
|
|
|
release_id=$(curl --silent \
|
|
|
|
--location \
|
|
|
|
https://api.github.com/repos/digital-asset/daml/releases/tags/v$VERSION \
|
|
|
|
| grep '"id":' \
|
|
|
|
| head -1 \
|
2023-10-16 11:47:46 +03:00
|
|
|
| sed 's|.*: \([0-9]*\),|\1|')
|
2023-10-11 19:14:56 +03:00
|
|
|
URL=$(curl --silent \
|
|
|
|
--location \
|
|
|
|
https://api.github.com/repos/digital-asset/daml/releases/$release_id/assets \
|
|
|
|
| grep browser_download_url \
|
2024-03-13 15:57:57 +03:00
|
|
|
| grep "daml-sdk-.*-$OS$platform.tar.gz\"" \
|
2023-10-11 19:14:56 +03:00
|
|
|
| sed 's|.*: "\(https://[^"]*\)"|\1|')
|
|
|
|
readonly TARBALL=$(basename $URL)
|
|
|
|
sdk_version=$(echo $TARBALL | sed 's|daml-sdk-\(.*\)-[^-]*.tar.gz|\1|')
|
|
|
|
|
|
|
|
echo "$(tput setaf 3)Downloading SDK $sdk_version for Daml $VERSION. This may take a while.$(tput sgr 0)"
|
2022-01-19 20:15:34 +03:00
|
|
|
curl -SLf $URL --output $TMPDIR/$TARBALL --progress-bar
|
|
|
|
if [ ! -f $TMPDIR/$TARBALL ] ; then
|
2019-05-14 13:54:05 +03:00
|
|
|
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
|
2022-01-19 20:15:34 +03:00
|
|
|
echo "Removing existing installation: $DAML_HOME"
|
2019-04-29 11:13:33 +03:00
|
|
|
chmod -R u+w $DAML_HOME
|
|
|
|
rm -rf $DAML_HOME
|
|
|
|
fi
|
|
|
|
|
2022-01-19 20:15:34 +03:00
|
|
|
#
|
|
|
|
# Remove existing cache.
|
|
|
|
#
|
|
|
|
readonly DAML_CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/daml"
|
|
|
|
if [ -d $DAML_CACHE ] ; then
|
|
|
|
echo "Removing existing cache: $DAML_CACHE"
|
|
|
|
rm -rf $DAML_CACHE
|
|
|
|
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
|
2022-01-19 20:15:34 +03:00
|
|
|
tar xzf $TMPDIR/$TARBALL -C $TMPDIR/sdk --strip-components 1
|
2019-04-25 13:33:29 +03:00
|
|
|
$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
|
2021-01-08 15:50:15 +03:00
|
|
|
echo "$(tput setaf 3)Successfully installed Daml.$(tput sgr 0)"
|
2020-12-16 20:15:01 +03:00
|
|
|
rmTmpDir
|