removed sudo from install/unistall script

This commit is contained in:
Uber Veng
2026-05-22 02:03:40 +07:00
parent bb0eb3189b
commit 4d0438a2cb
3 changed files with 72 additions and 80 deletions

View File

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