forked from Artisan-Lab/RAP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·81 lines (71 loc) · 3.16 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
#!/bin/bash
# Define color variables
BLUE='\033[0;34m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
cd rap && cargo clean
case "$SHELL" in
*zsh)
printf "Detecting shell context success: running on %bZsh%b.\n" "${BLUE}" "${NC}"
export SHELL_CONFIG=~/.zshrc
;;
*bash)
printf "Detecting shell context success: running on %bBash%b.\n" "${BLUE}" "${NC}"
export SHELL_CONFIG=~/.bashrc
;;
*)
printf "%bDetecting shell context failed.%b\n" "${RED}" "${NC}"
exit 1
;;
esac
# Set the library path to be added
#LIBRARY_PATH="$HOME/.rustup/toolchains/nightly-2023-10-05-x86_64-unknown-linux-gnu/lib"
toolchain_date="nightly-2024-06-30"
toolchain_file="rust-toolchain.toml"
if [ ! -f "$toolchain_file" ]; then
printf "%bError: %s does not exist.%b\n" "${RED}" "$toolchain_file" "${NC}"
exit 1
fi
os_type=$(uname -s)
arch_type=$(uname -m)
if [ "$os_type" = "Linux" ]; then
# Update the channel field in rust-toolchain.toml
toolchain="$toolchain_date-x86_64-unknown-linux-gnu"
toolchain_lib="$HOME/.rustup/toolchains/$toolchain/lib"
printf "%bDetected OS: Linux. Setting toolchain to %s%b\n" "${BLUE}" "$toolchain" "${NC}"
sed -i.bak "s/^channel = \".*\"/channel = \"$toolchain\"/" "$toolchain_file"
if ! grep -q "LD_LIBRARY_PATH.*$toolchain_lib" "$SHELL_CONFIG"; then
if grep -q "LD_LIBRARY_PATH" "$SHELL_CONFIG"; then
export LD_LIBRARY_PATH="$toolchain_lib:$LD_LIBRARY_PATH"
sed -i '/LD_LIBRARY_PATH/d' "$SHELL_CONFIG"
printf "%bOld LD_LIBRARY_PATH definition has been removed from %s.%b\n" "${GREEN}" "$SHELL_CONFIG" "${NC}"
else
export LD_LIBRARY_PATH="$toolchain_lib"
fi
echo "export LD_LIBRARY_PATH=\"${LD_LIBRARY_PATH}\"" >> "$SHELL_CONFIG"
printf "%bEnvironment variables have been successfully written to %s.%b\n" "${GREEN}" "$SHELL_CONFIG" "${NC}"
fi
elif [ "$os_type" = "Darwin" ]; then
if [ "$arch_type" = "x86_64" ]; then
toolchain="$toolchain_date-x86_64-apple-darwin"
toolchain_lib="$HOME/.rustup/toolchain/$toolchain/lib"
else
toolchain="$toolchain_date-aarch64-apple-darwin"
toolchain_lib="$HOME/.rustup/toolchain/$toolchain/lib"
fi
printf "%bDetected OS: macOS. Setting toolchain to %s%b\n" "${BLUE}" "$toolchain" "${NC}"
sed -i.bak "s/^channel = \".*\"/channel = \"$toolchain\"/" "$toolchain_file"
if ! grep -q "DYLD_LIBRARY_PATH.*$toolchain_lib" "$SHELL_CONFIG"; then
if grep -q "DYLD_LIBRARY_PATH" "$SHELL_CONFIG"; then
export DYLD_LIBRARY_PATH="$toolchain_lib:$DYLD_LIBRARY_PATH"
sed -i '/DYLD_LIBRARY_PATH/d' "$SHELL_CONFIG"
printf "%bOld DYLD_LIBRARY_PATH definition has been removed from %s.%b\n" "${GREEN}" "$SHELL_CONFIG" "${NC}"
else
export DYLD_LIBRARY_PATH="$toolchain_lib"
fi
echo "export DYLD_LIBRARY_PATH=\"${DYLD_LIBRARY_PATH}\"" >> "$SHELL_CONFIG"
printf "%bEnvironment variables have been successfully written to %s.%b\n" "${GREEN}" "$SHELL_CONFIG" "${NC}"
fi
fi
cargo install --path .
printf "%bTo apply the changes, you may need to run: %bsource %s%b\n" "${GREEN}" "${BLUE}" "$SHELL_CONFIG" "${NC}"