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
4 changes: 0 additions & 4 deletions docs/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ function Get-DecodoBin([string]$BinDir) {
}

function Get-CommandPrefix([string]$BinDir) {
if ($script:PathActivationRequired) {
return Get-DecodoBin $BinDir
}

return $CommandName
}

Expand Down
80 changes: 72 additions & 8 deletions docs/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ORIG_PATH=""
USER_PREFIX_BIN=""
PATH_ACTIVATION_REQUIRED=0
ACTIVATION_RC_FILE=""
LINKED_DIR=""

if [ -t 1 ]; then
RED='\033[0;31m'
Expand Down Expand Up @@ -83,13 +84,73 @@ ensure_path() {
warn "$dir was not in your PATH. Added it to $rc_file"
}

command_prefix() {
first_writable_path_dir() {
exclude="$1"
old_ifs="$IFS"
IFS=:
set -f
set -- $ORIG_PATH
set +f
IFS="$old_ifs"

for dir in "$@"; do
[ -n "$dir" ] || continue
case "$dir" in
/*) ;;
*) continue ;;
esac
[ "$dir" = "$exclude" ] && continue
if [ -d "$dir" ] && [ -w "$dir" ]; then
printf '%s' "$dir"
return 0
fi
done

return 1
}

link_command() {
bin_dir="$1"
if [ "$PATH_ACTIVATION_REQUIRED" = 1 ]; then
printf '%s/%s' "$bin_dir" "$COMMAND_NAME"
else
printf '%s' "$COMMAND_NAME"
dest_dir="$2"
src="${bin_dir}/${COMMAND_NAME}"
dest="${dest_dir}/${COMMAND_NAME}"

[ -e "$src" ] || return 1
if [ -e "$dest" ] && [ ! -L "$dest" ]; then
return 1
fi

ln -sf "$src" "$dest" 2>/dev/null || return 1
return 0
}

link_command_onto_path() {
bin_dir="$1"

if path_contains "$bin_dir" "$ORIG_PATH"; then
return 0
fi

link_dir=$(first_writable_path_dir "$bin_dir") || link_dir=""
if [ -n "$link_dir" ] && link_command "$bin_dir" "$link_dir"; then
LINKED_DIR="$link_dir"
return 0
fi

ensure_path "$bin_dir"
}

print_rehash_hint() {
shell_name=$(basename "${SHELL:-/bin/sh}")
case "$shell_name" in
zsh | bash)
printf "${DIM}If this shell can't find decodo yet, run: hash -r${RESET}\n"
;;
esac
}

command_prefix() {
printf '%s' "$COMMAND_NAME"
}

print_activation_steps() {
Expand Down Expand Up @@ -197,10 +258,10 @@ install_package() {
warn "Global install failed. Falling back to a user-level install."
else
warn "No write permission for the npm global directory ($(npm prefix -g 2>/dev/null))."
info "Installing ${PACKAGE_NAME} to ${HOME}/.npm-global instead (no sudo needed)..."
fi

user_prefix="${HOME}/.npm-global"
user_prefix="${HOME}/.local"
info "Installing ${PACKAGE_NAME} to ${user_prefix} (no sudo needed)..."
mkdir -p "$user_prefix"

if ! npm install -g --prefix "$user_prefix" "${PACKAGE_NAME}"; then
Expand Down Expand Up @@ -230,14 +291,17 @@ main() {
install_package

BIN_DIR=$(resolve_install_bin)
ensure_path "$BIN_DIR"
link_command_onto_path "$BIN_DIR"

installed_version=$("${BIN_DIR}/${COMMAND_NAME}" --version 2>/dev/null || echo "unknown")
printf '\n'
success "Success! ${PACKAGE_NAME} ${installed_version} is installed."

if [ "$PATH_ACTIVATION_REQUIRED" = 1 ]; then
print_activation_steps "$BIN_DIR"
elif [ -n "$LINKED_DIR" ]; then
success "Ready to use — decodo is on your PATH (linked into ${LINKED_DIR})."
print_rehash_hint
else
success "Ready to use — decodo is on your PATH."
fi
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@decodo/cli",
"version": "1.0.1",
"version": "1.0.2",
"description": "Official CLI for the Decodo APIs",
"license": "MIT",
"type": "module",
Expand Down
Loading