Skip to content
Merged
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
23 changes: 22 additions & 1 deletion install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ function Add-UserPath {
return $true
}

# Write-ConflictWarning reports other flagsmith commands on PATH that may shadow
# (or be shadowed by) the one just installed.
function Write-ConflictWarning {
param([string]$Target)

$resolvedTarget = [System.IO.Path]::GetFullPath($Target)
# Application catches flagsmith.exe and npm's flagsmith.cmd shim;
# ExternalScript catches its flagsmith.ps1 shim. Both expose .Path, and
# neither triggers module auto-loading the way an unfiltered -All can.
$others = @(Get-Command -Name 'flagsmith' -CommandType Application, ExternalScript -All -ErrorAction SilentlyContinue |
Where-Object { $_.Path -and ([System.IO.Path]::GetFullPath($_.Path) -ne $resolvedTarget) })
foreach ($other in $others) {
Write-Output "warning: another 'flagsmith' is on your PATH at $($other.Path)"
}
if ($others.Count -gt 0) {
Write-Output "It may shadow $Target - uninstall it first ('npm uninstall -g flagsmith-cli' removes the old npm CLI), then open a new terminal."
}
}

# Add-CiPath makes the CLI available to later steps of a GitHub Actions job.
function Add-CiPath {
param([string]$Dir)
Expand Down Expand Up @@ -144,6 +163,7 @@ try {

Expand-Archive -LiteralPath $zip -DestinationPath $tmp -Force
New-Item -ItemType Directory -Force -Path $BinDir | Out-Null
$verb, $prep = if (Test-Path -LiteralPath (Join-Path $BinDir $ExeName)) { 'updated', 'at' } else { 'installed', 'to' }
Move-Item -Force -LiteralPath (Join-Path $tmp $ExeName) -Destination (Join-Path $BinDir $ExeName)
} finally {
Remove-Item -Recurse -Force -LiteralPath $tmp
Expand All @@ -152,7 +172,8 @@ try {
$exe = Join-Path $BinDir $ExeName
$installed = & $exe --version
if ($LASTEXITCODE -ne 0) { throw "$exe was installed but will not run" }
Write-Output "installed $installed to $exe"
Write-Output "$verb $installed $prep $exe"
Write-ConflictWarning -Target $exe

$pathAdded = $false
if (-not $NoModifyPath) {
Expand Down
39 changes: 38 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,36 @@ end
EOF
}

# same_file returns 0 when both paths name the same file. -ef is not POSIX
# but every common sh has it; fall back to a plain string compare.
same_file() {
[ "$1" = "$2" ] && return 0
[ "$1" -ef "$2" ] 2>/dev/null
}

# warn_conflicts reports other flagsmith binaries on PATH that may shadow
# (or be shadowed by) the one just installed.
warn_conflicts() {
_target="${INSTALL_DIR}/${BIN_NAME}"
_found=0
_seen=
_ifs_save=$IFS
IFS=:
for _dir in $PATH; do
[ -n "$_dir" ] || continue
case ":${_seen}:" in *:"${_dir}":*) continue ;; esac
_seen="${_seen}:${_dir}"
[ -x "${_dir}/${BIN_NAME}" ] || continue
same_file "${_dir}/${BIN_NAME}" "$_target" && continue
Comment thread
coderabbitai[bot] marked this conversation as resolved.
say "warning: another '${BIN_NAME}' is on your PATH at ${_dir}/${BIN_NAME}"
_found=1
done
IFS=$_ifs_save
if [ "$_found" = 1 ]; then
say "It may shadow ${_target} — uninstall it first ('npm uninstall -g flagsmith-cli' removes the old npm CLI), then run 'hash -r' or open a new shell."
fi
}

# add_ci_path makes the CLI available to later steps of a GitHub Actions job.
# GITHUB_PATH does not expand variables, so write the resolved directory.
add_ci_path() {
Expand Down Expand Up @@ -248,11 +278,18 @@ If ${VERSION} was released moments ago its archives may still be uploading — r
tar -xzf "${tmp}/${archive_name}" -C "$tmp" "$BIN_NAME"
mkdir -p "$INSTALL_DIR"
chmod 755 "${tmp}/${BIN_NAME}"
verb=installed
preposition=to
if [ -e "${INSTALL_DIR}/${BIN_NAME}" ]; then
verb=updated
preposition='at'
fi
mv -f "${tmp}/${BIN_NAME}" "${INSTALL_DIR}/${BIN_NAME}"

installed=$("${INSTALL_DIR}/${BIN_NAME}" --version 2>/dev/null) ||
err "${INSTALL_DIR}/${BIN_NAME} was installed but will not run — wrong platform?"
say "installed ${installed} to ${INSTALL_DIR}/${BIN_NAME}"
say "${verb} ${installed} ${preposition} ${INSTALL_DIR}/${BIN_NAME}"
warn_conflicts

if [ "$NO_MODIFY_PATH" != 1 ]; then
modify_path
Expand Down