Files
loki 303c56f03d Initial commit: quoter CLI with 96 seed quotes
- quoter: bash CLI with random, list, search, add, delete, browse, TUI, import
- quotes.sql: 96 quotes (The Boys, Breaking Bad, Dark Knight, MCU, LOTR, GOT, games)
- install.sh: install/uninstall with --user/--system flags
- .gitignore: exclude .opencode, docs/superpowers, *.db, text.txt
2026-05-25 16:52:22 +02:00

198 lines
5.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
BINARY="quoter"
check_sqlite3() {
if ! command -v sqlite3 &>/dev/null; then
echo "Error: sqlite3 is required but not installed." >&2
echo "" >&2
echo "Install it with one of:" >&2
echo " Debian/Ubuntu: sudo apt install sqlite3" >&2
echo " Fedora: sudo dnf install sqlite" >&2
echo " macOS: brew install sqlite3" >&2
echo " Arch: sudo pacman -S sqlite" >&2
exit 1
fi
echo " sqlite3: $(sqlite3 --version | head -c1; echo)"
}
check_optional_deps() {
local missing=()
if ! command -v fzf &>/dev/null; then
missing+=("fzf")
else
echo " fzf: $(fzf --version 2>/dev/null | head -c1; echo)"
fi
if ! command -v gum &>/dev/null; then
missing+=("gum")
else
echo " gum: $(gum --version 2>/dev/null | head -c1; echo)"
fi
if [[ ${#missing[@]} -gt 0 ]]; then
echo ""
echo " Note: Optional TUI dependencies not found: ${missing[*]}"
echo " quoter works without them, but for the best experience:"
echo ""
if [[ " ${missing[*]} " =~ " fzf " ]]; then
echo " fzf (interactive browsing & deletion):"
echo " Debian/Ubuntu: sudo apt install fzf"
echo " macOS: brew install fzf"
echo " Arch: sudo pacman -S fzf"
echo " Other: https://github.com/junegunn/fzf"
echo ""
fi
if [[ " ${missing[*]} " =~ " gum " ]]; then
echo " gum (styled display & interactive adding):"
echo " macOS: brew install gum"
echo " Arch: pacman -S gum"
echo " Other: https://github.com/charmbracelet/gum"
echo ""
fi
fi
}
do_install() {
local install_dir="$1"
echo "Installing ${BINARY}..."
check_sqlite3
if [[ "$install_dir" == "/usr/local/bin" ]]; then
if [[ $EUID -ne 0 ]]; then
echo " System install requires sudo. Re-running with elevated privileges..."
exec sudo "$0" --system
fi
fi
if [[ ! -d "$install_dir" ]]; then
echo " Creating directory: $install_dir"
mkdir -p "$install_dir"
fi
if [[ -f "$install_dir/$BINARY" ]]; then
echo " Updating existing installation at $install_dir/$BINARY"
else
echo " Installing to $install_dir/$BINARY"
fi
cp "$SCRIPT_DIR/$BINARY" "$install_dir/$BINARY"
chmod +x "$install_dir/$BINARY"
local data_dir="$HOME/.local/share/quoter"
mkdir -p "$data_dir"
if [[ -f "$SCRIPT_DIR/quotes.sql" ]]; then
cp "$SCRIPT_DIR/quotes.sql" "$data_dir/quotes.sql"
echo " Default quotes installed to $data_dir/quotes.sql"
fi
echo ""
echo " ${BINARY} installed successfully to $install_dir/$BINARY"
echo ""
check_optional_deps
echo ""
if ! echo "$PATH" | tr ':' '\n' | grep -qx "$install_dir"; then
echo " Note: $install_dir is not in your PATH."
echo " Add it by running:"
echo " echo 'export PATH=\"$install_dir:\$PATH\"' >> ~/.bashrc"
echo " source ~/.bashrc"
echo ""
fi
echo " Run ${BINARY} to get a random quote!"
}
do_uninstall() {
local found=0
echo "Uninstalling ${BINARY}..."
for dir in "$HOME/.local/bin" "/usr/local/bin"; do
if [[ -f "$dir/$BINARY" ]]; then
echo " Removing $dir/$BINARY"
rm -f "$dir/$BINARY"
found=1
fi
done
local data_dir="$HOME/.local/share/quoter"
if [[ -d "$data_dir" ]]; then
read -rp " Remove all quote data at $data_dir? [y/N] " confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
rm -rf "$data_dir"
echo " Data directory removed."
else
echo " Data directory kept at $data_dir"
fi
fi
if [[ "$found" -eq 0 ]]; then
echo " ${BINARY} was not found in standard locations."
else
echo ""
echo " ${BINARY} has been uninstalled."
fi
}
show_help() {
cat << HELP
${BINARY} installer
Usage:
$(basename "$0") [option]
Options:
--user Install to ~/.local/bin (default)
--system Install to /usr/local/bin (requires sudo)
--uninstall Remove ${BINARY} and optionally its data
--help Show this help
Data is stored in: ~/.local/share/quoter/quoter.db
HELP
}
ACTION="user"
while [[ $# -gt 0 ]]; do
case "$1" in
--user)
ACTION="user"
shift
;;
--system)
ACTION="system"
shift
;;
--uninstall)
ACTION="uninstall"
shift
;;
--help|-h)
show_help
exit 0
;;
*)
echo "Unknown option: $1" >&2
show_help >&2
exit 1
;;
esac
done
case "$ACTION" in
user)
do_install "$HOME/.local/bin"
;;
system)
do_install "/usr/local/bin"
;;
uninstall)
do_uninstall
;;
esac