Files
finish/docs/install.sh
michael1986 08b76124e2
Some checks failed
Docker Build and Push / build-and-push (push) Has been cancelled
Tests / test (bash) (push) Has been cancelled
Tests / test (zsh) (push) Has been cancelled
Tests / lint (push) Has been cancelled
Tests / docker (push) Has been cancelled
typo fix
2025-12-02 09:10:02 +01:00

199 lines
5.6 KiB
Bash

#!/bin/sh
# finishte.sh installer
# Usage: curl -sSL https://git.appmodel.nl/Tour/finish/raw/branch/main/docs/install.sh | bash
set -e
ACSH_VERSION="v0.5.0"
BRANCH_OR_VERSION=${1:-main}
REPO_URL="https://git.appmodel.nl/Tour/finish/raw/branch"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo_green() {
printf "${GREEN}%s${NC}\n" "$1"
}
echo_error() {
printf "${RED}ERROR: %s${NC}\n" "$1" >&2
}
echo_warning() {
printf "${YELLOW}WARNING: %s${NC}\n" "$1"
}
# Detect the current shell
detect_shell() {
if [ -n "$ZSH_VERSION" ]; then
echo "zsh"
elif [ -n "$BASH_VERSION" ]; then
echo "bash"
else
parent_shell=$(ps -p $PPID -o comm= 2>/dev/null || echo "")
case "$parent_shell" in
*zsh*) echo "zsh" ;;
*bash*) echo "bash" ;;
*) echo "unknown" ;;
esac
fi
}
# Check dependencies
check_dependencies() {
local missing=""
if ! command -v curl > /dev/null 2>&1 && ! command -v wget > /dev/null 2>&1; then
missing="${missing}curl or wget, "
fi
if ! command -v jq > /dev/null 2>&1; then
missing="${missing}jq, "
fi
if ! command -v bc > /dev/null 2>&1; then
missing="${missing}bc, "
fi
if [ -n "$missing" ]; then
echo_error "Missing dependencies: ${missing%, }"
echo ""
echo "Install them with:"
echo " Ubuntu/Debian: sudo apt-get install curl jq bc bash-completion"
echo " CentOS/RHEL: sudo yum install curl jq bc bash-completion"
echo " macOS: brew install jq bc bash-completion"
return 1
fi
return 0
}
# Download file
download_file() {
local url="$1"
local output="$2"
if command -v curl > /dev/null 2>&1; then
curl -fsSL "$url" -o "$output"
elif command -v wget > /dev/null 2>&1; then
wget -q -O "$output" "$url"
else
echo_error "Neither curl nor wget is available"
return 1
fi
}
# Main installation
main() {
echo_green "=========================================="
echo_green " finishte.sh Installation"
echo_green " Version: $ACSH_VERSION"
echo_green "=========================================="
echo ""
# Detect shell
SHELL_TYPE=$(detect_shell)
case "$SHELL_TYPE" in
zsh)
SCRIPT_NAME="finishte.zsh"
RC_FILE="$HOME/.zshrc"
;;
bash)
SCRIPT_NAME="finishte.sh"
RC_FILE="$HOME/.bashrc"
;;
*)
echo_error "Unsupported shell. Currently only bash and zsh are supported."
exit 1
;;
esac
echo "Detected shell: $SHELL_TYPE"
# Check dependencies
echo "Checking dependencies..."
if ! check_dependencies; then
exit 1
fi
echo_green "✓ All dependencies found"
echo ""
# Determine installation location
if [ -d "$HOME/.local/bin" ]; then
INSTALL_LOCATION="$HOME/.local/bin/finishte"
# Add to PATH if not already there
if ! echo "$PATH" | grep -q "$HOME/.local/bin"; then
echo_warning "$HOME/.local/bin is not in PATH"
if [ ! -f "$RC_FILE" ] || ! grep -q ".local/bin" "$RC_FILE"; then
echo "Adding $HOME/.local/bin to PATH in $RC_FILE"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$RC_FILE"
fi
fi
elif [ -w "/usr/local/bin" ]; then
INSTALL_LOCATION="/usr/local/bin/finishte"
else
echo_error "Cannot write to /usr/local/bin and $HOME/.local/bin doesn't exist"
echo "Please create $HOME/.local/bin or run with sudo"
exit 1
fi
# Create directory if needed
mkdir -p "$(dirname "$INSTALL_LOCATION")"
# Download script
echo "Downloading finishte.sh..."
URL="$REPO_URL/$BRANCH_OR_VERSION/$SCRIPT_NAME"
if ! download_file "$URL" "$INSTALL_LOCATION"; then
echo_error "Failed to download from $URL"
exit 1
fi
chmod +x "$INSTALL_LOCATION"
echo_green "✓ Installed to $INSTALL_LOCATION"
echo ""
# Check bash-completion
if [ "$SHELL_TYPE" = "bash" ]; then
if ! command -v _init_completion > /dev/null 2>&1; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
echo_warning "bash-completion not loaded. Add to $RC_FILE:"
echo " source /usr/share/bash-completion/bash_completion"
elif [ -f /etc/bash_completion ]; then
echo_warning "bash-completion not loaded. Add to $RC_FILE:"
echo " source /etc/bash_completion"
else
echo_warning "bash-completion not found. Install it for best experience:"
echo " sudo apt-get install bash-completion # Ubuntu/Debian"
fi
echo ""
fi
fi
# Run finish install
echo "Running finish installation..."
if "$INSTALL_LOCATION" install; then
echo ""
echo_green "=========================================="
echo_green " Installation Complete!"
echo_green "=========================================="
echo ""
echo "Next steps:"
echo " 1. Reload your shell configuration:"
echo " source $RC_FILE"
echo ""
echo " 2. Select a language model:"
echo " finish model"
echo ""
echo " 3. Start using by pressing Tab twice after any command"
echo ""
echo "Documentation: https://git.appmodel.nl/Tour/finish/finish"
else
echo_error "Installation failed. Please check the output above."
exit 1
fi
}
main "$@"