From c5de32d2256be2c7998b75058a077fd0d0270220 Mon Sep 17 00:00:00 2001 From: Alexander Ng Date: Thu, 16 Jul 2026 15:19:34 -0700 Subject: [PATCH] fix(install): fall back to ~/.local/bin when sudo is unavailable Keep explicit bin-dir installs on the existing fatal sudo path, but let default installs fall back to a per-user bin directory when sudo is unavailable or denied. Also make envx auth quiet by default: hide the raw auth token and server response unless --debug is set, and print a concise authenticated line with the key fingerprint. Co-Authored-By: GPT-5.5 --- install.sh | 36 +++++++++++++++++++++++++++++------- src/commands/auth.rs | 13 ++++++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/install.sh b/install.sh index b2ae90c..1b3a44c 100755 --- a/install.sh +++ b/install.sh @@ -158,20 +158,24 @@ unpack() { return 1 } -elevate_priv() { +try_elevate_priv() { if ! has sudo; then error 'Could not find the command "sudo", needed to get permissions for install.' info "If you are on Windows, please run your shell as an administrator, then" info "rerun this script. Otherwise, please run this script as root, or install" info "sudo." - exit 1 + return 1 fi if ! sudo -v; then error "Superuser not granted, aborting installation" - exit 1 + return 1 fi } +elevate_priv() { + try_elevate_priv || exit 1 +} + install() { local msg local sudo @@ -183,9 +187,21 @@ install() { msg="Installing envx, please wait…" else warn "Escalated permissions are required to install to ${BIN_DIR}" - elevate_priv - sudo="sudo" - msg="Installing envx as root, please wait…" + if [ "${BIN_DIR_EXPLICIT}" = 1 ]; then + elevate_priv + sudo="sudo" + msg="Installing envx as root, please wait…" + elif try_elevate_priv; then + sudo="sudo" + msg="Installing envx as root, please wait…" + else + warn "Couldn't write to ${BIN_DIR} without sudo; installing to ${HOME}/.local/bin instead" + BIN_DIR="${HOME}/.local/bin" + mkdir -p "${BIN_DIR}" + check_bin_dir "${BIN_DIR}" + sudo="" + msg="Installing envx, please wait…" + fi fi info "$msg" @@ -337,6 +353,7 @@ is_build_available() { } UNINSTALL=0 HELP=0 +BIN_DIR_EXPLICIT=0 CARGOTOML="$(curl -fsSL https://raw.githubusercontent.com/env-store/rusty-cli/master/Cargo.toml)" ALL_VERSIONS="$(sed -n 's/.*version = "\([^"]*\)".*/\1/p' < anyhow::Result<()> { let key = config.primary_key()?; let password = config.primary_key_password()?; + let fingerprint = key.fingerprint[..8].to_string(); if key.uuid.is_none() { bail!("Key does not have a UUID, try `envx upload`"); @@ -24,7 +25,9 @@ pub async fn command(args: Args, config: &mut Config) -> anyhow::Result<()> { let client = reqwest::Client::new(); let auth_token = key.auth_token()?; - println!("auth token:\n{}", auth_token.signature); + if args.debug { + println!("auth token:\n{}", auth_token.signature); + } let url = format!("{}test-auth", api_url()); @@ -45,12 +48,12 @@ pub async fn command(args: Args, config: &mut Config) -> anyhow::Result<()> { let status = res.status(); if status.is_success() { - println!("success"); - // print the text response - let text = res.text().await?; - println!("{}", text); + println!("{} fingerprint: {}", "✓ authenticated".green(), fingerprint); + if args.debug { + println!("{}", text); + } } else { println!("status: {}", status); bail!("failed to auth")