flyctl icon indicating copy to clipboard operation
flyctl copied to clipboard

flyctl install script mistakenly thinks that the binary is on the PATH on Codespaces Ubuntu

Open lpil opened this issue 4 years ago • 6 comments

Describe the bug

Hello! I just ran curl -L https://fly.io/install.sh | sh on a new Ubuntu box and this happened

** Command output: **

curl -L https://fly.io/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1412    0  1412    0     0  23932      0 --:--:-- --:--:-- --:--:-- 23932

######################################################################## 100.0%##O#- #                                                                       
WARN no config file found at /home/codespace/.fly/config.yml
set channel to shell
flyctl was installed successfully to /home/codespace/.fly/bin/flyctl
Run 'flyctl --help' to get started

$ flyctl
bash: flyctl: command not found

Looking at the script I think the issue may be this check here:

echo "flyctl was installed successfully to $exe"
if command -v flyctl >/dev/null; then
	echo "Run 'flyctl --help' to get started"
else
	case $SHELL in
	/bin/zsh) shell_profile=".zshrc" ;;
	*) shell_profile=".bash_profile" ;;
	esac
	echo "Manually add the directory to your \$HOME/$shell_profile (or similar)"
	echo "  export FLYCTL_INSTALL=\"$flyctl_install\""
	echo "  export PATH=\"\$FLYCTL_INSTALL/bin:\$PATH\""
	echo "Run '$exe --help' to get started"
fi

It uses command -v flyctl to test if flyctl is on the PATH, but it mistakenly thinks it is because while it is not in the PATH, it is in the cwd when command -v flyctl is run, so flyctl successfully executes. Once the script exits we're no longer in the flyctl bin directory, so it no longer works.

If I follow the instructions in the other branch of the if statement it does work.

lpil avatar Jan 13 '22 23:01 lpil

I'm not able to reproduce this. Do you have . in your $PATH?

jsierles avatar Jan 14 '22 12:01 jsierles

Do you have . in your $PATH?

Unfortunately not. Here it is

$ echo $PATH
/home/codespace/.rbenv/shims:/vscode/bin/linux-x64/899d46d82c4c95423fb7e10e68eba52050e30ba3/bin:/home/codespace/.nvm/current/bin:/home/codespace/.npm-global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/codespace/.dotnet:/home/codespace/.dotnet/tools:/usr/local/sdkman/bin:/usr/local/sdkman/candidates/gradle/current/bin:/usr/local/sdkman/candidates/java/current/bin:/opt/maven/lts:/usr/local/cargo/bin:/usr/local/go/bin:/go/bin:/usr/local/py-utils/bin:/opt/conda/condabin:/home/codespace/.java/current/bin:/home/codespace/.nodejs/current/bin:/home/codespace/.php/current/bin:/home/codespace/.python/current/bin:/home/codespace/.ruby/current/bin:/home/codespace/.maven/current/bin:/home/codespace/.hugo/current/bin:/opt/oryx:/opt/nodejs/lts/bin:/opt/dotnet/lts:/opt/python/latest/bin:/opt/php/lts/bin:/opt/php-composer:/opt/yarn/stable/bin:/opt/hugo/lts::/opt/java/lts/bin:/opt/maven/lts/bin:/opt/ruby/lts/bin:/home/codespace/.local/bin:/usr/local/rvm/bin

Reproduction

Create a new codespace. I'm using this repo

image

Wait for it to boot.

Run cd to go to the home directory

Run curl -L https://fly.io/install.sh | sh

Run flyctl

lpil avatar Jan 14 '22 12:01 lpil

So revisiting this - indeed you have to set your path manually the first time. This is true on all platforms - the install script will not modify your PATH.

For codespaces, you'll want to make sure that the flyctl install directory is added to your profile at boot time.

jsierles avatar Feb 08 '22 10:02 jsierles

Sorry @jsierles , I think there has been a misunderstanding here. I am not reporting that the path was unmodifed, rather that the install script was failing to print the information saying that it needs to be added to the PATH.

I have tested this again and the problem still exists with the latest version.

Here is the current output:

@lpil ➜ ~ $ curl -L https://fly.io/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1412    0  1412    0     0   6854      0 --:--:-- --:--:-- --:--:--  6854
######################################################################## 100.0%##O#- #                ######################################################################## 100.0%
set channel to shell
flyctl was installed successfully to /home/codespace/.fly/bin/flyctl
Run 'flyctl --help' to get started

The expected output should include the output of this part of the shell script:

	echo "Manually add the directory to your \$HOME/$shell_profile (or similar)"
	echo "  export FLYCTL_INSTALL=\"$flyctl_install\""
	echo "  export PATH=\"\$FLYCTL_INSTALL/bin:\$PATH\""
	echo "Run '$exe --help' to get started"

I think this should be reopened.

lpil avatar Feb 08 '22 17:02 lpil

Ah OK. So I tried on a fresh ubuntu Docker container:

# curl -L https://fly.io/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1412    0  1412    0     0   3010      0 --:--:-- --:--:-- --:--:--  3010
######################################################################## 100.0%#=#=-#  #
set channel to shell
flyctl was installed successfully to /root/.fly/bin/flyctl
Manually add the directory to your $HOME/.bash_profile (or similar)
  export FLYCTL_INSTALL="/root/.fly"
  export PATH="$FLYCTL_INSTALL/bin:$PATH"
Run '/root/.fly/bin/flyctl --help' to get started

This means there must be something different in the environment you're testing. flyctl should not be in the PATH yet. I can try to test on codespaces when time permits.

jsierles avatar Feb 08 '22 17:02 jsierles

Thanks for reporting this. The current installer no longer changes into the flyctl bin directory before checking command -v flyctl, so the working-directory false positive from this report is gone. It now prints or configures the shell PATH when flyctl is not available. I’m going to close this as fixed. Please reopen if the current installer still says flyctl is on PATH when it is not.

tomr-fly avatar Aug 02 '26 19:08 tomr-fly