Skip to content

macOS: $HOME/Library/Application Support space not escaped in swiftly-install.sh #134

Closed
@BrianHenryIE

Description

@BrianHenryIE

I built the repo and replaced DOWNLOAD_URL in swiftly-install.sh with the build I made.

The UI displays $HOME/Library/Application where it should show $HOME/Library/Application Support/swiftly

% ./swiftly-install.sh 

This script will install swiftly, a Swift toolchain installer and manager.

Current installation options:

    Data and configuration files directory: $HOME/Library/Application
        Executables installation directory: $HOME/Library/Application
     Modify login config ($HOME/.zprofile): true
               Install system dependencies: true

Select one of the following:
1) Proceed with the installation (default)
2) Customize the installation
3) Cancel
> 1
Downloading swiftly from https://brianhenryie.s3.amazonaws.com/2024/swiftly...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 18.7M  100 18.7M    0     0  5497k      0  0:00:03  0:00:03 --:--:-- 5499k

swiftly has been successfully installed!

Once you log in again, swiftly should be accessible from your PATH.
To begin using swiftly from your current shell, first run the following command:

    . $HOME/Library/Application/env.sh

Then to install the latest version of Swift, run 'swiftly install latest'

Warning: existing installation of Swift detected at /usr/bin/swift
To ensure swiftly-installed toolchains can be found by the shell, uninstall any existing Swift installation(s).
To ensure the current shell can find swiftly-installed toolchains, you may also need to run 'hash -r'.

When I open a new Terminal shell

/Users/brianhenry/.zprofile:.:9: no such file or directory: /Users/brianhenry/Library/Application/env.sh

and

% swiftly

zsh: command not found: swiftly

The binary was correctly installed

% ls $HOME/Library/Application\ Support/swiftly/bin/       

swiftly

but the env.sh file seems to have escaping problems

cat $HOME/Library/Application\ Support/swiftly/env.sh 

export SWIFTLY_HOME_DIR="$HOME/Library/Application"
export SWIFTLY_BIN_DIR="$HOME/Library/Application"
if [[ ":$PATH:" != *":$SWIFTLY_BIN_DIR:"* ]]; then
   export PATH="$SWIFTLY_BIN_DIR:$PATH"
fi

The problem is in the replace_home_path function:

# Replaces the actual path to $HOME at the beginning of the provided string argument with
# the string "$HOME". This is used when printing to stdout.
# e.g. "home/user/.local/bin" => "$HOME/.local/bin"
replace_home_path () {
if [[ "$1" =~ ^"$HOME"(/|$) ]]; then
echo "\$HOME${1#$HOME}"
else
echo "$1"
fi
}

which I think can be fixed with:

replace_home_path () {
    if [[ "$@" =~ ^"$HOME"(.*|$) ]]; then
        printf "\$HOME${BASH_REMATCH[1]}"
    else
    echo "there"
        echo "$1"
    fi
}

And also use $@ in the bold function:

# Prints the provided argument using the terminal's bold text effect.
bold () {
echo "$(tput bold)$1$(tput sgr0)"
}

bold () {
    echo "$(tput bold)$@$(tput sgr0)"
}

Then the path put into the source command needs to be quoted:

SOURCE_LINE=". $(replace_home_path $HOME_DIR)/$ENV_FILE"

        SOURCE_LINE=". \"$(replace_home_path $HOME_DIR)/$ENV_FILE\""

I'll put together a PR with those changes now, but I don't know what, if any, impact it will have when run under Linux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions