Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(install): allow setting symlink target with env #800

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.sh]
indent_style = space
indent_size = 4
14 changes: 14 additions & 0 deletions scripts/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ Run the command below in your terminal.
curl -fsSL https://fvm.app/install.sh | bash
```

FVM will be installed to the following paths.

```bash
FVM_DIR="$HOME/.fvm_flutter}"
FVM_DIR_BIN="$HOME/bin}"
FVM_SYMLINK_TARGET="/usr/local/bin/fvm"
```

Target paths can be overridden using environment variables.

```bash
curl -fsSL https://fvm.app/install.sh | FVM_SYMLINK_TARGET=$HOME/.local/bin/fvm bash
```

### Install FVM on Windows

**Run as Admin**: Open PowerShell as Administrator.
Expand Down
45 changes: 31 additions & 14 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ Darwin*) OS='macos' ;;
esac

case "$ARCH" in
x86_64) ARCH='x64' ;;
arm64|aarch64) ARCH='arm64' ;;
armv7l) ARCH='arm' ;;
*) log_message "Unsupported architecture"; exit 1 ;;
x86_64) ARCH='x64' ;;
arm64 | aarch64) ARCH='arm64' ;;
armv7l) ARCH='arm' ;;
*)
log_message "Unsupported architecture"
exit 1
;;
esac

# Terminal colors setup
Expand Down Expand Up @@ -74,15 +77,19 @@ fi
log_message "Installing FVM version $FVM_VERSION."

# Setup installation directory and symlink
FVM_DIR="$HOME/.fvm_flutter"
FVM_DIR_BIN="$FVM_DIR/bin"

SYMLINK_TARGET="/usr/local/bin/fvm"

FVM_DIR="${FVM_DIR:-$HOME/.fvm_flutter}"
FVM_DIR_BIN="${FVM_DIR_BIN:-$FVM_DIR/bin}"
SYMLINK_TARGET="${FVM_SYMLINK_TARGET:-/usr/local/bin/fvm}"

# Create FVM directory if it doesn't exist
mkdir -p "$FVM_DIR_BIN" || error "Failed to create FVM directory: $FVM_DIR_BIN."
mkdir -p "$FVM_DIR_BIN" || {
echo "Failed to create FVM directory: $FVM_DIR_BIN."
exit 1
}

echo "FVM installation directory: $FVM_DIR"
echo "FVM binary directory: $FVM_DIR_BIN"
echo "FVM symlink target: $SYMLINK_TARGET"

# Check if FVM_DIR_BIN exists, and if it does delete it

Expand Down Expand Up @@ -114,12 +121,23 @@ if ! mv "$FVM_DIR/fvm" "$FVM_DIR_BIN"; then
error "Failed to move fvm to bin directory."
fi


# Create a symlink
if ! sudo ln -sf "$FVM_DIR_BIN/fvm" "$SYMLINK_TARGET"; then
error "Failed to create symlink."
if [ -n "${FVM_SYMLINK_TARGET}" ]; then
# Skip sudo if FVM_SYMLINK_TARGET is explicitly set
if ! ln -sf "$FVM_DIR_BIN/fvm" "$SYMLINK_TARGET"; then
echo "Failed to create symlink at $SYMLINK_TARGET."
exit 1
fi
else
# Use sudo for default SYMLINK_TARGET
if ! sudo ln -sf "$FVM_DIR_BIN/fvm" "$SYMLINK_TARGET"; then
echo "Failed to create symlink at $SYMLINK_TARGET with sudo."
exit 1
fi
fi

echo "Symlink created at $SYMLINK_TARGET pointing to $FVM_DIR_BIN/fvm"

tildify() {
if [[ $1 = $HOME/* ]]; then
local replacement=\~/
Expand Down Expand Up @@ -247,7 +265,6 @@ echo
log_message "To get started, run:"
echo


if [[ $refresh_command ]]; then
info_bold " $refresh_command"
fi
Expand Down