#!/bin/sh set -e # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND # FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. # Add a given path to the start of your $PATH if it doesn't already # exist path_preappend() { if [ -z "$1" ] ; then echo "need something to preappend" ; return ; fi pth="$1"; shift if ! echo "$PATH" | grep -qF "$pth" ; then export PATH="$pth:$PATH" fi } ubuntuOpam() { if grep -qi ubuntu /etc/os-release ; then # Check and see if we have the ppa already, if not let's go ahead and add it if ! apt policy 2>/dev/null | grep -q avsm/ppa ; then sudo add-apt-repository ppa:avsm/ppa sudo apt update fi sudo apt install opam fi } otherOpam() { if ! grep -qi ubuntu /etc/os-release ; then mkdir -p ~/bin checksum="b727fa6c91b8a8d261dbbad3b16687db8364b49f57c934d2d751c8ee7153cb88" curl -L -sS \ "https://github.com/ocaml/opam/releases/download/2.0.10/opam-2.0.10-x86_64-linux" \ > ~/bin/opam if ! sha256sum ~/bin/opam | grep -qi "$checksum" ; then printf "\033[1;31m%s\033[0m\n" "Invalid checksum for ~/bin/opam" exit 1 fi chmod +x ~/bin/opam fi } path_preappend "$HOME/bin" ocaml_version="4.12.1" # overridden later ocaml_switch_name="for_tezos" envvars="$(curl -sS \ 'https://gitlab.com/tezos/tezos/raw/latest-release/scripts/version.sh' \ | sed -e '/^#/d' -e '/^$/d' )" printf "\033[1;33m" printf "Fetched environment vars: \n%s\n" "$envvars" printf "\033[0m" printf "Does this look okay? [Yy]: " read -r resp case $resp in [Yy]*) ;; *) exit 0 ;; esac eval "$(echo "$envvars")" printf "\033[1;31m" echo "**********************************************************************" echo "* Short install script for tezos from source code, loosely based on: *" echo "* https://tezos.gitlab.io/introduction/howtoget.html *" echo "* *" echo "* This script was created on 09-12-2020 and may need some checking *" echo "* over for updates in the future *" echo "* *" printf "* ocaml_version: %-51s *\n" "$ocaml_version" printf "* ocaml_switch_name: %-47s *\n" "$ocaml_switch_name" printf "* recommended_rust_version: %-40s *\n" "$recommended_rust_version" echo "**********************************************************************" echo printf "\033[0m" set -x # Check and see if cargo is in the path, if not let's add it path_preappend "$HOME/.cargo/bin" # Check and see if rustc is available, if not we're going to go ahead # and try to install it from their main source if ! stat "$(which rustc | sed 1q)" >/dev/null 2>&1 ; then echo "Need rustc... installing" curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh fi rustup set profile minimal rustup toolchain install "$recommended_rust_version" rustup default "$recommended_rust_version" . $HOME/.cargo/env if ! [ -x "$(command -v opam)" ] ; then otherOpam ; ubuntuOpam fi err=0 for cmd in unzip ocamlc ; do if ! [ -x "$(command -v $cmd)" ] ; then echo "You need '$cmd' to continue" err=1 fi done if [ $err -ne 0 ] ; then exit 1 fi if ! [ -x "$(command -v opam)" ] ; then printf "\033[1;31m" printf "You need 'opam' installed in order to continue\n" printf "\033[0m" fi if ! [ -d "$HOME/tezos" ] ; then git clone https://gitlab.com/tezos/tezos.git "$HOME/tezos" fi cd "$HOME/tezos" git checkout latest-release make build-deps eval $(opam env) make cp -vf ~/tezos/tezos-* ~/bin/