aboutsummaryrefslogtreecommitdiff
path: root/tezos/install.sh
blob: bcfb39e0834a4da60232b47f41ec5e12b99d67c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/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/