Skip to content
Open
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
36 changes: 29 additions & 7 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -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' <<EOH
Expand All @@ -361,6 +378,9 @@ fi

if [ -z "${ENVX_BIN_DIR-}" ]; then
BIN_DIR=/usr/local/bin
else
BIN_DIR="${ENVX_BIN_DIR}"
BIN_DIR_EXPLICIT=1
fi

if [ -z "${ENVX_ARCH-}" ]; then
Expand All @@ -380,6 +400,7 @@ while [ "$#" -gt 0 ]; do
;;
-b | --bin-dir)
BIN_DIR="$2"
BIN_DIR_EXPLICIT=1
shift 2
;;
-a | --arch)
Expand Down Expand Up @@ -413,6 +434,7 @@ while [ "$#" -gt 0 ]; do
;;
-b=* | --bin-dir=*)
BIN_DIR="${1#*=}"
BIN_DIR_EXPLICIT=1
shift 1
;;
-a=* | --arch=*)
Expand Down Expand Up @@ -525,4 +547,4 @@ printf "$MAGENTA"
_/j L l\_! _//^---^\\_

EOF
printf "$NO_COLOR"
printf "$NO_COLOR"
13 changes: 8 additions & 5 deletions src/commands/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct Args {
pub async fn command(args: Args, config: &mut Config) -> 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`");
Expand All @@ -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());

Expand All @@ -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")
Expand Down