From c02d4a79e81e993f42ad838817f8d156c2fe9a18 Mon Sep 17 00:00:00 2001 From: Alejo Salles Date: Tue, 7 May 2024 04:26:09 -0400 Subject: [PATCH] remove suaveup root password requirement (#242) * remove suaveup root password requirement * add suave-geth to PATH --- suave/suaveup/suaveup | 53 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/suave/suaveup/suaveup b/suave/suaveup/suaveup index 25e996897..12ea65ed6 100755 --- a/suave/suaveup/suaveup +++ b/suave/suaveup/suaveup @@ -56,21 +56,54 @@ else exit 1 fi -# use tar to extract the downloaded file and move it to /usr/local/bin +# use tar to extract the downloaded file and move it to the SUAVE_BIN_DIR directory echo "Extracting suave-geth_${VERSION}_${ARCH_STRING}.zip ..." unzip -qq -o suave-geth_${VERSION}_${ARCH_STRING}.zip chmod +x suave-geth -if [ ! -d "/usr/local" ]; then - sudo mkdir /usr/local -fi -if [ ! -d "/usr/local/bin" ]; then - sudo mkdir /usr/local/bin -fi +BASE_DIR="${XDG_CONFIG_HOME:-$HOME}" +SUAVE_DIR="${SUAVE_DIR-"$BASE_DIR/.suave"}" +SUAVE_BIN_DIR="$SUAVE_DIR/bin" -echo "Moving suave-geth to /usr/local/bin ..." -sudo mv suave-geth /usr/local/bin/suave-geth +mkdir -p "$SUAVE_BIN_DIR" + +echo "Moving suave-geth to ${SUAVE_BIN_DIR}..." +mv suave-geth $SUAVE_BIN_DIR/suave-geth rm suave-geth_${VERSION}_${ARCH_STRING}.zip +# Pick the right shell profile file +case $SHELL in +*/zsh) + PROFILE="${ZDOTDIR-"$HOME"}/.zshenv" + PREF_SHELL=zsh + ;; +*/bash) + PROFILE=$HOME/.bashrc + PREF_SHELL=bash + ;; +*/fish) + PROFILE=$HOME/.config/fish/config.fish + PREF_SHELL=fish + ;; +*/ash) + PROFILE=$HOME/.profile + PREF_SHELL=ash + ;; +*) + echo "suaveup: could not detect shell, manually add ${SUAVE_BIN_DIR} to your PATH." + exit 1 +esac + +# Add suaveup if it isn't already in PATH. +if [[ ":$PATH:" != *":${SUAVE_BIN_DIR}:"* ]]; then + # Add the suaveup directory to the path and ensure the old PATH variables remain. + # If the shell is fish, echo fish_add_path instead of export. + if [[ "$PREF_SHELL" == "fish" ]]; then + echo >> "$PROFILE" && echo "fish_add_path -a $SUAVE_BIN_DIR" >> "$PROFILE" + else + echo >> "$PROFILE" && echo "export PATH=\"\$PATH:$SUAVE_BIN_DIR\"" >> "$PROFILE" + fi +fi + echo "Installed suave-geth $VERSION ✅ " -echo "You can confirm by running 'suave-geth version'" +echo "Run 'source $PROFILE' or start a new terminal session to add suave-geth to your PATH, then check the installation by running 'suave-geth version'"