-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev_setup.sh
executable file
·127 lines (109 loc) · 3.13 KB
/
dev_setup.sh
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
#!/bin/bash
# Copyright (c) The Libra Core Contributors
# SPDX-License-Identifier: Apache-2.0
# This script sets up the environment for the Libra build by installing necessary dependencies.
#
# Usage ./dev_setup.sh <options>
# v - verbose, print all statements
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$SCRIPT_PATH/.."
set -e
OPTIONS="$1"
if [[ $OPTIONS == *"v"* ]]; then
set -x
fi
if [ ! -f Cargo.toml ]; then
echo "Unknown location. Please run this from the libra repository. Abort."
exit 1
fi
PACKAGE_MANAGER=
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if which yum &>/dev/null; then
PACKAGE_MANAGER="yum"
elif which apt-get &>/dev/null; then
PACKAGE_MANAGER="apt-get"
elif which pacman &>/dev/null; then
PACKAGE_MANAGER="pacman"
else
echo "Unable to find supported package manager (yum, apt-get, or pacman). Abort"
exit 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
if which brew &>/dev/null; then
PACKAGE_MANAGER="brew"
else
echo "Missing package manager Homebrew (https://brew.sh/). Abort"
exit 1
fi
else
echo "Unknown OS. Abort."
exit 1
fi
cat <<EOF
Welcome to Libra!
This script will download and install the necessary dependencies needed to
build Libra Core. This includes:
* Rust (and the necessary components, e.g. rust-fmt, clippy)
* CMake
* Clang
If you'd prefer to install these dependencies yourself, please exit this script
now with Ctrl-C.
EOF
printf "Proceed with installing necessary dependencies? (y/N) > "
read -e input
if [[ "$input" != "y"* ]]; then
echo "Exiting..."
exit 0
fi
# Install Rust
echo "Installing Rust......"
if rustup --version &>/dev/null; then
echo "Rust is already installed"
else
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable
CARGO_ENV="$HOME/.cargo/env"
source "$CARGO_ENV"
fi
# Run update in order to download and install the checked in toolchain
rustup update
# Add all the components that we need
rustup component add rustfmt
rustup component add clippy
if [[ $"$PACKAGE_MANAGER" == "apt-get" ]]; then
echo "Updating apt-get......"
sudo apt-get update
fi
echo "Installing CMake......"
if which cmake &>/dev/null; then
echo "CMake is already installed"
else
if [[ "$PACKAGE_MANAGER" == "yum" ]]; then
sudo yum install cmake -y
elif [[ "$PACKAGE_MANAGER" == "apt-get" ]]; then
sudo apt-get install cmake -y
elif [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
sudo pacman -Syu cmake --noconfirm
elif [[ "$PACKAGE_MANAGER" == "brew" ]]; then
brew install cmake
fi
fi
echo "Installing Clang......"
if which clang &>/dev/null; then
echo "Clang is already installed"
else
if [[ "$PACKAGE_MANAGER" == "yum" ]]; then
sudo yum install clang -y
elif [[ "$PACKAGE_MANAGER" == "apt-get" ]]; then
sudo apt-get install clang -y
elif [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
sudo pacman -Syu clang --noconfirm
elif [[ "$PACKAGE_MANAGER" == "brew" ]]; then
brew install llvm
fi
fi
cat <<EOF
Finished installing all dependencies.
You should now be able to build the project by running:
source $HOME/.cargo/env
cargo build
EOF