removed sudo from install/unistall script
This commit is contained in:
20
README.md
20
README.md
@@ -12,7 +12,7 @@
|
|||||||
curl -fsSL https://git.vainend.com/admin/ostiary/raw/branch/master/install.sh | bash
|
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 |
|
| `ostiary-macos-x86_64` | macOS Intel |
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
mkdir -p ~/.local/bin
|
||||||
chmod +x ostiary-linux-x86_64
|
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
|
```bash
|
||||||
sudo rm /usr/local/bin/ostiary
|
rm ~/.local/bin/ostiary
|
||||||
rm -rf ~/.config/ostiary
|
rm -rf ~/.config/ostiary
|
||||||
```
|
```
|
||||||
|
|
||||||
### Переменные окружения для install.sh
|
### Переменная окружения
|
||||||
|
|
||||||
| Переменная | По умолчанию | Описание |
|
| Переменная | Описание |
|
||||||
|---|---|---|
|
|---|---|
|
||||||
| `OSTIARY_API` | `https://git.vainend.com/api/v1/repos/admin/ostiary` | Базовый URL Gitea API |
|
| `OSTIARY_API` | Базовый URL Gitea API (если используете собственный инстанс) |
|
||||||
| `INSTALL_DIR` | `/usr/local/bin` | Куда установить бинарник |
|
|
||||||
|
|
||||||
Пример с кастомным каталогом:
|
Пример с кастомным каталогом:
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
68
install.sh
68
install.sh
@@ -4,7 +4,7 @@ set -e
|
|||||||
# ── Configuration ────────────────────────────────────────────────────────────
|
# ── Configuration ────────────────────────────────────────────────────────────
|
||||||
BINARY="ostiary"
|
BINARY="ostiary"
|
||||||
REPO_API="${OSTIARY_API:-https://git.vainend.com/api/v1/repos/admin/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 ───────────────────────────────────────────────────────────────────
|
# ── Colors ───────────────────────────────────────────────────────────────────
|
||||||
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
|
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
|
||||||
@@ -47,7 +47,6 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# ── Fetch latest release tag ─────────────────────────────────────────────────
|
# ── Fetch latest release tag ─────────────────────────────────────────────────
|
||||||
# Uses /releases/latest which returns the newest non-prerelease, non-draft release.
|
|
||||||
info "Fetching latest release info..."
|
info "Fetching latest release info..."
|
||||||
|
|
||||||
LATEST_JSON=$(fetch "${REPO_API}/releases/latest") \
|
LATEST_JSON=$(fetch "${REPO_API}/releases/latest") \
|
||||||
@@ -63,52 +62,55 @@ VERSION=$(printf '%s' "$LATEST_JSON" \
|
|||||||
ok "Latest version: ${VERSION}"
|
ok "Latest version: ${VERSION}"
|
||||||
|
|
||||||
# ── Build download URL ───────────────────────────────────────────────────────
|
# ── 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||')
|
BASE_URL=$(printf '%s' "$REPO_API" | sed 's|/api/v1/repos||')
|
||||||
DOWNLOAD_URL="${BASE_URL}/releases/download/${VERSION}/${ASSET}"
|
DOWNLOAD_URL="${BASE_URL}/releases/download/${VERSION}/${ASSET}"
|
||||||
|
|
||||||
info "Downloading ${DOWNLOAD_URL}..."
|
info "Downloading ${DOWNLOAD_URL}..."
|
||||||
|
|
||||||
# Quick existence check before downloading the full binary
|
|
||||||
CODE=$(http_code "$DOWNLOAD_URL")
|
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)
|
TMP=$(mktemp)
|
||||||
trap 'rm -f "$TMP"' EXIT
|
trap 'rm -f "$TMP"' EXIT
|
||||||
|
|
||||||
fetch_file "$DOWNLOAD_URL" "$TMP" || die "Download failed"
|
fetch_file "$DOWNLOAD_URL" "$TMP" || die "Download failed"
|
||||||
chmod +x "$TMP"
|
chmod +x "$TMP"
|
||||||
|
|
||||||
# ── Install ──────────────────────────────────────────────────────────────────
|
# ── Install to ~/.local/bin ───────────────────────────────────────────────────
|
||||||
do_install() {
|
mkdir -p "$INSTALL_DIR"
|
||||||
local dest="$1/$BINARY"
|
mv "$TMP" "$INSTALL_DIR/$BINARY"
|
||||||
if [ -w "$1" ]; then
|
ok "Installed → $INSTALL_DIR/$BINARY"
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
if ! do_install "$INSTALL_DIR"; then
|
# ── Add ~/.local/bin to PATH if missing ──────────────────────────────────────
|
||||||
FALLBACK="$HOME/.local/bin"
|
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
|
||||||
warn "${INSTALL_DIR} is not writable and sudo is unavailable"
|
warn "$INSTALL_DIR is not in PATH — adding it now..."
|
||||||
warn "Installing to ${FALLBACK} instead"
|
|
||||||
mkdir -p "$FALLBACK"
|
EXPORT_LINE="export PATH=\"\$HOME/.local/bin:\$PATH\""
|
||||||
mv "$TMP" "$FALLBACK/$BINARY"
|
|
||||||
ok "Installed → $FALLBACK/$BINARY"
|
# Determine which profile file to update
|
||||||
if [[ ":$PATH:" != *":$FALLBACK:"* ]]; then
|
if [ -f "$HOME/.bashrc" ]; then
|
||||||
warn "Add to your shell profile:"
|
PROFILE="$HOME/.bashrc"
|
||||||
warn " export PATH=\"\$HOME/.local/bin:\$PATH\""
|
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
|
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
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
62
uninstall.sh
62
uninstall.sh
@@ -2,6 +2,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
BINARY="ostiary"
|
BINARY="ostiary"
|
||||||
|
INSTALL_DIR="$HOME/.local/bin"
|
||||||
CONFIG_DIR="$HOME/.config/$BINARY"
|
CONFIG_DIR="$HOME/.config/$BINARY"
|
||||||
|
|
||||||
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
|
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} $*"; }
|
ok() { echo -e "${GREEN}[ostiary]${NC} $*"; }
|
||||||
warn() { echo -e "${YELLOW}[ostiary]${NC} $*"; }
|
warn() { echo -e "${YELLOW}[ostiary]${NC} $*"; }
|
||||||
|
|
||||||
# ── Find binary ──────────────────────────────────────────────────────────────
|
# ── Remove binary ────────────────────────────────────────────────────────────
|
||||||
BINARY_PATH=$(command -v "$BINARY" 2>/dev/null || true)
|
BINARY_PATH="$INSTALL_DIR/$BINARY"
|
||||||
|
|
||||||
removed_binary=false
|
if [ -f "$BINARY_PATH" ]; then
|
||||||
|
|
||||||
if [ -n "$BINARY_PATH" ]; then
|
|
||||||
info "Found binary: $BINARY_PATH"
|
info "Found binary: $BINARY_PATH"
|
||||||
read -rp " Remove $BINARY_PATH? [y/N] " answer
|
read -rp " Remove it? [y/N] " answer
|
||||||
if [[ "$answer" =~ ^[Yy]$ ]]; then
|
if [[ "$answer" =~ ^[Yy]$ ]]; then
|
||||||
BIN_DIR=$(dirname "$BINARY_PATH")
|
|
||||||
if [ -w "$BIN_DIR" ]; then
|
|
||||||
rm "$BINARY_PATH"
|
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
|
|
||||||
ok "Binary removed"
|
ok "Binary removed"
|
||||||
removed_binary=true
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Check common locations manually
|
warn "Binary not found at $BINARY_PATH"
|
||||||
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
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! $removed_binary; then
|
# ── Remove config ────────────────────────────────────────────────────────────
|
||||||
warn "Binary not found in PATH"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ── Config directory ─────────────────────────────────────────────────────────
|
|
||||||
if [ -d "$CONFIG_DIR" ]; then
|
if [ -d "$CONFIG_DIR" ]; then
|
||||||
echo ""
|
echo ""
|
||||||
info "Config directory: $CONFIG_DIR"
|
info "Config directory: $CONFIG_DIR"
|
||||||
@@ -70,5 +39,22 @@ if [ -d "$CONFIG_DIR" ]; then
|
|||||||
fi
|
fi
|
||||||
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 ""
|
echo ""
|
||||||
ok "Done"
|
ok "Done"
|
||||||
|
|||||||
Reference in New Issue
Block a user