diff --git a/install.sh b/install.sh index b3b0e2a..b0c5a07 100755 --- a/install.sh +++ b/install.sh @@ -32,22 +32,21 @@ TAG=$(curl -fsSL "$API/releases/latest" | tr ',' '\n' | grep -m1 '"tag_name"' | [ -n "${TAG:-}" ] || { echo "agent-helm: hittade ingen release på $BASE"; exit 1; } URL="$BASE/$OWNER/$REPO/releases/download/$TAG/$ASSET" -# --- bin-katalog (root -> /usr/local/bin, annars sudo, annars ~/.local/bin) --- +# --- bin-katalog: /usr/local/bin om root/skrivbar, annars ~/.local/bin (ingen sudo). +# För system-wide utan att vara root: curl -fsSL ... | sudo sh PREFIX="${PREFIX:-/usr/local}" -SUDO="" -if [ "$(id -u)" = 0 ] || [ -w "$PREFIX/bin" ]; then +if [ "$(id -u)" = 0 ] || { mkdir -p "$PREFIX/bin" 2>/dev/null && [ -w "$PREFIX/bin" ]; }; then BIN="$PREFIX/bin" -elif command -v sudo >/dev/null 2>&1; then - BIN="$PREFIX/bin"; SUDO=sudo else - BIN="$HOME/.local/bin"; mkdir -p "$BIN" + BIN="$HOME/.local/bin" fi +mkdir -p "$BIN" echo "agent-helm: hämtar $ASSET ($TAG) -> $BIN/agent-helm" tmp=$(mktemp) curl -fSL "$URL" -o "$tmp" chmod +x "$tmp" -$SUDO install -m 0755 "$tmp" "$BIN/agent-helm" +install -m 0755 "$tmp" "$BIN/agent-helm" rm -f "$tmp" # --- config ---