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")