Skip to content

Commit

Permalink
chore: slim install.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
zjp-CN committed Dec 26, 2024
1 parent 095cd6a commit cfd55c0
Showing 1 changed file with 1 addition and 84 deletions.
85 changes: 1 addition & 84 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,4 @@

set -e

# 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-10-12"
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

if ! rustup toolchain install "$toolchain_date" --profile minimal --component rustc-dev,rust-src,llvm-tools-preview; then
printf "%bError: Failed to install toolchain %s.%b\n" "${RED}" "$toolchain_date" "${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}"
cargo install --path rap

0 comments on commit cfd55c0

Please sign in to comment.