Skip to content

Commit

Permalink
chore: Add some progress reporting to installation script (#537)
Browse files Browse the repository at this point in the history
* Update script

* Force symlink

* Create dir if doest exist

* Apply automatic changes

---------

Co-authored-by: nahsi <[email protected]>
  • Loading branch information
nahsi and nahsi authored Oct 10, 2023
1 parent e8ce0b1 commit 06b0d50
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 77 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ fluence update --help

### Installing manually

- download fluence archive for your platfrom from
[latest release](https://github.com/fluencelabs/cli/releases/latest).
- extract archive contents to default fluence user directory
- download fluence archive for your platfrom from
[latest release](https://github.com/fluencelabs/cli/releases/latest).
- extract archive contents to default fluence user directory

```shell
tar --strip-components=1 -xzf <archive> -C "${HOME}/.fluence/cli"
```
```shell
tar --strip-components=1 -xzf <archive> -C "${HOME}/.fluence/cli"
```

- add `${HOME}/.fluence/cli/bin` to `$PATH`
- add `${HOME}/.fluence/cli/bin` to `$PATH`

### Using npm

Prerequisites:

- Linux or MacOS (there are currently some bugs on Windows)
- [Node.js = 18.x.x](https://nodejs.org/)
- Linux or MacOS (there are currently some bugs on Windows)
- [Node.js = 18.x.x](https://nodejs.org/)

To install and try Fluence CLI, run:

Expand Down
93 changes: 25 additions & 68 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,97 +1,54 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail

# set current working directory to script directory to run script from everywhere
cd "$(dirname "$0")"
echo "Starting Fluence installation..."

# Get the Operating System and Architecture type
# Identify OS and architecture
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"

# Define the directory where Fluence will be installed, or use a default
# Install in default fluence home dir
FLUENCE_USER_DIR="${FLUENCE_USER_DIR-$HOME/.fluence}"

# Create a temporary directory and ensure it's removed upon script exit or on interrupt/terminate signals
# Temporary directory creation and cleanup setup
TEMP="$(mktemp -d)"
trap "rm -rf '$TEMP'" EXIT INT TERM

# Check if the cli directory empty
# Verify if the cli directory is empty
if $(ls -1 ${FLUENCE_USER_DIR}/cli &>/dev/null); then
echo "${FLUENCE_USER_DIR}/cli exists and is not empty, remove it before continuing"
echo "Error: ${FLUENCE_USER_DIR}/cli exists and is not empty. Please remove it and rerun the script."
exit 1
fi

# Assign a value to 'arch' variable based on the system's architecture
# Validate and set system architecture
case "$ARCH" in
"x86_64")
arch="x64"
;;
"arm64" | "aarch64")
arch="arm64"
;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
"x86_64") arch="x64";;
"arm64" | "aarch64") arch="arm64";;
*) echo "Error: Unsupported architecture - $ARCH"; exit 1;;
esac

# Validate the operating system type
# Validate and set the operating system type
case "$OS" in
"darwin")
os="darwin"
;;
"linux")
os="linux"
;;
*)
echo "Unsupported OS: $OS"
exit 1
;;
"darwin") os="darwin";;
"linux") os="linux";;
*) echo "Error: Unsupported OS - $OS"; exit 1;;
esac

# Form archive name and URL for downloading the correct binary based on OS and Architecture
# Set archive name and URL based on OS and architecture
archive="fluence-${os}-${arch}.tar.gz"
# TODO hide S3 URL under some pretty name
url="https://fcli-binaries.s3.eu-west-1.amazonaws.com/channels/stable/${archive}"

# Create directory for Fluence CLI
echo "Downloading and extracting Fluence archive..."
mkdir -p "${FLUENCE_USER_DIR}/cli"

# Downloade and extracte the Fluence binary archive
curl -L -sS "$url" -o "${TEMP}/${archive}"
wget -q --show-progress -O "${TEMP}/${archive}" "$url"
tar --strip-components=1 -xzf "${TEMP}/${archive}" -C "${FLUENCE_USER_DIR}/cli"

# Determine shell type and define shell profile file to add Fluence CLI to PATH
case $SHELL in
*/zsh)
SHELL_PROFILE="$HOME/.zshrc"
;;
*/fish)
SHELL_PROFILE="$HOME/.config/fish/config.fish"
;;
*/bash)
SHELL_PROFILE="$HOME/.bashrc"
;;
*)
echo "Unsupported shell. Please add ${FLUENCE_USER_DIR}/cli/bin to \$PATH yourself"
exit
;;
esac

# Add the Fluence CLI binary to shell's PATH in the profile file, if it's not already present
if ! grep -q "${FLUENCE_USER_DIR}/cli/bin" "$SHELL_PROFILE"; then
if [[ $SHELL == */fish ]]; then
echo "set -gx PATH \$PATH ${FLUENCE_USER_DIR}/cli/bin" >>"$SHELL_PROFILE"
else
echo "export PATH=\$PATH:${FLUENCE_USER_DIR}/cli/bin" >>"$SHELL_PROFILE"
fi
echo "Fluence CLI installation complete!"
if echo $PATH | grep -q $HOME/.local/bin ; then
mkdir -p $HOME/.local/bin
ln -sf ${FLUENCE_USER_DIR}/cli/bin/fluence $HOME/.local/bin/fluence
else
echo "Create a symlink to fluence binary in any directory that is in \$PATH, for example:"
echo "sudo ln -s ${FLUENCE_USER_DIR}/cli/bin/fluence /usr/local/bin/fluence"
fi

# Activate the new PATH immediately, adjusting based on shell type
case $SHELL in
*/fish)
set -gx PATH $PATH ${FLUENCE_USER_DIR}/cli/bin
;;
*)
source "$SHELL_PROFILE"
;;
esac

0 comments on commit 06b0d50

Please sign in to comment.