forked from rapidsai/devcontainers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
160 lines (130 loc) · 5.77 KB
/
install.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
set -e
export CARGO_HOME="/usr/local/cargo";
export RUSTUP_HOME="/usr/local/rustup";
UPDATE_RC="${UPDATERC:-"true"}";
UPDATE_RUST="${UPDATERUST:-"false"}";
RUST_VERSION="${VERSION:-"latest"}";
RUSTUP_PROFILE="${PROFILE:-"minimal"}";
# Ensure we're in this feature's directory during build
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
# install global/common scripts
. ./common/install.sh;
check_nightly_version_formatting() {
local variable_name=$1
local requested_version=${!variable_name}
if [ "${requested_version}" = "none" ]; then return; fi
local version_date=$(echo ${requested_version} | sed -e "s/^nightly-//")
date -d ${version_date} >/dev/null 2>&1
if [ $? != 0 ]; then
echo -e "Invalid ${variable_name} value: ${requested_version}\nNightly version should be in the format nightly-YYYY-MM-DD" >&2
exit 1
fi
if [ $(date -d ${version_date} +%s) -ge $(date +%s) ]; then
echo -e "Invalid ${variable_name} value: ${requested_version}\nNightly version should not exceed current date" >&2
exit 1
fi
}
export DEBIAN_FRONTEND=noninteractive;
gcc_pkgs="gcc g++";
if [[ -n "${GCC_VERSION:-}" ]]; then
gcc_pkgs="gcc-${GCC_VERSION} g++-${GCC_VERSION}";
fi
lldb_pkg="lldb";
if [[ -n "${LLVM_VERSION:-}" ]]; then
lldb_pkg="lldb-${LLVM_VERSION}";
elif type llvm-config >/dev/null 2>&1; then
lldb_pkg="lldb-$(llvm-config --version | cut -d':' -f3 | cut -d'.' -f1)";
fi
# Install curl, lldb, python3-minimal,libpython and rust dependencies if missing
check_packages curl ca-certificates ${gcc_pkgs} libc6-dev libssl-dev gnupg2 gettext-base;
if ! dpkg -s gnupg2 ${lldb_pkg} python3-minimal pkg-config > /dev/null 2>&1; then
apt-get install -y --no-install-recommends ${lldb_pkg} python3-minimal libpython3.? pkg-config;
fi
architecture="${TARGETARCH:-$(dpkg --print-architecture | awk -F'-' '{print $NF}')}";
download_architecture="${architecture}";
case ${download_architecture} in
amd64)
download_architecture="x86_64"
;;
arm64)
download_architecture="aarch64"
;;
*) echo "(!) Architecture ${architecture} not supported."
exit 1
;;
esac
# Install Rust
umask 0002
if ! cat /etc/group | grep -e "^rustlang:" > /dev/null 2>&1; then
groupadd -r rustlang;
fi
# Determine the appropriate non-root user
find_non_root_user;
usermod -a -G rustlang "${USERNAME}";
mkdir -p "${CARGO_HOME}" "${RUSTUP_HOME}";
chown "${USERNAME}:rustlang" "${RUSTUP_HOME}" "${CARGO_HOME}";
chmod g+r+w+s "${RUSTUP_HOME}" "${CARGO_HOME}";
if [ "${RUST_VERSION}" = "none" ] || type rustup > /dev/null 2>&1; then
echo "Rust already installed. Skipping...";
else
if [ "${RUST_VERSION}" != "latest" ] && [ "${RUST_VERSION}" != "lts" ] && [ "${RUST_VERSION}" != "stable" ]; then
# Find version using soft match
if ! type git >/dev/null 2>&1; then
check_packages git;
fi
is_nightly=0;
echo ${RUST_VERSION} | grep -q "nightly" || is_nightly=$?;
if [ $is_nightly = 0 ]; then
check_nightly_version_formatting RUST_VERSION;
else
find_version_from_git_tags RUST_VERSION "https://github.com/rust-lang/rust" "tags/";
fi
default_toolchain_arg="--default-toolchain ${RUST_VERSION}";
fi
echo "Installing Rust...";
# Download and verify rustup sha
mkdir -p /tmp/rustup/target/${download_architecture}-unknown-linux-gnu/release/;
curl -sSL --proto '=https' --tlsv1.2 "https://static.rust-lang.org/rustup/dist/${download_architecture}-unknown-linux-gnu/rustup-init" -o /tmp/rustup/target/${download_architecture}-unknown-linux-gnu/release/rustup-init;
curl -sSL --proto '=https' --tlsv1.2 "https://static.rust-lang.org/rustup/dist/${download_architecture}-unknown-linux-gnu/rustup-init.sha256" -o /tmp/rustup/rustup-init.sha256;
cd /tmp/rustup;
cp /tmp/rustup/target/${download_architecture}-unknown-linux-gnu/release/rustup-init /tmp/rustup/rustup-init
sha256sum -c rustup-init.sha256;
chmod +x target/${download_architecture}-unknown-linux-gnu/release/rustup-init;
target/${download_architecture}-unknown-linux-gnu/release/rustup-init -y --no-modify-path --profile ${RUSTUP_PROFILE} ${default_toolchain_arg};
cd -;
rm -rf /tmp/rustup;
fi
export PATH="${CARGO_HOME}/bin:${PATH}";
if [ "${UPDATE_RUST}" = "true" ]; then
echo "Updating Rust...";
rustup update 2>&1;
fi
echo "Installing common Rust dependencies...";
rustup component add rust-analyzer rust-src rustfmt clippy 2>&1;
# Add CARGO_HOME, RUSTUP_HOME and bin directory into bashrc/zshrc files (unless disabled)
if [ "${UPDATE_RC}" = "true" ]; then
vars_=();
vars_+=('$CARGO_HOME');
vars_+=('$RUSTUP_HOME');
printf -v vars_ '%s,' "${vars_[@]}";
append_etc_zshrc "$(cat .bashrc | envsubst "${vars_%,}")";
append_to_etc_bashrc "$(cat .bashrc | envsubst "${vars_%,}")";
append_to_all_bashrcs "$(cat .bashrc | envsubst "${vars_%,}")";
# export envvars in /etc/profile.d
add_etc_profile_d_script rust "$(cat .bashrc | envsubst "${vars_%,}")";
fi
# Completion
rustup completions bash | tee /usr/share/bash-completion/completions/rustup > /dev/null
rustup completions bash cargo | tee /usr/share/bash-completion/completions/cargo > /dev/null
# Make files writable for rustlang group
chmod -R g+r+w "${RUSTUP_HOME}" "${CARGO_HOME}";
# Clean up
# rm -rf /tmp/*;
rm -rf /var/tmp/*;
rm -rf /var/cache/apt/*;
rm -rf /var/lib/apt/lists/*;