diff --git a/README.md b/README.md index bbbda93..4ba9b50 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ curl -fsSL https://git.vainend.com/admin/ostiary/raw/branch/master/install.sh | bash ``` -Скрипт автоматически определяет ОС и архитектуру, скачивает последний стабильный релиз и устанавливает бинарник в `/usr/local/bin/ostiary` (или `~/.local/bin/` если нет прав). +Скрипт определяет ОС и архитектуру, скачивает последний стабильный релиз и устанавливает бинарник в `~/.local/bin/ostiary`. Если этого пути нет в `$PATH` — автоматически добавляет строку в `~/.bashrc` (или `~/.bash_profile` / `~/.profile`). Не требует `sudo`. ### Ручная установка @@ -26,8 +26,13 @@ curl -fsSL https://git.vainend.com/admin/ostiary/raw/branch/master/install.sh | | `ostiary-macos-x86_64` | macOS Intel | ```bash +mkdir -p ~/.local/bin chmod +x ostiary-linux-x86_64 -sudo mv ostiary-linux-x86_64 /usr/local/bin/ostiary +mv ostiary-linux-x86_64 ~/.local/bin/ostiary + +# Добавить в PATH если нужно +echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc +source ~/.bashrc ``` ### Удаление @@ -39,16 +44,15 @@ curl -fsSL https://git.vainend.com/admin/ostiary/raw/branch/master/uninstall.sh Или вручную: ```bash -sudo rm /usr/local/bin/ostiary +rm ~/.local/bin/ostiary rm -rf ~/.config/ostiary ``` -### Переменные окружения для install.sh +### Переменная окружения -| Переменная | По умолчанию | Описание | -|---|---|---| -| `OSTIARY_API` | `https://git.vainend.com/api/v1/repos/admin/ostiary` | Базовый URL Gitea API | -| `INSTALL_DIR` | `/usr/local/bin` | Куда установить бинарник | +| Переменная | Описание | +|---|---| +| `OSTIARY_API` | Базовый URL Gitea API (если используете собственный инстанс) | Пример с кастомным каталогом: ```bash diff --git a/install.sh b/install.sh index 35e05fd..2961b1c 100755 --- a/install.sh +++ b/install.sh @@ -4,7 +4,7 @@ set -e # ── Configuration ──────────────────────────────────────────────────────────── BINARY="ostiary" REPO_API="${OSTIARY_API:-https://git.vainend.com/api/v1/repos/admin/ostiary}" -INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}" +INSTALL_DIR="$HOME/.local/bin" # ── Colors ─────────────────────────────────────────────────────────────────── RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m' @@ -47,7 +47,6 @@ else fi # ── Fetch latest release tag ───────────────────────────────────────────────── -# Uses /releases/latest which returns the newest non-prerelease, non-draft release. info "Fetching latest release info..." LATEST_JSON=$(fetch "${REPO_API}/releases/latest") \ @@ -63,52 +62,55 @@ VERSION=$(printf '%s' "$LATEST_JSON" \ ok "Latest version: ${VERSION}" # ── Build download URL ─────────────────────────────────────────────────────── -# Strip /api/v1/repos from the API base to get the Gitea web URL: -# https://git.vainend.com/api/v1/repos/admin/ostiary -# → https://git.vainend.com/admin/ostiary BASE_URL=$(printf '%s' "$REPO_API" | sed 's|/api/v1/repos||') DOWNLOAD_URL="${BASE_URL}/releases/download/${VERSION}/${ASSET}" info "Downloading ${DOWNLOAD_URL}..." -# Quick existence check before downloading the full binary CODE=$(http_code "$DOWNLOAD_URL") -[ "$CODE" = "200" ] || die "Asset not found (HTTP ${CODE}): ${ASSET}\nCheck that the release contains a file named '${ASSET}'" +[ "$CODE" = "200" ] || die "Asset not found (HTTP ${CODE}): ${ASSET}" -# ── Download to temp file ──────────────────────────────────────────────────── +# ── Download ───────────────────────────────────────────────────────────────── TMP=$(mktemp) trap 'rm -f "$TMP"' EXIT fetch_file "$DOWNLOAD_URL" "$TMP" || die "Download failed" chmod +x "$TMP" -# ── Install ────────────────────────────────────────────────────────────────── -do_install() { - local dest="$1/$BINARY" - if [ -w "$1" ]; then - mv "$TMP" "$dest" - ok "Installed → $dest" - return 0 - elif command -v sudo &>/dev/null; then - warn "Writing to $1 requires sudo..." - sudo mv "$TMP" "$dest" - ok "Installed → $dest" - return 0 - fi - return 1 -} +# ── Install to ~/.local/bin ─────────────────────────────────────────────────── +mkdir -p "$INSTALL_DIR" +mv "$TMP" "$INSTALL_DIR/$BINARY" +ok "Installed → $INSTALL_DIR/$BINARY" -if ! do_install "$INSTALL_DIR"; then - FALLBACK="$HOME/.local/bin" - warn "${INSTALL_DIR} is not writable and sudo is unavailable" - warn "Installing to ${FALLBACK} instead" - mkdir -p "$FALLBACK" - mv "$TMP" "$FALLBACK/$BINARY" - ok "Installed → $FALLBACK/$BINARY" - if [[ ":$PATH:" != *":$FALLBACK:"* ]]; then - warn "Add to your shell profile:" - warn " export PATH=\"\$HOME/.local/bin:\$PATH\"" +# ── Add ~/.local/bin to PATH if missing ────────────────────────────────────── +if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then + warn "$INSTALL_DIR is not in PATH — adding it now..." + + EXPORT_LINE="export PATH=\"\$HOME/.local/bin:\$PATH\"" + + # Determine which profile file to update + if [ -f "$HOME/.bashrc" ]; then + PROFILE="$HOME/.bashrc" + elif [ -f "$HOME/.bash_profile" ]; then + PROFILE="$HOME/.bash_profile" + elif [ -f "$HOME/.profile" ]; then + PROFILE="$HOME/.profile" + else + # Create .bashrc if nothing exists + PROFILE="$HOME/.bashrc" fi + + # Avoid duplicate entries + if ! grep -qF "$INSTALL_DIR" "$PROFILE" 2>/dev/null; then + printf '\n# Added by ostiary installer\n%s\n' "$EXPORT_LINE" >> "$PROFILE" + ok "Added PATH entry to $PROFILE" + fi + + warn "Run the following to use ostiary in this session:" + warn " export PATH=\"\$HOME/.local/bin:\$PATH\"" + warn "New shells will pick it up automatically." +else + ok "$INSTALL_DIR is already in PATH" fi echo "" diff --git a/uninstall.sh b/uninstall.sh index fc80c5a..907ca2c 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -2,6 +2,7 @@ set -e BINARY="ostiary" +INSTALL_DIR="$HOME/.local/bin" CONFIG_DIR="$HOME/.config/$BINARY" RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m' @@ -11,53 +12,21 @@ info() { echo -e "${CYAN}[ostiary]${NC} $*"; } ok() { echo -e "${GREEN}[ostiary]${NC} $*"; } warn() { echo -e "${YELLOW}[ostiary]${NC} $*"; } -# ── Find binary ────────────────────────────────────────────────────────────── -BINARY_PATH=$(command -v "$BINARY" 2>/dev/null || true) +# ── Remove binary ──────────────────────────────────────────────────────────── +BINARY_PATH="$INSTALL_DIR/$BINARY" -removed_binary=false - -if [ -n "$BINARY_PATH" ]; then +if [ -f "$BINARY_PATH" ]; then info "Found binary: $BINARY_PATH" - read -rp " Remove $BINARY_PATH? [y/N] " answer + read -rp " Remove it? [y/N] " answer if [[ "$answer" =~ ^[Yy]$ ]]; then - BIN_DIR=$(dirname "$BINARY_PATH") - if [ -w "$BIN_DIR" ]; then - rm "$BINARY_PATH" - elif command -v sudo &>/dev/null; then - sudo rm "$BINARY_PATH" - else - warn "Cannot remove $BINARY_PATH (no write permission and no sudo)" - fi + rm "$BINARY_PATH" ok "Binary removed" - removed_binary=true fi else - # Check common locations manually - for loc in /usr/local/bin /usr/bin "$HOME/.local/bin"; do - if [ -f "$loc/$BINARY" ]; then - info "Found binary: $loc/$BINARY" - read -rp " Remove $loc/$BINARY? [y/N] " answer - if [[ "$answer" =~ ^[Yy]$ ]]; then - if [ -w "$loc" ]; then - rm "$loc/$BINARY" - elif command -v sudo &>/dev/null; then - sudo rm "$loc/$BINARY" - else - warn "Cannot remove $loc/$BINARY" - fi - ok "Binary removed" - removed_binary=true - fi - break - fi - done + warn "Binary not found at $BINARY_PATH" fi -if ! $removed_binary; then - warn "Binary not found in PATH" -fi - -# ── Config directory ───────────────────────────────────────────────────────── +# ── Remove config ──────────────────────────────────────────────────────────── if [ -d "$CONFIG_DIR" ]; then echo "" info "Config directory: $CONFIG_DIR" @@ -70,5 +39,22 @@ if [ -d "$CONFIG_DIR" ]; then fi fi +# ── Remove PATH entry from shell profile ───────────────────────────────────── +for PROFILE in "$HOME/.bashrc" "$HOME/.bash_profile" "$HOME/.profile"; do + if [ -f "$PROFILE" ] && grep -qF ".local/bin" "$PROFILE"; then + echo "" + info "Found PATH entry in $PROFILE" + read -rp " Remove the PATH line added by ostiary installer? [y/N] " answer + if [[ "$answer" =~ ^[Yy]$ ]]; then + # Remove the comment and the export line added by install.sh + sed -i.bak '/# Added by ostiary installer/d' "$PROFILE" + sed -i.bak '/\.local\/bin.*PATH/d' "$PROFILE" + rm -f "${PROFILE}.bak" + ok "PATH entry removed from $PROFILE" + fi + break + fi +done + echo "" ok "Done"