Compare commits
11 Commits
fbaebfaae2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97f224746c | ||
|
|
c727d8e1f2 | ||
|
|
85fec83f2c | ||
|
|
1c682a338c | ||
|
|
62cb59e645 | ||
|
|
b60850ef14 | ||
|
|
e7e64f6838 | ||
|
|
4f27a626a6 | ||
|
|
e2a3cf4c5d | ||
|
|
811f1b800c | ||
|
|
979977d16e |
44
AGENTS.md
Normal file
44
AGENTS.md
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# Agent Instructions for GitHub Binary Installers
|
||||||
|
|
||||||
|
## When to Use the Installer Creation Guide
|
||||||
|
|
||||||
|
When a user requests the creation of an installer script for a binary hosted on GitHub releases, follow these steps:
|
||||||
|
|
||||||
|
1. **Check Existing Installers**: First, verify if an installer for the requested tool already exists in the repository by checking the project files.
|
||||||
|
|
||||||
|
2. **Use the Guide**: If no installer exists, use the `INSTALLER_CREATION_GUIDE.md` as the primary reference for creating the new installer.
|
||||||
|
|
||||||
|
3. **Follow the Template**: Strictly adhere to the structure, functions, and patterns outlined in the guide. Do not deviate from the established conventions.
|
||||||
|
|
||||||
|
4. **Adapt Placeholders**: Replace all placeholders (`[tool]`, `[Tool Name]`, `[TOOL]`, `[owner]/[repo]`) with the actual values for the requested binary.
|
||||||
|
|
||||||
|
5. **Verify GitHub Releases**: Ensure the binary naming convention and download URLs match the actual GitHub release assets.
|
||||||
|
|
||||||
|
6. **Test the Script**: After creation, the script should be tested to ensure it works correctly on the target systems.
|
||||||
|
|
||||||
|
7. **Update Documentation**: Add appropriate usage examples and next steps specific to the tool being installed.
|
||||||
|
|
||||||
|
## Key Requirements
|
||||||
|
|
||||||
|
- **System-Wide Preference**: Always prefer system-wide installation (`/usr/local/bin`) over user-specific installation.
|
||||||
|
- **Binary-Only**: Disable package manager installation to ensure the latest version from GitHub is used.
|
||||||
|
- **Version Management**: Implement proper version symlinks for multiple version support.
|
||||||
|
- **Conflict Resolution**: Detect and offer to remove conflicting user bin installations.
|
||||||
|
- **Command-Line Options**: Support `--version`, `--force`, and `--reinstall` options.
|
||||||
|
- **Error Handling**: Include comprehensive error checking and user-friendly messages.
|
||||||
|
|
||||||
|
## File Naming Convention
|
||||||
|
|
||||||
|
Name the installer script as `install-[tool-name].sh` (e.g., `install-my-tool.sh`).
|
||||||
|
|
||||||
|
## Integration
|
||||||
|
|
||||||
|
After creating the installer:
|
||||||
|
1. Add it to the repository
|
||||||
|
2. Update any relevant README files to reference the new installer
|
||||||
|
3. Ensure the script is executable (`chmod +x install-[tool-name].sh`)
|
||||||
|
|
||||||
|
## Reference
|
||||||
|
|
||||||
|
See `INSTALLER_CREATION_GUIDE.md` for complete implementation details and code templates.</content>
|
||||||
|
<parameter name="filePath">AGENTS.md
|
||||||
@@ -1,192 +0,0 @@
|
|||||||
# Borg CLI Installer
|
|
||||||
|
|
||||||
A comprehensive installer script for Borg CLI that supports multiple Linux distributions and installation methods.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- **Version Checking**: Only downloads and installs if newer version is available
|
|
||||||
- **Multiple Installation Methods**:
|
|
||||||
- Package manager (apt, yum, dnf, pacman, zypper)
|
|
||||||
- Binary download from GitHub releases
|
|
||||||
- **Cross-Platform Support**: Debian, Ubuntu, RHEL, CentOS, Fedora, Arch, openSUSE
|
|
||||||
- **Architecture Support**: x86_64 (amd64), ARM64, ARM
|
|
||||||
- **Automatic Updates**: Fetches latest version from GitHub API
|
|
||||||
- **Force Reinstall**: Option to force reinstall even if up-to-date
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
### Basic Usage
|
|
||||||
```bash
|
|
||||||
# Install latest version (only if newer than current)
|
|
||||||
./install-borg-cli.sh
|
|
||||||
|
|
||||||
# Install specific version
|
|
||||||
./install-borg-cli.sh -v 1.4.2
|
|
||||||
|
|
||||||
# Force reinstall even if up-to-date
|
|
||||||
./install-borg-cli.sh --force
|
|
||||||
```
|
|
||||||
|
|
||||||
### Installation Methods
|
|
||||||
```bash
|
|
||||||
# Force installation from package manager
|
|
||||||
./install-borg-cli.sh --package
|
|
||||||
|
|
||||||
# Force installation from binary
|
|
||||||
./install-borg-cli.sh --binary
|
|
||||||
```
|
|
||||||
|
|
||||||
### Help
|
|
||||||
```bash
|
|
||||||
./install-borg-cli.sh --help
|
|
||||||
```
|
|
||||||
|
|
||||||
## Installation Logic
|
|
||||||
|
|
||||||
### Version Checking
|
|
||||||
1. **Check Current Version**: Detects installed Borg CLI version
|
|
||||||
2. **Fetch Latest**: Gets latest version from GitHub API
|
|
||||||
3. **Compare Versions**: Only proceeds if newer version available
|
|
||||||
4. **Force Override**: `--force` flag bypasses version check
|
|
||||||
|
|
||||||
### Installation Priority
|
|
||||||
1. **Package Manager** (preferred):
|
|
||||||
- Debian/Ubuntu: Checks for official borgbackup package
|
|
||||||
- RHEL/CentOS/Fedora: Checks for available borgbackup package
|
|
||||||
- Arch Linux: Available in pacman repositories
|
|
||||||
- openSUSE: Checks for available borgbackup package
|
|
||||||
|
|
||||||
2. **Binary Download** (fallback):
|
|
||||||
- Downloads platform-specific binary from GitHub releases
|
|
||||||
- Supports x86_64, ARM64, ARM architectures
|
|
||||||
- Installs to `/usr/local/bin/borg` or `~/bin/borg`
|
|
||||||
|
|
||||||
## File Locations
|
|
||||||
|
|
||||||
### Installation Directory
|
|
||||||
- Binary: `/usr/local/bin/borg` (system) or `~/bin/borg` (user)
|
|
||||||
- Symlink: `borg -> borg-1.4.2` (version-specific)
|
|
||||||
|
|
||||||
## Version Comparison
|
|
||||||
|
|
||||||
The installer uses semantic version comparison:
|
|
||||||
- **Format**: `X.Y.Z` (e.g., `1.4.2`)
|
|
||||||
- **Logic**: Compares major, minor, patch versions
|
|
||||||
- **Build Info**: Ignores build hashes/identifiers
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
```bash
|
|
||||||
# Current: 1.4.0, Latest: 1.4.2 → Update needed
|
|
||||||
# Current: 1.4.2, Latest: 1.4.2 → No update needed
|
|
||||||
# Current: 1.4.3, Latest: 1.4.2 → No update needed (newer installed)
|
|
||||||
```
|
|
||||||
|
|
||||||
## System Requirements
|
|
||||||
|
|
||||||
### Required
|
|
||||||
- `curl` or `wget` (for downloading)
|
|
||||||
- `sudo` access (for system-wide installation)
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
- Package manager access (for package installations)
|
|
||||||
- Internet connection (for downloading releases)
|
|
||||||
|
|
||||||
## Supported Distributions
|
|
||||||
|
|
||||||
### Package Manager Support
|
|
||||||
- **Debian/Ubuntu**: `borgbackup` package
|
|
||||||
- **RHEL/CentOS/Fedora**: `borgbackup` package
|
|
||||||
- **Arch Linux**: `borg` package
|
|
||||||
- **openSUSE**: `borgbackup` package
|
|
||||||
|
|
||||||
### Binary Support
|
|
||||||
- **Linux x86_64**: `borg-linux-glibc231-x86_64`
|
|
||||||
- **Linux ARM64**: `borg-linux-glibc231-aarch64`
|
|
||||||
- **Linux ARM**: `borg-linux-glibc231-armv7`
|
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
### Version Detection Issues
|
|
||||||
```bash
|
|
||||||
# Check current version manually
|
|
||||||
borg --version
|
|
||||||
|
|
||||||
# Force reinstall if version detection fails
|
|
||||||
./install-borg-cli.sh --force
|
|
||||||
```
|
|
||||||
|
|
||||||
### Permission Issues
|
|
||||||
```bash
|
|
||||||
# For system installation
|
|
||||||
sudo ./install-borg-cli.sh --binary
|
|
||||||
```
|
|
||||||
|
|
||||||
### PATH Issues
|
|
||||||
```bash
|
|
||||||
# Check if user bin is in PATH
|
|
||||||
echo $PATH | grep -q "$HOME/bin" && echo "OK" || echo "Add to PATH"
|
|
||||||
|
|
||||||
# Test borg command
|
|
||||||
which borg
|
|
||||||
borg --version
|
|
||||||
```
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
### Typical Workflow
|
|
||||||
```bash
|
|
||||||
# Check if update needed
|
|
||||||
./install-borg-cli.sh
|
|
||||||
|
|
||||||
# Output if up-to-date:
|
|
||||||
# [SUCCESS] You already have latest version (1.4.2)
|
|
||||||
# [SUCCESS] No installation needed. Exiting.
|
|
||||||
|
|
||||||
# Output if update available:
|
|
||||||
# [INFO] Current version: 1.4.0 (user)
|
|
||||||
# [INFO] Latest version: 1.4.2
|
|
||||||
# [INFO] Newer version available: 1.4.2 > 1.4.0
|
|
||||||
# [SUCCESS] Installation completed successfully!
|
|
||||||
```
|
|
||||||
|
|
||||||
### Force Binary Installation
|
|
||||||
```bash
|
|
||||||
# Force binary installation
|
|
||||||
./install-borg-cli.sh --force --binary
|
|
||||||
|
|
||||||
# Output:
|
|
||||||
# [SUCCESS] Borg CLI binary installed successfully
|
|
||||||
# Next steps:
|
|
||||||
# 1. Test installation: borg --version
|
|
||||||
# 2. Initialize repository: borg init --encryption=repokey /path/to/repo
|
|
||||||
# 3. Create backup: borg create /path/to/repo::backup-name /path/to/backup
|
|
||||||
# 4. Use Borg CLI: borg --help
|
|
||||||
```
|
|
||||||
|
|
||||||
## Integration with Setup Script
|
|
||||||
|
|
||||||
The Borg CLI installer can be integrated with backup setup scripts:
|
|
||||||
- Automatically called when Borg CLI is needed
|
|
||||||
- Respects user preferences for installation location
|
|
||||||
- Provides clear feedback on installation strategy
|
|
||||||
- Handles both new installations and updates
|
|
||||||
|
|
||||||
## Security Features
|
|
||||||
|
|
||||||
- **Official Releases**: Downloads from official GitHub releases
|
|
||||||
- **Package Verification**: Uses official package repositories
|
|
||||||
- **Proper Permissions**: Sets appropriate file ownership and permissions
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
To add support for new distributions or architectures:
|
|
||||||
|
|
||||||
1. Update `detect_os()` function for new package managers
|
|
||||||
2. Add architecture detection in `get_arch()` function
|
|
||||||
3. Update installation methods in `install_borg_from_*()` functions
|
|
||||||
4. Test with target distribution
|
|
||||||
5. Update documentation
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
This installer script follows the same license as Borg (BSD-3-Clause).
|
|
||||||
@@ -1,247 +0,0 @@
|
|||||||
# Git Credential Manager Installer
|
|
||||||
|
|
||||||
A comprehensive installer script for Git Credential Manager (GCM) that supports multiple Linux distributions and installation methods.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- **Version Checking**: Only downloads and installs if newer version is available
|
|
||||||
- **Multiple Installation Methods**:
|
|
||||||
- Package manager (apt, yum, dnf, pacman, zypper)
|
|
||||||
- DEB packages (Debian/Ubuntu)
|
|
||||||
- Tar.gz archives (universal)
|
|
||||||
- **Cross-Platform Support**: Debian, Ubuntu, RHEL, CentOS, Fedora, Arch, openSUSE
|
|
||||||
- **Architecture Support**: x86_64 (amd64), ARM64 (arm64), ARM (armv7l)
|
|
||||||
- **Automatic Updates**: Fetches latest version from GitHub releases
|
|
||||||
- **Force Reinstall**: Option to force reinstallation even if up-to-date
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
### Basic Usage
|
|
||||||
```bash
|
|
||||||
# Install latest version (only if newer than current)
|
|
||||||
./install-git-credential-manager.sh
|
|
||||||
|
|
||||||
# Install specific version
|
|
||||||
./install-git-credential-manager.sh -v v2.6.0
|
|
||||||
|
|
||||||
# Force reinstall even if up-to-date
|
|
||||||
./install-git-credential-manager.sh --force
|
|
||||||
```
|
|
||||||
|
|
||||||
### Installation Methods
|
|
||||||
```bash
|
|
||||||
# Force installation from package manager
|
|
||||||
./install-git-credential-manager.sh --package
|
|
||||||
|
|
||||||
# Force installation from DEB package
|
|
||||||
./install-git-credential-manager.sh --deb
|
|
||||||
|
|
||||||
# Force installation from tarball
|
|
||||||
./install-git-credential-manager.sh --tarball
|
|
||||||
```
|
|
||||||
|
|
||||||
### Check Configuration Only
|
|
||||||
```bash
|
|
||||||
# Check current Git credential configuration without installing
|
|
||||||
./install-git-credential-manager.sh --checks
|
|
||||||
|
|
||||||
# Example output:
|
|
||||||
# ✓ Global credential helper: manager
|
|
||||||
# ✓ GitHub credential helper configured
|
|
||||||
# ✗ GitLab credential helper not configured
|
|
||||||
# ✗ Azure DevOps useHttpPath not configured
|
|
||||||
# ✗ Bitbucket credential helper not configured
|
|
||||||
# ✓ Gitea credential helpers configured (1 found)
|
|
||||||
#
|
|
||||||
# Run these commands to complete the configuration:
|
|
||||||
# git config --global credential.https://gitlab.com.helper manager
|
|
||||||
# git config --global credential.https://dev.azure.com.useHttpPath true
|
|
||||||
# git config --global credential.https://bitbucket.org.helper manager
|
|
||||||
```
|
|
||||||
|
|
||||||
### Help
|
|
||||||
```bash
|
|
||||||
./install-git-credential-manager.sh --help
|
|
||||||
```
|
|
||||||
|
|
||||||
## Installation Logic
|
|
||||||
|
|
||||||
### Version Checking
|
|
||||||
1. **Check Current Version**: Detects installed GCM version
|
|
||||||
2. **Fetch Latest**: Gets latest version from GitHub API
|
|
||||||
3. **Compare Versions**: Only proceeds if newer version available
|
|
||||||
4. **Force Override**: `--force` flag bypasses version check
|
|
||||||
|
|
||||||
### Installation Priority
|
|
||||||
1. **Package Manager** (preferred):
|
|
||||||
- Debian/Ubuntu: `apt install git-credential-manager`
|
|
||||||
- Arch Linux: `pacman -S git-credential-manager`
|
|
||||||
- Others: Falls back to manual installation
|
|
||||||
|
|
||||||
2. **Distribution-Specific**:
|
|
||||||
- Debian/Ubuntu: Downloads `.deb` package
|
|
||||||
- Other Linux: Downloads `.tar.gz` archive
|
|
||||||
|
|
||||||
3. **Universal Fallback**:
|
|
||||||
- Downloads tarball for any architecture
|
|
||||||
- Extracts and installs binary to `/usr/local/bin`
|
|
||||||
|
|
||||||
## System Requirements
|
|
||||||
|
|
||||||
### Required
|
|
||||||
- `curl` or `wget` (for downloading)
|
|
||||||
- `sudo` access (for system-wide installation)
|
|
||||||
- Git (for configuration)
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
- Package manager access (for package installations)
|
|
||||||
- Internet connection (for downloading releases)
|
|
||||||
|
|
||||||
## File Locations
|
|
||||||
|
|
||||||
### Installation Directory
|
|
||||||
- Binary: `/usr/local/bin/git-credential-manager`
|
|
||||||
- Symlink: `/usr/local/bin/git-credential-manager-core`
|
|
||||||
- Libraries: `/usr/local/bin/lib*.so`
|
|
||||||
|
|
||||||
### Configuration
|
|
||||||
- Git config: `~/.gitconfig`
|
|
||||||
- Credential storage: Platform-specific secure storage
|
|
||||||
|
|
||||||
## Version Comparison
|
|
||||||
|
|
||||||
The installer uses semantic version comparison:
|
|
||||||
- **Format**: `vX.Y.Z` (e.g., `v2.6.1`)
|
|
||||||
- **Logic**: Compares major, minor, patch versions
|
|
||||||
- **Build Info**: Ignores build hashes/identifiers
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
```bash
|
|
||||||
# Current: v2.6.1, Latest: v2.6.1 → No update needed
|
|
||||||
# Current: v2.6.0, Latest: v2.6.1 → Update needed
|
|
||||||
# Current: v2.6.1, Latest: v2.6.0 → No update needed (newer installed)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Integration with Setup Script
|
|
||||||
|
|
||||||
The installer is automatically integrated with the main Git repository setup script:
|
|
||||||
|
|
||||||
1. **Detection**: Checks for existing credential managers
|
|
||||||
2. **Offer Installation**: Prompts to install GCM if none found
|
|
||||||
3. **Configuration**: Sets up Git to use the credential manager
|
|
||||||
4. **Domain-Specific**: Configures for specific Gitea instances
|
|
||||||
|
|
||||||
## Security Features
|
|
||||||
|
|
||||||
- **Official Releases**: Downloads from official GitHub releases
|
|
||||||
- **Checksum Verification**: Can verify package integrity (future enhancement)
|
|
||||||
- **Secure Storage**: Uses OS keyring for credential storage
|
|
||||||
- **No Plain Text**: Never stores credentials in plain text
|
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
### Version Detection Issues
|
|
||||||
```bash
|
|
||||||
# Check current version manually
|
|
||||||
git-credential-manager --version
|
|
||||||
|
|
||||||
# Force reinstall if version detection fails
|
|
||||||
./install-git-credential-manager.sh --force
|
|
||||||
```
|
|
||||||
|
|
||||||
### Permission Issues
|
|
||||||
```bash
|
|
||||||
# Ensure proper permissions
|
|
||||||
sudo chown root:root /usr/local/bin/git-credential-manager
|
|
||||||
sudo chmod 755 /usr/local/bin/git-credential-manager
|
|
||||||
```
|
|
||||||
|
|
||||||
### Network Issues
|
|
||||||
```bash
|
|
||||||
# Use specific version if network blocks GitHub API
|
|
||||||
./install-git-credential-manager.sh -v v2.6.1
|
|
||||||
```
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
### Typical Workflow
|
|
||||||
```bash
|
|
||||||
# Check if update needed
|
|
||||||
./install-git-credential-manager.sh
|
|
||||||
|
|
||||||
# Output if up-to-date:
|
|
||||||
# [SUCCESS] You already have the latest version (v2.6.1)
|
|
||||||
# [SUCCESS] No installation needed. Exiting.
|
|
||||||
|
|
||||||
# Output if update available:
|
|
||||||
# [INFO] Current version: v2.6.0
|
|
||||||
# [INFO] Latest version: v2.6.1
|
|
||||||
# [INFO] Newer version available: v2.6.1 > v2.6.0
|
|
||||||
# [SUCCESS] Installation completed successfully!
|
|
||||||
```
|
|
||||||
|
|
||||||
### Automated Installation
|
|
||||||
```bash
|
|
||||||
# Script for automated setup
|
|
||||||
#!/bin/bash
|
|
||||||
./install-git-credential-manager.sh --force --package
|
|
||||||
git config --global credential.helper manager
|
|
||||||
```
|
|
||||||
|
|
||||||
## Post-Installation Configuration Check
|
|
||||||
|
|
||||||
After successful installation, the installer automatically checks and configures all required Git presets:
|
|
||||||
|
|
||||||
### ✅ Preset Verification
|
|
||||||
The installer checks these configurations:
|
|
||||||
- **Global credential helper**: `credential.helper manager`
|
|
||||||
- **GitHub**: `credential.https://github.com.helper manager`
|
|
||||||
- **GitLab**: `credential.https://gitlab.com.helper manager`
|
|
||||||
- **Bitbucket**: `credential.https://bitbucket.org.helper manager`
|
|
||||||
- **Azure DevOps**: `credential.https://dev.azure.com.useHttpPath true`
|
|
||||||
- **Gitea servers**: Domain-specific credential helpers
|
|
||||||
|
|
||||||
### 📋 Configuration Report
|
|
||||||
The installer provides:
|
|
||||||
- **Status summary**: Shows which presets are configured (✓) or missing (✗)
|
|
||||||
- **Exact commands**: Lists the exact `git config` commands needed
|
|
||||||
- **Testing guidance**: Commands to verify the configuration
|
|
||||||
- **Service-specific advice**: Tailored guidance for different Git hosting services
|
|
||||||
|
|
||||||
### 🔧 Manual Configuration
|
|
||||||
If presets are missing, the installer shows exactly what to run:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Example output for missing presets:
|
|
||||||
Run these commands to complete the configuration:
|
|
||||||
git config --global credential.https://gitlab.com.helper manager
|
|
||||||
git config --global credential.https://dev.azure.com.useHttpPath true
|
|
||||||
git config --global credential.https://bitbucket.org.helper manager
|
|
||||||
# For Gitea servers, configure domain-specific helper:
|
|
||||||
git config --global credential.https://go-gitea.mywire.org.helper manager
|
|
||||||
|
|
||||||
After configuring, test with:
|
|
||||||
git config --global --list | grep credential
|
|
||||||
```
|
|
||||||
|
|
||||||
## Integration with Setup Script
|
|
||||||
|
|
||||||
The installer integrates seamlessly with the main setup script:
|
|
||||||
- Automatically called when Git Credential Manager is needed
|
|
||||||
- Respects user preferences for installation location
|
|
||||||
- Provides clear feedback on installation strategy
|
|
||||||
- Handles both new installations and updates
|
|
||||||
- **Performs comprehensive preset checking and configuration**
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
To add support for new distributions or architectures:
|
|
||||||
|
|
||||||
1. Update `detect_os()` function for new package managers
|
|
||||||
2. Add architecture detection in `get_arch()` function
|
|
||||||
3. Update installation methods in `install_from_*()` functions
|
|
||||||
4. Test with target distribution
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
This installer script follows the same license as Git Credential Manager (MIT).
|
|
||||||
@@ -1,217 +0,0 @@
|
|||||||
# Gitea Server Installer
|
|
||||||
|
|
||||||
A comprehensive installer script for Gitea server that supports multiple Linux distributions and installation methods.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- **Version Checking**: Only downloads and installs if newer version is available
|
|
||||||
- **Multiple Installation Methods**:
|
|
||||||
- Package manager (apt, yum, dnf, zypper)
|
|
||||||
- Binary download from GitHub releases
|
|
||||||
- **Cross-Platform Support**: Debian, Ubuntu, RHEL, CentOS, Fedora, Arch, openSUSE
|
|
||||||
- **Architecture Support**: x86_64 (amd64), ARM64, ARM
|
|
||||||
- **Automatic Updates**: Fetches latest version from GitHub releases
|
|
||||||
- **Force Reinstall**: Option to force reinstall even if up-to-date
|
|
||||||
- **Service Setup**: Optional systemd service creation and configuration
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
### Basic Usage
|
|
||||||
```bash
|
|
||||||
# Install latest version (only if newer than current)
|
|
||||||
./install-gitea-server.sh
|
|
||||||
|
|
||||||
# Install specific version
|
|
||||||
./install-gitea-server.sh -v v1.25.0
|
|
||||||
|
|
||||||
# Force reinstall even if up-to-date
|
|
||||||
./install-gitea-server.sh --force
|
|
||||||
```
|
|
||||||
|
|
||||||
### Installation Methods
|
|
||||||
```bash
|
|
||||||
# Force installation from package manager
|
|
||||||
./install-gitea-server.sh --package
|
|
||||||
|
|
||||||
# Force installation from binary
|
|
||||||
./install-gitea-server.sh --binary
|
|
||||||
|
|
||||||
# Install and set up as systemd service
|
|
||||||
./install-gitea-server.sh --service
|
|
||||||
```
|
|
||||||
|
|
||||||
### Help
|
|
||||||
```bash
|
|
||||||
./install-gitea-server.sh --help
|
|
||||||
```
|
|
||||||
|
|
||||||
## Installation Logic
|
|
||||||
|
|
||||||
### Version Checking
|
|
||||||
1. **Check Current Version**: Detects installed Gitea version
|
|
||||||
2. **Fetch Latest**: Gets latest version from GitHub API
|
|
||||||
3. **Compare Versions**: Only proceeds if newer version available
|
|
||||||
4. **Force Override**: `--force` flag bypasses version check
|
|
||||||
|
|
||||||
### Installation Priority
|
|
||||||
1. **Package Manager** (preferred):
|
|
||||||
- Debian/Ubuntu: Uses official Gitea repository
|
|
||||||
- RHEL/CentOS/Fedora: Uses official Gitea repository
|
|
||||||
- Arch Linux: Available in AUR
|
|
||||||
- openSUSE: Uses official Gitea repository
|
|
||||||
|
|
||||||
2. **Binary Download** (fallback):
|
|
||||||
- Downloads platform-specific binary from GitHub releases
|
|
||||||
- Supports x86_64, ARM64, ARM architectures
|
|
||||||
- Installs to `/usr/local/bin/gitea`
|
|
||||||
|
|
||||||
### Service Setup
|
|
||||||
When `--service` is used:
|
|
||||||
- Creates systemd service file
|
|
||||||
- Sets up proper user/group permissions
|
|
||||||
- Creates configuration directories
|
|
||||||
- Generates basic configuration
|
|
||||||
- Enables and starts the service
|
|
||||||
|
|
||||||
## File Locations
|
|
||||||
|
|
||||||
### Installation Directory
|
|
||||||
- Binary: `/usr/local/bin/gitea`
|
|
||||||
- Service: `/etc/systemd/system/gitea.service`
|
|
||||||
- Configuration: `/etc/gitea/app.ini`
|
|
||||||
- Data: `/var/lib/gitea/data`
|
|
||||||
- Repositories: `/var/lib/gitea/data/repositories`
|
|
||||||
- Logs: `/var/lib/gitea/log`
|
|
||||||
- Attachments: `/var/lib/gitea/data/attachments`
|
|
||||||
|
|
||||||
### Configuration
|
|
||||||
The installer creates a basic configuration with:
|
|
||||||
- SQLite database (suitable for small installations)
|
|
||||||
- Security settings with generated secret key
|
|
||||||
- Local file storage
|
|
||||||
- Console logging
|
|
||||||
- Service user/group permissions
|
|
||||||
|
|
||||||
## Version Comparison
|
|
||||||
|
|
||||||
The installer uses semantic version comparison:
|
|
||||||
- **Format**: `vX.Y.Z` (e.g., `v1.25.1`)
|
|
||||||
- **Logic**: Compares major, minor, patch versions
|
|
||||||
- **Build Info**: Ignores build hashes/identifiers
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
### Typical Workflow
|
|
||||||
```bash
|
|
||||||
# Check if update needed
|
|
||||||
./install-gitea-server.sh
|
|
||||||
|
|
||||||
# Output if up-to-date:
|
|
||||||
# [SUCCESS] You already have latest version (v1.25.1)
|
|
||||||
# [SUCCESS] No installation needed. Exiting.
|
|
||||||
|
|
||||||
# Output if update available:
|
|
||||||
# [INFO] Current version: v1.25.0
|
|
||||||
# [INFO] Latest version: v1.25.1
|
|
||||||
# [INFO] Newer version available: v1.25.1 > v1.25.0
|
|
||||||
# [SUCCESS] Installation completed successfully!
|
|
||||||
```
|
|
||||||
|
|
||||||
### Service Setup
|
|
||||||
```bash
|
|
||||||
# Install and set up as service
|
|
||||||
./install-gitea-server.sh --service
|
|
||||||
|
|
||||||
# Output:
|
|
||||||
# [SUCCESS] Gitea service setup completed!
|
|
||||||
# Next steps:
|
|
||||||
# 1. Start service: sudo systemctl start gitea
|
|
||||||
# 2. Check status: sudo systemctl status gitea
|
|
||||||
# 3. View logs: sudo journalctl -u gitea -f
|
|
||||||
# 4. Configure at: /etc/gitea/app.ini
|
|
||||||
```
|
|
||||||
|
|
||||||
## System Requirements
|
|
||||||
|
|
||||||
### Required
|
|
||||||
- `curl` or `wget` (for downloading)
|
|
||||||
- `sudo` access (for system-wide installation)
|
|
||||||
- Systemd (for service setup)
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
- Package manager access (for package installations)
|
|
||||||
- Internet connection (for downloading releases)
|
|
||||||
|
|
||||||
## Security Features
|
|
||||||
|
|
||||||
- **Official Releases**: Downloads from official GitHub releases
|
|
||||||
- **Package Verification**: Uses GPG keys for package manager installations
|
|
||||||
- **Proper Permissions**: Sets appropriate file ownership and permissions
|
|
||||||
- **Service Isolation**: Runs as dedicated service user/group
|
|
||||||
|
|
||||||
## Supported Distributions
|
|
||||||
|
|
||||||
### Package Manager Support
|
|
||||||
- **Debian/Ubuntu**: Official Gitea repository with GPG verification
|
|
||||||
- **RHEL/CentOS/Fedora**: Official Gitea RPM repository
|
|
||||||
- **Arch Linux**: Available in AUR (pacman)
|
|
||||||
- **openSUSE**: Official Gitea repository
|
|
||||||
|
|
||||||
### Binary Support
|
|
||||||
- **Linux x86_64**: `gitea-1.25.1-linux-amd64`
|
|
||||||
- **Linux ARM64**: `gitea-1.25.1-linux-arm64`
|
|
||||||
- **Linux ARM**: `gitea-1.25.1-linux-arm-5`
|
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
### Version Detection Issues
|
|
||||||
```bash
|
|
||||||
# Check current version manually
|
|
||||||
gitea --version
|
|
||||||
|
|
||||||
# Force reinstall if version detection fails
|
|
||||||
./install-gitea-server.sh --force
|
|
||||||
```
|
|
||||||
|
|
||||||
### Permission Issues
|
|
||||||
```bash
|
|
||||||
# Ensure proper permissions
|
|
||||||
sudo chown root:root /usr/local/bin/gitea
|
|
||||||
sudo chmod 755 /usr/local/bin/gitea
|
|
||||||
```
|
|
||||||
|
|
||||||
### Service Issues
|
|
||||||
```bash
|
|
||||||
# Check service status
|
|
||||||
sudo systemctl status gitea
|
|
||||||
|
|
||||||
# View service logs
|
|
||||||
sudo journalctl -u gitea -f
|
|
||||||
|
|
||||||
# Restart service
|
|
||||||
sudo systemctl restart gitea
|
|
||||||
```
|
|
||||||
|
|
||||||
## Production Considerations
|
|
||||||
|
|
||||||
For production use, consider:
|
|
||||||
- Using PostgreSQL/MySQL instead of SQLite
|
|
||||||
- Configuring reverse proxy (nginx/apache)
|
|
||||||
- Setting up SSL certificates
|
|
||||||
- Adjusting firewall settings
|
|
||||||
- Regular backups
|
|
||||||
- Monitoring and log rotation
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
To add support for new distributions or architectures:
|
|
||||||
|
|
||||||
1. Update `detect_os()` function for new package managers
|
|
||||||
2. Add architecture detection in `get_arch()` function
|
|
||||||
3. Update installation methods in `install_from_*()` functions
|
|
||||||
4. Test with target distribution
|
|
||||||
5. Update documentation
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
This installer script follows the same license as Gitea (MIT).
|
|
||||||
@@ -1,205 +0,0 @@
|
|||||||
# Git Credential Managers for Gitea
|
|
||||||
|
|
||||||
Git credential managers provide secure storage and automatic retrieval of your Git credentials, eliminating the need to repeatedly enter usernames and passwords/tokens.
|
|
||||||
|
|
||||||
## Supported Credential Managers
|
|
||||||
|
|
||||||
### 1. Git Credential Manager (GCM) - Console & GUI
|
|
||||||
- **Cross-platform**: Windows, macOS, Linux
|
|
||||||
- **Official Microsoft project**
|
|
||||||
- **Console-First**: Works perfectly in terminal without GUI
|
|
||||||
- **Supports**: HTTPS authentication, personal access tokens, OAuth
|
|
||||||
- **Installation**:
|
|
||||||
```bash
|
|
||||||
# Linux (various distributions)
|
|
||||||
sudo apt install git-credential-manager # Ubuntu/Debian
|
|
||||||
sudo yum install git-credential-manager # RHEL/CentOS
|
|
||||||
sudo pacman -S git-credential-manager # Arch
|
|
||||||
|
|
||||||
# macOS
|
|
||||||
brew install git-credential-manager
|
|
||||||
|
|
||||||
# Windows
|
|
||||||
# Included with Git for Windows
|
|
||||||
```
|
|
||||||
- **Console Usage**: All operations are terminal-based, no GUI required
|
|
||||||
|
|
||||||
### 2. libsecret (Linux) - Console Only
|
|
||||||
- **Linux native**: Uses system keyring (GNOME Keyring, KWallet)
|
|
||||||
- **Console-Only**: No GUI components, pure terminal integration
|
|
||||||
- **Installation**:
|
|
||||||
```bash
|
|
||||||
# Ubuntu/Debian
|
|
||||||
sudo apt install libsecret-1-0 libsecret-1-dev
|
|
||||||
|
|
||||||
# RHEL/CentOS
|
|
||||||
sudo yum install libsecret-devel
|
|
||||||
|
|
||||||
# Configure Git
|
|
||||||
git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. osxkeychain (macOS) - Console & GUI
|
|
||||||
- **Built-in**: Uses macOS Keychain
|
|
||||||
- **Console-First**: Works in terminal, can also access GUI keychain
|
|
||||||
- **Configuration**:
|
|
||||||
```bash
|
|
||||||
git config --global credential.helper osxkeychain
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. manager (Generic)
|
|
||||||
- **Built-in**: Simple in-memory cache
|
|
||||||
- **Configuration**:
|
|
||||||
```bash
|
|
||||||
git config --global credential.helper manager
|
|
||||||
```
|
|
||||||
|
|
||||||
## Configuration for Gitea
|
|
||||||
|
|
||||||
### Method 1: Personal Access Token
|
|
||||||
1. Generate token in Gitea: User Settings → Applications → Generate Token
|
|
||||||
2. Configure Git:
|
|
||||||
```bash
|
|
||||||
git config --global credential.helper manager
|
|
||||||
# First push will prompt for username and token
|
|
||||||
```
|
|
||||||
|
|
||||||
### Method 2: Direct Credential Storage
|
|
||||||
```bash
|
|
||||||
# Store credentials for specific Gitea instance
|
|
||||||
git config --global credential.https://go-gitea.mywire.org.helper manager
|
|
||||||
```
|
|
||||||
|
|
||||||
### Method 3: Environment Variables
|
|
||||||
```bash
|
|
||||||
export GIT_USERNAME="your_username"
|
|
||||||
export GIT_PASSWORD="your_access_token"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Security Considerations
|
|
||||||
|
|
||||||
### ✅ Secure Options
|
|
||||||
- **GCM**: Encrypts credentials, integrates with OS keyring
|
|
||||||
- **libsecret/osxkeychain**: Uses system secure storage
|
|
||||||
- **Personal Access Tokens**: More secure than passwords, can be revoked
|
|
||||||
|
|
||||||
### ⚠️ Less Secure Options
|
|
||||||
- **Plain text**: Storing credentials in .netrc files
|
|
||||||
- **Environment variables**: Visible in process list
|
|
||||||
- **Cache-only**: Credentials stored in memory only
|
|
||||||
|
|
||||||
## Console-Only Operation
|
|
||||||
|
|
||||||
### How It Works Without GUI
|
|
||||||
1. **Terminal Prompts**: Git prompts for username/token in console
|
|
||||||
2. **Secure Storage**: Credentials stored in system keyring (encrypted)
|
|
||||||
3. **Automatic Retrieval**: Subsequent Git operations use stored credentials
|
|
||||||
4. **No GUI Required**: All operations happen in terminal
|
|
||||||
|
|
||||||
### Console Workflow Example
|
|
||||||
```bash
|
|
||||||
# First time - prompts in terminal
|
|
||||||
$ git push origin main
|
|
||||||
Username for 'https://go-gitea.mywire.org': kadu
|
|
||||||
Password for 'https://kadu@go-gitea.mywire.org': your_access_token
|
|
||||||
|
|
||||||
# Subsequent times - automatic
|
|
||||||
$ git push origin main
|
|
||||||
Everything up-to-date
|
|
||||||
|
|
||||||
# No more prompts!
|
|
||||||
```
|
|
||||||
|
|
||||||
## Integration with Setup Script
|
|
||||||
|
|
||||||
The setup script can:
|
|
||||||
1. Detect available credential managers
|
|
||||||
2. Configure Git to use the best available option
|
|
||||||
3. Guide users through secure credential setup
|
|
||||||
4. Test credential storage and retrieval
|
|
||||||
5. **Check all required Git presets after installation**
|
|
||||||
6. **Provide exact commands to complete configuration**
|
|
||||||
|
|
||||||
## Post-Installation Configuration Check
|
|
||||||
|
|
||||||
The installer automatically checks and configures these Git presets:
|
|
||||||
|
|
||||||
### ✅ Required Presets
|
|
||||||
- `credential.helper manager` - Global credential helper
|
|
||||||
- `credential.https://github.com.helper manager` - GitHub specific
|
|
||||||
- `credential.https://gitlab.com.helper manager` - GitLab specific
|
|
||||||
- `credential.https://bitbucket.org.helper manager` - Bitbucket specific
|
|
||||||
- `credential.https://dev.azure.com.useHttpPath true` - Azure DevOps
|
|
||||||
- Domain-specific helpers for Gitea servers
|
|
||||||
|
|
||||||
### 📋 Configuration Summary
|
|
||||||
After installation, the installer provides:
|
|
||||||
- **Status of each preset** (✓ configured, ✗ missing)
|
|
||||||
- **Exact commands** to complete configuration
|
|
||||||
- **Testing commands** to verify setup
|
|
||||||
- **Usage guidance** for different Git hosting services
|
|
||||||
5. Work entirely in console mode
|
|
||||||
|
|
||||||
## Best Practices for Gitea
|
|
||||||
|
|
||||||
1. **Use Personal Access Tokens** instead of passwords
|
|
||||||
2. **Set token expiration** and permissions appropriately
|
|
||||||
3. **Use HTTPS with credential manager** for most users (console-friendly)
|
|
||||||
4. **Use SSH keys** for automated/scripted access
|
|
||||||
5. **Regularly rotate tokens** for security
|
|
||||||
6. **Console environments**: All credential managers work perfectly in SSH/remote terminals
|
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
### Common Issues
|
|
||||||
- **Token not working**: Ensure token has required scopes (repo, user)
|
|
||||||
- **Credential manager not found**: Install appropriate package for your OS
|
|
||||||
- **HTTPS certificate errors**: Configure Git to trust your Gitea certificate
|
|
||||||
- **Authentication prompts**: Check credential helper configuration
|
|
||||||
|
|
||||||
### Debug Commands
|
|
||||||
```bash
|
|
||||||
# Test credential storage
|
|
||||||
git credential fill
|
|
||||||
|
|
||||||
# Check current configuration
|
|
||||||
git config --global --show-origin --get credential.helper
|
|
||||||
|
|
||||||
# Clear stored credentials
|
|
||||||
git credential-cache exit
|
|
||||||
```
|
|
||||||
|
|
||||||
## Example Workflow (Console Only)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 1. Configure credential manager
|
|
||||||
git config --global credential.helper manager
|
|
||||||
|
|
||||||
# 2. First time authentication (console prompts)
|
|
||||||
$ git clone https://go-gitea.mywire.org/username/repo.git
|
|
||||||
Username for 'https://go-gitea.mywire.org': your_username
|
|
||||||
Password for 'https://go-gitea.mywire.org': your_access_token
|
|
||||||
|
|
||||||
# 3. Subsequent operations use stored credentials automatically
|
|
||||||
$ git pull
|
|
||||||
Already up to date.
|
|
||||||
|
|
||||||
$ git push
|
|
||||||
Everything up-to-date
|
|
||||||
|
|
||||||
# No more prompts - works in any terminal/SSH session!
|
|
||||||
```
|
|
||||||
|
|
||||||
## Remote/SSH Console Usage
|
|
||||||
|
|
||||||
Credential managers work perfectly in remote SSH sessions:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# SSH into remote server
|
|
||||||
ssh user@server
|
|
||||||
|
|
||||||
# Git operations work with stored credentials
|
|
||||||
cd /project
|
|
||||||
git pull # Uses stored credentials, no prompts
|
|
||||||
git push # Automatic authentication
|
|
||||||
```
|
|
||||||
621
INSTALLER_CREATION_GUIDE.md
Normal file
621
INSTALLER_CREATION_GUIDE.md
Normal file
@@ -0,0 +1,621 @@
|
|||||||
|
# GitHub Binary Installer Template
|
||||||
|
|
||||||
|
This document provides instructions for creating a new installer script for binaries hosted on GitHub releases, following the patterns established in the git-credential-manager, borg-cli, and tea-cli installers.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
The installer should:
|
||||||
|
- Prefer system-wide installation (/usr/local/bin) for all users
|
||||||
|
- Fall back to user-specific installation ($HOME/bin) if no sudo access
|
||||||
|
- Handle version management with symlinks
|
||||||
|
- Warn about and offer to remove conflicting user bin installations
|
||||||
|
- Support command-line options for version specification and reinstallation
|
||||||
|
- Always use GitHub releases for the latest binaries (avoid package managers)
|
||||||
|
|
||||||
|
## Script Structure
|
||||||
|
|
||||||
|
### 1. Header and Configuration
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# [Tool Name] Installer
|
||||||
|
# Downloads and installs the latest [Tool Name] binary
|
||||||
|
# Supports multiple platforms and installation methods
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
GITHUB_REPO="[owner]/[repo]" # e.g., "git-ecosystem/git-credential-manager"
|
||||||
|
USER_BIN_DIR="$HOME/bin"
|
||||||
|
SYSTEM_INSTALL_DIR="/usr/local/bin"
|
||||||
|
TEMP_DIR="/tmp/[tool]-install"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Core Utility Functions
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Function to print colored output
|
||||||
|
print_status() {
|
||||||
|
echo -e "${BLUE}[INFO]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_success() {
|
||||||
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_warning() {
|
||||||
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_error() {
|
||||||
|
echo -e "${RED}[ERROR]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to check if command exists
|
||||||
|
command_exists() {
|
||||||
|
command -v "$1" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. System Detection Functions
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Function to detect OS and package manager
|
||||||
|
detect_os() {
|
||||||
|
if [[ -f /etc/os-release ]]; then
|
||||||
|
. /etc/os-release
|
||||||
|
OS="$ID"
|
||||||
|
OS_VERSION="$VERSION_ID"
|
||||||
|
else
|
||||||
|
print_error "Cannot detect operating system"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Detect package manager
|
||||||
|
if command_exists apt; then
|
||||||
|
PKG_MANAGER="apt"
|
||||||
|
elif command_exists yum; then
|
||||||
|
PKG_MANAGER="yum"
|
||||||
|
elif command_exists dnf; then
|
||||||
|
PKG_MANAGER="dnf"
|
||||||
|
elif command_exists pacman; then
|
||||||
|
PKG_MANAGER="pacman"
|
||||||
|
elif command_exists zypper; then
|
||||||
|
PKG_MANAGER="zypper"
|
||||||
|
else
|
||||||
|
PKG_MANAGER="unknown"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_status "Detected OS: $OS $OS_VERSION"
|
||||||
|
print_status "Package manager: $PKG_MANAGER"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to get system architecture
|
||||||
|
get_arch() {
|
||||||
|
ARCH=$(uname -m)
|
||||||
|
case $ARCH in
|
||||||
|
x86_64)
|
||||||
|
echo "amd64"
|
||||||
|
;;
|
||||||
|
aarch64|arm64)
|
||||||
|
echo "arm64"
|
||||||
|
;;
|
||||||
|
armv7l)
|
||||||
|
echo "arm"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print_error "Unsupported architecture: $ARCH"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Version Management Functions
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Function to get current installed version and location
|
||||||
|
get_current_version() {
|
||||||
|
if command_exists [tool]; then
|
||||||
|
CURRENT_VERSION=$([tool] --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n 1)
|
||||||
|
if [[ -z "$CURRENT_VERSION" ]]; then
|
||||||
|
CURRENT_VERSION="unknown"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Determine installation location
|
||||||
|
[TOOL]_PATH=$(which [tool])
|
||||||
|
if [[ "$[TOOL]_PATH" == "$USER_BIN_DIR"* ]]; then
|
||||||
|
INSTALL_TYPE="user"
|
||||||
|
elif [[ "$[TOOL]_PATH" == "/usr/local/bin"* ]] || [[ "$[TOOL]_PATH" == "/usr/bin"* ]]; then
|
||||||
|
INSTALL_TYPE="system"
|
||||||
|
else
|
||||||
|
INSTALL_TYPE="other"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
CURRENT_VERSION="not_installed"
|
||||||
|
INSTALL_TYPE="none"
|
||||||
|
fi
|
||||||
|
echo "$CURRENT_VERSION:$INSTALL_TYPE"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to compare versions
|
||||||
|
compare_versions() {
|
||||||
|
local version1="$1"
|
||||||
|
local version2="$2"
|
||||||
|
|
||||||
|
# Remove 'v' prefix if present
|
||||||
|
version1=${version1#v}
|
||||||
|
version2=${version2#v}
|
||||||
|
|
||||||
|
# Split versions into arrays
|
||||||
|
IFS='.' read -ra V1 <<< "$version1"
|
||||||
|
IFS='.' read -ra V2 <<< "$version2"
|
||||||
|
|
||||||
|
# Compare major, minor, patch
|
||||||
|
for i in {0..2}; do
|
||||||
|
local v1=${V1[$i]:-0}
|
||||||
|
local v2=${V2[$i]:-0}
|
||||||
|
|
||||||
|
if (( v1 > v2 )); then
|
||||||
|
return 0 # version1 > version2
|
||||||
|
elif (( v1 < v2 )); then
|
||||||
|
return 1 # version1 < version2
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
return 0 # versions are equal
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to get latest release info
|
||||||
|
get_latest_release() {
|
||||||
|
print_status "Fetching latest [Tool Name] release information..."
|
||||||
|
|
||||||
|
if command_exists curl; then
|
||||||
|
RELEASE_INFO=$(curl -s "https://api.github.com/repos/$GITHUB_REPO/releases/latest")
|
||||||
|
elif command_exists wget; then
|
||||||
|
RELEASE_INFO=$(wget -qO- "https://api.github.com/repos/$GITHUB_REPO/releases/latest")
|
||||||
|
else
|
||||||
|
print_error "curl or wget is required"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$RELEASE_INFO" ]]; then
|
||||||
|
print_error "Failed to fetch release information"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extract version and download URLs
|
||||||
|
LATEST_VERSION=$(echo "$RELEASE_INFO" | grep -o '"tag_name": *"[^"]*"' | sed -E 's/.*"([^"]+)".*/\1/')
|
||||||
|
|
||||||
|
if [[ -z "$LATEST_VERSION" ]]; then
|
||||||
|
print_error "Failed to parse release information"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_success "Latest version: $LATEST_VERSION"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to check if update is needed
|
||||||
|
check_update_needed() {
|
||||||
|
local latest_version="$1"
|
||||||
|
local current_info=$(get_current_version)
|
||||||
|
local current_version=$(echo "$current_info" | cut -d: -f1)
|
||||||
|
local install_type=$(echo "$current_info" | cut -d: -f2)
|
||||||
|
|
||||||
|
print_status "Current version: $current_version ($install_type)"
|
||||||
|
print_status "Latest version: $latest_version"
|
||||||
|
|
||||||
|
if [[ "$current_version" == "not_installed" ]]; then
|
||||||
|
print_status "[Tool Name] is not installed"
|
||||||
|
return 0 # Need to install
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$current_version" == "unknown" ]]; then
|
||||||
|
print_warning "Cannot determine current version, proceeding with update"
|
||||||
|
return 0 # Assume update needed
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clean version strings for comparison
|
||||||
|
local clean_current="${current_version#v}"
|
||||||
|
local clean_latest="${latest_version#v}"
|
||||||
|
|
||||||
|
if compare_versions "$clean_latest" "$clean_current"; then
|
||||||
|
if [[ "$clean_latest" == "$clean_current" ]]; then
|
||||||
|
print_success "You already have the latest version ($current_version) installed at $install_type location"
|
||||||
|
if [[ "$force_reinstall" == "true" ]]; then
|
||||||
|
print_status "Force reinstall requested, proceeding..."
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1 # No update needed
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_status "Newer version available: $latest_version > $current_version"
|
||||||
|
return 0 # Update needed
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_success "Your version ($current_version) is newer than latest release ($latest_version)"
|
||||||
|
return 1 # No update needed
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. Installation Strategy Functions
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Function to check if user bin directory exists and is in PATH
|
||||||
|
check_user_bin_setup() {
|
||||||
|
if [[ ! -d "$USER_BIN_DIR" ]]; then
|
||||||
|
print_status "User bin directory doesn't exist"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if user bin is in PATH
|
||||||
|
if [[ ":$PATH:" != *":$USER_BIN_DIR:"* ]]; then
|
||||||
|
print_warning "User bin directory ($USER_BIN_DIR) is not in PATH"
|
||||||
|
print_status "Add to PATH: export PATH=\"$USER_BIN_DIR:\$PATH\""
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to check for version-specific symlink
|
||||||
|
check_version_symlink() {
|
||||||
|
local [tool]_path=$(which [tool] 2>/dev/null)
|
||||||
|
if [[ -z "$[tool]_path" ]]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if it's a symlink
|
||||||
|
if [[ -L "$[tool]_path" ]]; then
|
||||||
|
SYMLINK_TARGET=$(readlink "$[tool]_path")
|
||||||
|
# Extract version from symlink target
|
||||||
|
if [[ "$SYMLINK_TARGET" =~ [tool]-([0-9]+\.[0-9]+\.[0-9]+) ]]; then
|
||||||
|
CURRENT_SYMLINK_VERSION="${BASH_REMATCH[1]}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to determine installation strategy
|
||||||
|
determine_install_strategy() {
|
||||||
|
local current_info=$(get_current_version)
|
||||||
|
local current_version=$(echo "$current_info" | cut -d: -f1)
|
||||||
|
local install_type=$(echo "$current_info" | cut -d: -f2)
|
||||||
|
|
||||||
|
# Strategy: Prefer system installation for all users
|
||||||
|
if [[ $EUID -eq 0 ]] || sudo -n true 2>/dev/null; then
|
||||||
|
print_status "Installing system-wide for all users"
|
||||||
|
INSTALL_STRATEGY="system_install"
|
||||||
|
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||||
|
|
||||||
|
# Warn if user bin has [tool]
|
||||||
|
if [[ -f "$USER_BIN_DIR/[tool]" ]]; then
|
||||||
|
print_warning "[Tool Name] found in user bin directory ($USER_BIN_DIR)"
|
||||||
|
print_status "This might take precedence if $USER_BIN_DIR is in PATH before system paths"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_status "No sudo access, checking user bin directory"
|
||||||
|
if check_user_bin_setup; then
|
||||||
|
print_status "User bin directory is available and in PATH"
|
||||||
|
|
||||||
|
# Check if [tool] exists in user bin
|
||||||
|
if [[ -f "$USER_BIN_DIR/[tool]" ]]; then
|
||||||
|
print_status "[Tool Name] found in user bin directory"
|
||||||
|
|
||||||
|
# Check for version symlink
|
||||||
|
if check_version_symlink; then
|
||||||
|
print_status "Version symlink found: $CURRENT_SYMLINK_VERSION"
|
||||||
|
INSTALL_STRATEGY="user_update"
|
||||||
|
TARGET_DIR="$USER_BIN_DIR"
|
||||||
|
else
|
||||||
|
print_status "No version symlink found, will create one"
|
||||||
|
INSTALL_STRATEGY="user_upgrade"
|
||||||
|
TARGET_DIR="$USER_BIN_DIR"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_status "[Tool Name] not found in user bin, will install there"
|
||||||
|
INSTALL_STRATEGY="user_install"
|
||||||
|
TARGET_DIR="$USER_BIN_DIR"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_error "Cannot install system-wide (no sudo) and user bin not available"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_status "Installation strategy: $INSTALL_STRATEGY"
|
||||||
|
print_status "Target directory: $TARGET_DIR"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. Download and Installation Functions
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Function to download file
|
||||||
|
download_file() {
|
||||||
|
local url="$1"
|
||||||
|
local filename="$2"
|
||||||
|
|
||||||
|
print_status "Downloading $filename..."
|
||||||
|
|
||||||
|
if command_exists curl; then
|
||||||
|
curl -L -o "$TEMP_DIR/$filename" "$url"
|
||||||
|
elif command_exists wget; then
|
||||||
|
wget -O "$TEMP_DIR/$filename" "$url"
|
||||||
|
else
|
||||||
|
print_error "curl or wget is required"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -f "$TEMP_DIR/$filename" ]]; then
|
||||||
|
print_error "Failed to download $filename"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_success "Downloaded $filename"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to install [Tool Name] from binary
|
||||||
|
install_[tool]_from_binary() {
|
||||||
|
local arch="$1"
|
||||||
|
local version="$2"
|
||||||
|
|
||||||
|
# Determine binary name pattern from GitHub releases
|
||||||
|
local binary_name="[tool]-${version#v}-linux-${arch}"
|
||||||
|
|
||||||
|
local download_url="https://github.com/$GITHUB_REPO/releases/download/$version/$binary_name"
|
||||||
|
|
||||||
|
download_file "$download_url" "$binary_name"
|
||||||
|
|
||||||
|
# Determine installation command based on target directory
|
||||||
|
local install_cmd="install -m 755"
|
||||||
|
local symlink_cmd="ln -sf"
|
||||||
|
|
||||||
|
if [[ "$TARGET_DIR" == "$SYSTEM_INSTALL_DIR" ]]; then
|
||||||
|
install_cmd="sudo $install_cmd"
|
||||||
|
symlink_cmd="sudo $symlink_cmd"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_status "Installing [Tool Name] binary to $TARGET_DIR..."
|
||||||
|
|
||||||
|
# Install the binary with version suffix
|
||||||
|
$install_cmd "$TEMP_DIR/$binary_name" "$TARGET_DIR/[tool]-$version"
|
||||||
|
|
||||||
|
# Verify installation
|
||||||
|
if [[ ! -f "$TARGET_DIR/[tool]-$version" ]]; then
|
||||||
|
print_error "Failed to install [Tool Name] binary"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove any existing [tool] symlink or file to avoid conflicts
|
||||||
|
rm -f "$TARGET_DIR/[tool]"
|
||||||
|
|
||||||
|
# Create/update symlink to point to this version
|
||||||
|
$symlink_cmd "$TARGET_DIR/[tool]-$version" "$TARGET_DIR/[tool]"
|
||||||
|
|
||||||
|
print_success "[Tool Name] binary installed successfully"
|
||||||
|
print_status "Version symlink: [tool] -> [tool]-$version"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to verify [Tool Name] installation
|
||||||
|
verify_[tool]_installation() {
|
||||||
|
print_status "Verifying [Tool Name] installation..."
|
||||||
|
|
||||||
|
if command_exists [tool]; then
|
||||||
|
local version=$([tool] --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n 1)
|
||||||
|
print_success "[Tool Name] installed: $version"
|
||||||
|
|
||||||
|
# Check for user bin versions and offer removal
|
||||||
|
if [[ -d "$USER_BIN_DIR" ]] && [[ "$TARGET_DIR" == "$SYSTEM_INSTALL_DIR" ]]; then
|
||||||
|
local user_versions=()
|
||||||
|
for file in "$USER_BIN_DIR"/[tool]*; do
|
||||||
|
if [[ -f "$file" ]]; then
|
||||||
|
user_versions+=("$file")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ${#user_versions[@]} -gt 0 ]]; then
|
||||||
|
print_warning "Found [tool] binaries in user bin directory:"
|
||||||
|
for file in "${user_versions[@]}"; do
|
||||||
|
echo " $file"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
read -p "Would you like to remove these user bin versions? (y/N): " -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
for file in "${user_versions[@]}"; do
|
||||||
|
rm -f "$file"
|
||||||
|
print_status "Removed $file"
|
||||||
|
done
|
||||||
|
print_success "Removed all user bin versions"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
print_error "[Tool Name] installation verification failed"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 7. Utility Functions
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Function to cleanup
|
||||||
|
cleanup() {
|
||||||
|
if [[ -d "$TEMP_DIR" ]]; then
|
||||||
|
rm -rf "$TEMP_DIR"
|
||||||
|
print_status "Cleaned up temporary files"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to show usage
|
||||||
|
show_usage() {
|
||||||
|
echo "[Tool Name] Installer"
|
||||||
|
echo
|
||||||
|
echo "Usage: $0 [OPTIONS]"
|
||||||
|
echo
|
||||||
|
echo "Options:"
|
||||||
|
echo " -h, --help Show this help message"
|
||||||
|
echo " -v, --version Install specific version (default: latest)"
|
||||||
|
echo " -f, --force Force reinstall even if up-to-date"
|
||||||
|
echo " -r, --reinstall Reinstall the current installed version"
|
||||||
|
echo
|
||||||
|
echo "Examples:"
|
||||||
|
echo " $0 # Install latest version using best method"
|
||||||
|
echo " $0 -v v1.0.0 # Install specific version"
|
||||||
|
echo " $0 --reinstall # Reinstall current version"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8. Main Function
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Main installation function
|
||||||
|
main() {
|
||||||
|
local target_version=""
|
||||||
|
local force_reinstall=false
|
||||||
|
local reinstall_current=false
|
||||||
|
|
||||||
|
# Parse command line arguments
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
-h|--help)
|
||||||
|
show_usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-v|--version)
|
||||||
|
target_version="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-f|--force)
|
||||||
|
force_reinstall=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-r|--reinstall)
|
||||||
|
reinstall_current=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print_error "Unknown option: $1"
|
||||||
|
show_usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "========================================"
|
||||||
|
echo "[Tool Name] Installer"
|
||||||
|
echo "========================================"
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Check if running as root for system installation
|
||||||
|
if [[ $EUID -ne 0 ]]; then
|
||||||
|
print_warning "Not running as root. Some operations may require sudo."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Detect system
|
||||||
|
detect_os
|
||||||
|
ARCH=$(get_arch)
|
||||||
|
|
||||||
|
# Handle reinstall current version
|
||||||
|
if [[ "$reinstall_current" == "true" ]]; then
|
||||||
|
local current_info=$(get_current_version)
|
||||||
|
local current_version=$(echo "$current_info" | cut -d: -f1)
|
||||||
|
if [[ "$current_version" == "not_installed" ]]; then
|
||||||
|
print_error "No current version installed to reinstall"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
target_version="$current_version"
|
||||||
|
force_reinstall=true
|
||||||
|
print_status "Reinstalling current version: $target_version"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get latest version if not specified
|
||||||
|
if [[ -z "$target_version" ]]; then
|
||||||
|
get_latest_release
|
||||||
|
target_version="$LATEST_VERSION"
|
||||||
|
else
|
||||||
|
print_status "Using specified version: $target_version"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Determine installation strategy
|
||||||
|
determine_install_strategy
|
||||||
|
|
||||||
|
# Check if update is needed
|
||||||
|
if ! check_update_needed "$target_version"; then
|
||||||
|
print_success "No installation needed. Exiting."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create temporary directory
|
||||||
|
mkdir -p "$TEMP_DIR"
|
||||||
|
|
||||||
|
# Trap cleanup on exit
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
# Install from binary
|
||||||
|
install_[tool]_from_binary "$ARCH" "$target_version"
|
||||||
|
verify_[tool]_installation
|
||||||
|
|
||||||
|
# Installation completed successfully
|
||||||
|
echo
|
||||||
|
print_success "Installation completed successfully!"
|
||||||
|
echo
|
||||||
|
echo "Installation details:"
|
||||||
|
echo "- Strategy: $INSTALL_STRATEGY"
|
||||||
|
echo "- Location: $TARGET_DIR"
|
||||||
|
if [[ "$INSTALL_STRATEGY" == user* ]]; then
|
||||||
|
echo "- Binary: [tool] (symlink to [tool]-$target_version)"
|
||||||
|
echo "- Version: $target_version"
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
echo "Next steps:"
|
||||||
|
echo "1. Test installation: [tool] --version"
|
||||||
|
echo "2. [Add tool-specific usage instructions]"
|
||||||
|
echo
|
||||||
|
if [[ "$INSTALL_STRATEGY" == user* ]]; then
|
||||||
|
echo "User-specific installation notes:"
|
||||||
|
echo "- Binary installed in: $USER_BIN_DIR"
|
||||||
|
echo "- Ensure $USER_BIN_DIR is in your PATH"
|
||||||
|
echo "- You can have multiple versions side-by-side"
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
echo "For more information, visit: https://github.com/$GITHUB_REPO"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run main function
|
||||||
|
main "$@"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Implementation Notes
|
||||||
|
|
||||||
|
1. **Replace Placeholders**: Replace `[tool]`, `[Tool Name]`, `[TOOL]`, `[owner]/[repo]` with actual values.
|
||||||
|
|
||||||
|
2. **Binary Naming Convention**: Adjust the `binary_name` in `install_[tool]_from_binary` to match the actual GitHub release asset names.
|
||||||
|
|
||||||
|
3. **Version Detection**: Modify the version extraction in `get_current_version` and `verify_[tool]_installation` to match the tool's `--version` output format.
|
||||||
|
|
||||||
|
4. **Package Manager**: Since we disable package manager installation, the script will always use the binary method.
|
||||||
|
|
||||||
|
5. **Testing**: Test the script on different systems and with different scenarios (system vs user installation, reinstall, etc.).
|
||||||
|
|
||||||
|
6. **Error Handling**: Ensure all error conditions are properly handled with appropriate exit codes.
|
||||||
|
|
||||||
|
7. **Documentation**: Update the usage examples and next steps section with tool-specific information.
|
||||||
|
|
||||||
|
This template ensures consistency across all installer scripts and provides a robust installation experience for users.</content>
|
||||||
|
<parameter name="filePath">INSTALLER_CREATION_GUIDE.md
|
||||||
@@ -1,157 +0,0 @@
|
|||||||
# Tea CLI Installer - Advanced Version Management
|
|
||||||
|
|
||||||
## Enhanced Installation Strategy
|
|
||||||
|
|
||||||
The Tea CLI installer now implements sophisticated version management with user-specific installations:
|
|
||||||
|
|
||||||
### Installation Priority Order
|
|
||||||
|
|
||||||
1. **User Bin Directory** (`~/bin`) - Preferred
|
|
||||||
- Checks if `~/bin` exists and is in PATH
|
|
||||||
- Installs binaries with version-specific names
|
|
||||||
- Creates symlinks for easy version switching
|
|
||||||
- Allows multiple versions side-by-side
|
|
||||||
|
|
||||||
2. **System Installation** (`/usr/local/bin`) - Fallback
|
|
||||||
- Used when user bin is not available
|
|
||||||
- Requires sudo for system-wide installation
|
|
||||||
- Single version installation
|
|
||||||
|
|
||||||
### Version Management Features
|
|
||||||
|
|
||||||
#### Symlink-Based Version Control
|
|
||||||
```bash
|
|
||||||
~/bin/
|
|
||||||
├── tea -> tea-v0.11.1 # Active version symlink
|
|
||||||
├── tea-v0.11.0 # Previous version
|
|
||||||
├── tea-v0.11.1 # Current version
|
|
||||||
└── tea-v0.12.0 # Future version (when available)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Automatic Updates
|
|
||||||
- Detects current version via symlink
|
|
||||||
- Downloads newer versions with version suffix
|
|
||||||
- Updates symlink to point to latest version
|
|
||||||
- Preserves old versions for rollback
|
|
||||||
|
|
||||||
### Installation Strategies
|
|
||||||
|
|
||||||
#### `user_install` - Fresh User Installation
|
|
||||||
- When Tea CLI not found in user bin
|
|
||||||
- Creates versioned binary and symlink
|
|
||||||
- No sudo required
|
|
||||||
|
|
||||||
#### `user_update` - User Version Update
|
|
||||||
- When newer version available
|
|
||||||
- Downloads new version with suffix
|
|
||||||
- Updates symlink to new version
|
|
||||||
- Keeps old versions
|
|
||||||
|
|
||||||
#### `user_upgrade` - User Upgrade (No Symlink)
|
|
||||||
- When existing binary found but no symlink
|
|
||||||
- Creates versioned structure
|
|
||||||
- Adds symlink management
|
|
||||||
|
|
||||||
#### `system_install` - System Installation
|
|
||||||
- When user bin not available/in PATH
|
|
||||||
- Installs to `/usr/local/bin`
|
|
||||||
- Requires sudo privileges
|
|
||||||
|
|
||||||
### Usage Examples
|
|
||||||
|
|
||||||
#### Normal Usage (Auto-detects strategy)
|
|
||||||
```bash
|
|
||||||
./install-tea-cli.sh
|
|
||||||
# Detects user bin, checks versions, updates if needed
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Force Binary Installation
|
|
||||||
```bash
|
|
||||||
./install-tea-cli.sh --force --binary
|
|
||||||
# Forces binary download regardless of current version
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Check Current Status
|
|
||||||
```bash
|
|
||||||
./install-tea-cli.sh
|
|
||||||
# Shows current version and installation type
|
|
||||||
# Exits if no update needed
|
|
||||||
```
|
|
||||||
|
|
||||||
### Version Detection Logic
|
|
||||||
|
|
||||||
1. **Check PATH**: Finds `tea` command location
|
|
||||||
2. **Installation Type**: Determines user vs system installation
|
|
||||||
3. **Symlink Check**: Detects version-specific symlinks
|
|
||||||
4. **Version Comparison**: Compares with latest release
|
|
||||||
5. **Strategy Selection**: Chooses appropriate installation method
|
|
||||||
|
|
||||||
### Benefits
|
|
||||||
|
|
||||||
✅ **User Isolation**: Installations don't affect other users
|
|
||||||
✅ **Version Control**: Multiple versions can coexist
|
|
||||||
✅ **Easy Updates**: Symlinks automatically point to latest
|
|
||||||
✅ **Rollback Support**: Old versions preserved
|
|
||||||
✅ **No Sudo Required**: User installations don't need root
|
|
||||||
✅ **System Fallback**: Falls back to system installation when needed
|
|
||||||
|
|
||||||
### Directory Structure
|
|
||||||
|
|
||||||
#### User Installation
|
|
||||||
```
|
|
||||||
~/bin/
|
|
||||||
├── tea -> tea-v0.11.1
|
|
||||||
├── tea-v0.11.0
|
|
||||||
└── tea-v0.11.1
|
|
||||||
```
|
|
||||||
|
|
||||||
#### System Installation
|
|
||||||
```
|
|
||||||
/usr/local/bin/
|
|
||||||
├── tea -> tea-v0.11.1
|
|
||||||
├── tea-v0.11.0
|
|
||||||
└── tea-v0.11.1
|
|
||||||
```
|
|
||||||
|
|
||||||
### PATH Requirements
|
|
||||||
|
|
||||||
For user installations, ensure `~/bin` is in PATH:
|
|
||||||
```bash
|
|
||||||
# Add to ~/.bashrc or ~/.profile
|
|
||||||
export PATH="$HOME/bin:$PATH"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Troubleshooting
|
|
||||||
|
|
||||||
#### Version Not Updating
|
|
||||||
```bash
|
|
||||||
# Check current symlink
|
|
||||||
ls -la ~/bin/tea
|
|
||||||
|
|
||||||
# Force reinstall
|
|
||||||
./install-tea-cli.sh --force
|
|
||||||
```
|
|
||||||
|
|
||||||
#### PATH Issues
|
|
||||||
```bash
|
|
||||||
# Check if user bin is in PATH
|
|
||||||
echo $PATH | grep -q "$HOME/bin" && echo "OK" || echo "Add to PATH"
|
|
||||||
|
|
||||||
# Test tea command
|
|
||||||
which tea
|
|
||||||
tea --version
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Permission Issues
|
|
||||||
```bash
|
|
||||||
# For system installation
|
|
||||||
sudo ./install-tea-cli.sh --binary
|
|
||||||
```
|
|
||||||
|
|
||||||
### Integration with Setup Script
|
|
||||||
|
|
||||||
The installer integrates seamlessly with the main setup script:
|
|
||||||
- Automatically called when Tea CLI is needed
|
|
||||||
- Respects user preferences for installation location
|
|
||||||
- Provides clear feedback on installation strategy
|
|
||||||
- Handles both new installations and updates
|
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
# Tea CLI Installer
|
|
||||||
|
|
||||||
A comprehensive installer script for Gitea Tea CLI that supports multiple Linux distributions and installation methods.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- **Version Checking**: Only downloads and installs if newer version is available
|
|
||||||
- **Multiple Installation Methods**:
|
|
||||||
- Package manager (apt, yum, dnf, zypper)
|
|
||||||
- Binary download from Gitea releases
|
|
||||||
- **Cross-Platform Support**: Debian, Ubuntu, RHEL, CentOS, Fedora, Arch, openSUSE
|
|
||||||
- **Architecture Support**: x86_64 (amd64), ARM64, ARM
|
|
||||||
- **Automatic Updates**: Fetches latest version from Gitea API
|
|
||||||
- **Force Reinstall**: Option to force reinstall even if up-to-date
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
### Basic Usage
|
|
||||||
```bash
|
|
||||||
# Install latest version (only if newer than current)
|
|
||||||
./install-tea-cli.sh
|
|
||||||
|
|
||||||
# Install specific version
|
|
||||||
./install-tea-cli.sh -v v0.11.0
|
|
||||||
|
|
||||||
# Force reinstall even if up-to-date
|
|
||||||
./install-tea-cli.sh --force
|
|
||||||
```
|
|
||||||
|
|
||||||
### Installation Methods
|
|
||||||
```bash
|
|
||||||
# Force installation from package manager
|
|
||||||
./install-tea-cli.sh --package
|
|
||||||
|
|
||||||
# Force installation from binary
|
|
||||||
./install-tea-cli.sh --binary
|
|
||||||
```
|
|
||||||
|
|
||||||
### Help
|
|
||||||
```bash
|
|
||||||
./install-tea-cli.sh --help
|
|
||||||
```
|
|
||||||
|
|
||||||
## Installation Logic
|
|
||||||
|
|
||||||
### Version Checking
|
|
||||||
1. **Check Current Version**: Detects installed Tea CLI version
|
|
||||||
2. **Fetch Latest**: Gets latest version from Gitea API
|
|
||||||
3. **Compare Versions**: Only proceeds if newer version available
|
|
||||||
4. **Force Override**: `--force` flag bypasses version check
|
|
||||||
|
|
||||||
### Installation Priority
|
|
||||||
1. **Package Manager** (preferred):
|
|
||||||
- Debian/Ubuntu: Checks for official Tea CLI package
|
|
||||||
- RHEL/CentOS/Fedora: Checks for available Tea CLI package
|
|
||||||
- Arch Linux: Available in AUR (pacman)
|
|
||||||
- openSUSE: Checks for available Tea CLI package
|
|
||||||
|
|
||||||
2. **Binary Download** (fallback):
|
|
||||||
- Downloads platform-specific binary from Gitea releases
|
|
||||||
- Supports x86_64, ARM64, ARM architectures
|
|
||||||
- Installs to `/usr/local/bin/tea`
|
|
||||||
|
|
||||||
## File Locations
|
|
||||||
|
|
||||||
### Installation Directory
|
|
||||||
- Binary: `/usr/local/bin/tea`
|
|
||||||
- Symlink: `/usr/local/bin/tea-<version>`
|
|
||||||
|
|
||||||
## Version Comparison
|
|
||||||
|
|
||||||
The installer uses semantic version comparison:
|
|
||||||
- **Format**: `vX.Y.Z` (e.g., `v0.11.1`)
|
|
||||||
- **Logic**: Compares major, minor, patch versions
|
|
||||||
- **Build Info**: Ignores build hashes/identifiers
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
```bash
|
|
||||||
# Current: 0.11.0, Latest: v0.11.1 → Update needed
|
|
||||||
# Current: 0.11.1, Latest: v0.11.1 → No update needed
|
|
||||||
# Current: 0.11.2, Latest: v0.11.1 → No update needed (newer installed)
|
|
||||||
```
|
|
||||||
|
|
||||||
## System Requirements
|
|
||||||
|
|
||||||
### Required
|
|
||||||
- `curl` or `wget` (for downloading)
|
|
||||||
- `sudo` access (for system-wide installation)
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
- Package manager access (for package installations)
|
|
||||||
- Internet connection (for downloading releases)
|
|
||||||
|
|
||||||
## Supported Distributions
|
|
||||||
|
|
||||||
### Package Manager Support
|
|
||||||
- **Debian/Ubuntu**: Checks for official Tea CLI package
|
|
||||||
- **RHEL/CentOS/Fedora**: Checks for available Tea CLI package
|
|
||||||
- **Arch Linux**: Available in AUR (pacman)
|
|
||||||
- **openSUSE**: Checks for available Tea CLI package
|
|
||||||
|
|
||||||
### Binary Support
|
|
||||||
- **Linux x86_64**: `tea-0.11.1-linux-amd64`
|
|
||||||
- **Linux ARM64**: `tea-0.11.1-linux-arm64`
|
|
||||||
- **Linux ARM**: `tea-0.11.1-linux-arm-5`, `tea-0.11.1-linux-arm-6`, `tea-0.11.1-linux-arm-7`
|
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
### Version Detection Issues
|
|
||||||
```bash
|
|
||||||
# Check current version manually
|
|
||||||
tea --version
|
|
||||||
|
|
||||||
# Force reinstall if version detection fails
|
|
||||||
./install-tea-cli.sh --force
|
|
||||||
```
|
|
||||||
|
|
||||||
### Permission Issues
|
|
||||||
```bash
|
|
||||||
# Ensure proper permissions
|
|
||||||
sudo chown root:root /usr/local/bin/tea
|
|
||||||
sudo chmod 755 /usr/local/bin/tea
|
|
||||||
```
|
|
||||||
|
|
||||||
### PATH Issues
|
|
||||||
```bash
|
|
||||||
# Check which tea is being used
|
|
||||||
which tea
|
|
||||||
|
|
||||||
# Check all tea installations
|
|
||||||
find /usr -name tea 2>/dev/null
|
|
||||||
find /home -name tea 2>/dev/null
|
|
||||||
|
|
||||||
# Update PATH if needed
|
|
||||||
export PATH="/usr/local/bin:$PATH"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
### Typical Workflow
|
|
||||||
```bash
|
|
||||||
# Check if update needed
|
|
||||||
./install-tea-cli.sh
|
|
||||||
|
|
||||||
# Output if up-to-date:
|
|
||||||
# [SUCCESS] You already have the latest version (0.11.1)
|
|
||||||
# [SUCCESS] No installation needed. Exiting.
|
|
||||||
|
|
||||||
# Output if update available:
|
|
||||||
# [INFO] Current version: 0.11.0
|
|
||||||
# [INFO] Latest version: v0.11.1
|
|
||||||
# [INFO] Newer version available: v0.11.1 > 0.11.0
|
|
||||||
# [SUCCESS] Installation completed successfully!
|
|
||||||
```
|
|
||||||
|
|
||||||
### Force Binary Installation
|
|
||||||
```bash
|
|
||||||
# Force binary installation
|
|
||||||
./install-tea-cli.sh --force --binary
|
|
||||||
|
|
||||||
# Output:
|
|
||||||
# [SUCCESS] Tea CLI binary installed successfully
|
|
||||||
# Next steps:
|
|
||||||
# 1. Test installation: tea --version
|
|
||||||
# 2. Configure login: tea login add
|
|
||||||
# 3. Use Tea CLI: tea --help
|
|
||||||
```
|
|
||||||
|
|
||||||
## Integration with Setup Script
|
|
||||||
|
|
||||||
The Tea CLI installer is automatically integrated with the main Git repository setup script:
|
|
||||||
|
|
||||||
1. **Detection**: Checks for existing Tea CLI installations
|
|
||||||
2. **Offer Installation**: Prompts to install Tea CLI if none found
|
|
||||||
3. **Configuration**: Guides through login setup
|
|
||||||
4. **Repository Management**: Enables Gitea repository operations
|
|
||||||
|
|
||||||
## Security Features
|
|
||||||
|
|
||||||
- **Official Releases**: Downloads from official Gitea releases
|
|
||||||
- **Package Verification**: Uses official package repositories
|
|
||||||
- **Proper Permissions**: Sets appropriate file ownership and permissions
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
To add support for new distributions or architectures:
|
|
||||||
|
|
||||||
1. Update `detect_os()` function for new package managers
|
|
||||||
2. Add architecture detection in `get_arch()` function
|
|
||||||
3. Update installation methods in `install_tea_from_*()` functions
|
|
||||||
4. Test with target distribution
|
|
||||||
5. Update documentation
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
This installer script follows the same license as Gitea Tea CLI (MIT).
|
|
||||||
@@ -198,7 +198,7 @@ check_update_needed() {
|
|||||||
|
|
||||||
if compare_versions "$clean_latest" "$clean_current"; then
|
if compare_versions "$clean_latest" "$clean_current"; then
|
||||||
if [[ "$clean_latest" == "$clean_current" ]]; then
|
if [[ "$clean_latest" == "$clean_current" ]]; then
|
||||||
print_success "You already have the latest version ($current_version)"
|
print_success "You already have the latest version ($current_version) installed at $install_type location"
|
||||||
if [[ "$force_reinstall" == "true" ]]; then
|
if [[ "$force_reinstall" == "true" ]]; then
|
||||||
print_status "Force reinstall requested, proceeding..."
|
print_status "Force reinstall requested, proceeding..."
|
||||||
return 0
|
return 0
|
||||||
@@ -278,37 +278,49 @@ check_version_symlink() {
|
|||||||
|
|
||||||
# Function to determine installation strategy
|
# Function to determine installation strategy
|
||||||
determine_install_strategy() {
|
determine_install_strategy() {
|
||||||
local current_info=$(get_current_version)
|
local local_install="$1"
|
||||||
local current_version=$(echo "$current_info" | cut -d: -f1)
|
|
||||||
local install_type=$(echo "$current_info" | cut -d: -f2)
|
|
||||||
|
|
||||||
# Strategy 1: Check user bin directory first
|
# Strategy: Check installation type preference
|
||||||
if check_user_bin_setup; then
|
if [[ "$local_install" == "true" ]]; then
|
||||||
print_status "User bin directory is available and in PATH"
|
print_status "Local installation requested"
|
||||||
|
if check_user_bin_setup; then
|
||||||
# Check if borg exists in user bin
|
print_status "User bin directory is available and in PATH"
|
||||||
if [[ -f "$USER_BIN_DIR/borg" ]]; then
|
|
||||||
print_status "Borg CLI found in user bin directory"
|
|
||||||
|
|
||||||
# Check for version symlink
|
|
||||||
if check_version_symlink; then
|
|
||||||
print_status "Version symlink found: $CURRENT_SYMLINK_VERSION"
|
|
||||||
INSTALL_STRATEGY="user_update"
|
|
||||||
TARGET_DIR="$USER_BIN_DIR"
|
|
||||||
else
|
|
||||||
print_status "No version symlink found, will create one"
|
|
||||||
INSTALL_STRATEGY="user_upgrade"
|
|
||||||
TARGET_DIR="$USER_BIN_DIR"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
print_status "Borg CLI not found in user bin, will install there"
|
|
||||||
INSTALL_STRATEGY="user_install"
|
INSTALL_STRATEGY="user_install"
|
||||||
TARGET_DIR="$USER_BIN_DIR"
|
TARGET_DIR="$USER_BIN_DIR"
|
||||||
|
else
|
||||||
|
print_error "User bin directory not available for local installation"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
print_status "User bin directory not available, using system installation"
|
# Prefer system installation for all users
|
||||||
INSTALL_STRATEGY="system_install"
|
if [[ $EUID -eq 0 ]]; then
|
||||||
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
print_status "Running as root, installing system-wide"
|
||||||
|
INSTALL_STRATEGY="system_install"
|
||||||
|
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||||
|
elif sudo -n true 2>/dev/null; then
|
||||||
|
print_status "Passwordless sudo available, installing system-wide"
|
||||||
|
INSTALL_STRATEGY="system_install"
|
||||||
|
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||||
|
elif command_exists sudo; then
|
||||||
|
print_status "Testing sudo access (you may be prompted for password)..."
|
||||||
|
if sudo -v 2>/dev/null; then
|
||||||
|
print_success "Sudo access confirmed, installing system-wide"
|
||||||
|
INSTALL_STRATEGY="system_install"
|
||||||
|
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||||
|
else
|
||||||
|
print_error "Sudo access failed. Use --local to install to user bin directory"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_error "Sudo not available. Use --local to install to user bin directory"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Warn if user bin has borg (only for system installs)
|
||||||
|
if [[ "$INSTALL_STRATEGY" == "system_install" ]] && [[ -f "$USER_BIN_DIR/borg" ]]; then
|
||||||
|
print_warning "Borg CLI found in user bin directory ($USER_BIN_DIR)"
|
||||||
|
print_status "This might take precedence if $USER_BIN_DIR is in PATH before system paths"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
print_status "Installation strategy: $INSTALL_STRATEGY"
|
print_status "Installation strategy: $INSTALL_STRATEGY"
|
||||||
@@ -317,75 +329,9 @@ determine_install_strategy() {
|
|||||||
|
|
||||||
# Function to install Borg CLI from package manager
|
# Function to install Borg CLI from package manager
|
||||||
install_borg_from_package_manager() {
|
install_borg_from_package_manager() {
|
||||||
# Package manager installation only works for system-wide installation
|
# Package manager versions are often outdated, use binary from GitHub instead
|
||||||
if [[ "$INSTALL_STRATEGY" == user* ]]; then
|
print_warning "Package manager installation skipped for Borg CLI to ensure latest version, using binary instead"
|
||||||
print_status "Skipping package manager for user installation"
|
return 1
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
print_status "Attempting to install Borg CLI from package manager..."
|
|
||||||
|
|
||||||
case $PKG_MANAGER in
|
|
||||||
apt)
|
|
||||||
# Check if Borg CLI is available in official repositories
|
|
||||||
if apt-cache show borgbackup 2>/dev/null | grep -q "borg"; then
|
|
||||||
print_status "Installing Borg CLI from Ubuntu/Debian repositories..."
|
|
||||||
sudo apt install -y borgbackup
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
print_warning "Borg CLI not available in Ubuntu/Debian repositories"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
yum)
|
|
||||||
# Check if Borg CLI is available
|
|
||||||
if yum list available borgbackup 2>/dev/null | grep -q borgbackup; then
|
|
||||||
print_status "Installing Borg CLI from yum repositories..."
|
|
||||||
sudo yum install -y borgbackup
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
print_warning "Borg CLI not available in yum repositories"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
dnf)
|
|
||||||
# Check if Borg CLI is available
|
|
||||||
if dnf list available borgbackup 2>/dev/null | grep -q borgbackup; then
|
|
||||||
print_status "Installing Borg CLI from dnf repositories..."
|
|
||||||
sudo dnf install -y borgbackup
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
print_warning "Borg CLI not available in dnf repositories"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
pacman)
|
|
||||||
# Borg is available in Arch repositories
|
|
||||||
if pacman -Si borg 2>/dev/null | grep -q borg; then
|
|
||||||
print_status "Installing Borg CLI from pacman repositories..."
|
|
||||||
sudo pacman -S --noconfirm borg
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
print_warning "Borg CLI not available in pacman repositories"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
zypper)
|
|
||||||
# Check if Borg CLI is available
|
|
||||||
if zypper search -x borgbackup 2>/dev/null | grep -q borgbackup; then
|
|
||||||
print_status "Installing Borg CLI from zypper repositories..."
|
|
||||||
sudo zypper install -y borgbackup
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
print_warning "Borg CLI not available in zypper repositories"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
print_warning "Package manager $PKG_MANAGER not supported for automatic installation"
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to install Borg CLI from binary
|
# Function to install Borg CLI from binary
|
||||||
@@ -393,8 +339,23 @@ install_borg_from_binary() {
|
|||||||
local arch="$1"
|
local arch="$1"
|
||||||
local version="$2"
|
local version="$2"
|
||||||
|
|
||||||
# Borg uses different naming convention: borg-linux-glibc231-x86_64
|
# Borg uses different naming conventions based on architecture
|
||||||
local binary_name="borg-linux-glibc231-$arch"
|
local binary_name
|
||||||
|
case "$arch" in
|
||||||
|
x86_64)
|
||||||
|
binary_name="borg-linux-glibc231-x86_64"
|
||||||
|
;;
|
||||||
|
aarch64)
|
||||||
|
binary_name="borg-linux-glibc235-arm64-gh"
|
||||||
|
;;
|
||||||
|
armv7)
|
||||||
|
binary_name="borg-linux-glibc231-armv7"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print_error "Unsupported architecture: $arch"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
local download_url="https://github.com/$GITHUB_REPO/releases/download/$version/$binary_name"
|
local download_url="https://github.com/$GITHUB_REPO/releases/download/$version/$binary_name"
|
||||||
|
|
||||||
download_file "$download_url" "$binary_name"
|
download_file "$download_url" "$binary_name"
|
||||||
@@ -413,6 +374,19 @@ install_borg_from_binary() {
|
|||||||
# Install the binary with version suffix
|
# Install the binary with version suffix
|
||||||
$install_cmd "$TEMP_DIR/$binary_name" "$TARGET_DIR/borg-$version"
|
$install_cmd "$TEMP_DIR/$binary_name" "$TARGET_DIR/borg-$version"
|
||||||
|
|
||||||
|
# Verify installation
|
||||||
|
if [[ ! -f "$TARGET_DIR/borg-$version" ]]; then
|
||||||
|
print_error "Failed to install Borg CLI binary"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove any existing borg symlink or file to avoid conflicts
|
||||||
|
if [[ "$TARGET_DIR" == "$SYSTEM_INSTALL_DIR" ]]; then
|
||||||
|
sudo rm -f "$TARGET_DIR/borg"
|
||||||
|
else
|
||||||
|
rm -f "$TARGET_DIR/borg"
|
||||||
|
fi
|
||||||
|
|
||||||
# Create/update symlink to point to this version
|
# Create/update symlink to point to this version
|
||||||
$symlink_cmd "$TARGET_DIR/borg-$version" "$TARGET_DIR/borg"
|
$symlink_cmd "$TARGET_DIR/borg-$version" "$TARGET_DIR/borg"
|
||||||
|
|
||||||
@@ -427,6 +401,34 @@ verify_borg_installation() {
|
|||||||
if command_exists borg; then
|
if command_exists borg; then
|
||||||
local version=$(borg --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n 1)
|
local version=$(borg --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n 1)
|
||||||
print_success "Borg CLI installed: $version"
|
print_success "Borg CLI installed: $version"
|
||||||
|
|
||||||
|
# Check for user bin versions and offer removal
|
||||||
|
if [[ -d "$USER_BIN_DIR" ]] && [[ "$TARGET_DIR" == "$SYSTEM_INSTALL_DIR" ]]; then
|
||||||
|
local user_versions=()
|
||||||
|
for file in "$USER_BIN_DIR"/borg*; do
|
||||||
|
if [[ -f "$file" ]]; then
|
||||||
|
user_versions+=("$file")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ${#user_versions[@]} -gt 0 ]]; then
|
||||||
|
print_warning "Found borg binaries in user bin directory:"
|
||||||
|
for file in "${user_versions[@]}"; do
|
||||||
|
echo " $file"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
read -p "Would you like to remove these user bin versions? (y/N): " -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
for file in "${user_versions[@]}"; do
|
||||||
|
rm -f "$file"
|
||||||
|
print_status "Removed $file"
|
||||||
|
done
|
||||||
|
print_success "Removed all user bin versions"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
print_error "Borg CLI installation verification failed"
|
print_error "Borg CLI installation verification failed"
|
||||||
@@ -452,12 +454,16 @@ show_usage() {
|
|||||||
echo " -h, --help Show this help message"
|
echo " -h, --help Show this help message"
|
||||||
echo " -v, --version Install specific version (default: latest)"
|
echo " -v, --version Install specific version (default: latest)"
|
||||||
echo " -f, --force Force reinstall even if up-to-date"
|
echo " -f, --force Force reinstall even if up-to-date"
|
||||||
|
echo " -r, --reinstall Reinstall the current installed version"
|
||||||
|
echo " -l, --local Force installation to user bin directory (~/.bin)"
|
||||||
echo " -p, --package Force installation from package manager"
|
echo " -p, --package Force installation from package manager"
|
||||||
echo " -b, --binary Force installation from binary"
|
echo " -b, --binary Force installation from binary"
|
||||||
echo
|
echo
|
||||||
echo "Examples:"
|
echo "Examples:"
|
||||||
echo " $0 # Install latest version using best method"
|
echo " $0 # Install latest version using best method"
|
||||||
echo " $0 -v v1.2.7 # Install specific version"
|
echo " $0 -v v1.2.7 # Install specific version"
|
||||||
|
echo " $0 --reinstall # Reinstall current version"
|
||||||
|
echo " $0 --local # Force installation to user bin"
|
||||||
echo " $0 --package # Force installation from package manager"
|
echo " $0 --package # Force installation from package manager"
|
||||||
echo " $0 --binary # Force installation from binary"
|
echo " $0 --binary # Force installation from binary"
|
||||||
echo
|
echo
|
||||||
@@ -467,6 +473,8 @@ show_usage() {
|
|||||||
main() {
|
main() {
|
||||||
local target_version=""
|
local target_version=""
|
||||||
local force_reinstall=false
|
local force_reinstall=false
|
||||||
|
local reinstall_current=false
|
||||||
|
local local_install=false
|
||||||
local install_method="auto"
|
local install_method="auto"
|
||||||
|
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
@@ -484,6 +492,14 @@ main() {
|
|||||||
force_reinstall=true
|
force_reinstall=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-r|--reinstall)
|
||||||
|
reinstall_current=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-l|--local)
|
||||||
|
local_install=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-p|--package)
|
-p|--package)
|
||||||
install_method="package"
|
install_method="package"
|
||||||
shift
|
shift
|
||||||
@@ -514,6 +530,19 @@ main() {
|
|||||||
detect_os
|
detect_os
|
||||||
ARCH=$(get_arch)
|
ARCH=$(get_arch)
|
||||||
|
|
||||||
|
# Handle reinstall current version
|
||||||
|
if [[ "$reinstall_current" == "true" ]]; then
|
||||||
|
local current_info=$(get_current_version)
|
||||||
|
local current_version=$(echo "$current_info" | cut -d: -f1)
|
||||||
|
if [[ "$current_version" == "not_installed" ]]; then
|
||||||
|
print_error "No current version installed to reinstall"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
target_version="$current_version"
|
||||||
|
force_reinstall=true
|
||||||
|
print_status "Reinstalling current version: $target_version"
|
||||||
|
fi
|
||||||
|
|
||||||
# Get latest version if not specified
|
# Get latest version if not specified
|
||||||
if [[ -z "$target_version" ]]; then
|
if [[ -z "$target_version" ]]; then
|
||||||
get_latest_release
|
get_latest_release
|
||||||
@@ -523,7 +552,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Determine installation strategy
|
# Determine installation strategy
|
||||||
determine_install_strategy
|
determine_install_strategy "$local_install"
|
||||||
|
|
||||||
# Check if update is needed
|
# Check if update is needed
|
||||||
if ! check_update_needed "$target_version"; then
|
if ! check_update_needed "$target_version"; then
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ NC='\033[0m' # No Color
|
|||||||
# Configuration
|
# Configuration
|
||||||
GITHUB_REPO="git-ecosystem/git-credential-manager"
|
GITHUB_REPO="git-ecosystem/git-credential-manager"
|
||||||
INSTALL_DIR="/usr/local/bin"
|
INSTALL_DIR="/usr/local/bin"
|
||||||
|
USER_BIN_DIR="$HOME/bin"
|
||||||
TEMP_DIR="/tmp/gcm-install"
|
TEMP_DIR="/tmp/gcm-install"
|
||||||
|
|
||||||
# Function to print colored output
|
# Function to print colored output
|
||||||
@@ -90,7 +91,7 @@ get_arch() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to get current installed version
|
# Function to get current installed version and location
|
||||||
get_current_version() {
|
get_current_version() {
|
||||||
if command_exists git-credential-manager; then
|
if command_exists git-credential-manager; then
|
||||||
# Extract version from output like "2.6.1+786ab03440ddc82e807a97c0e540f5247e44cec6"
|
# Extract version from output like "2.6.1+786ab03440ddc82e807a97c0e540f5247e44cec6"
|
||||||
@@ -101,10 +102,21 @@ get_current_version() {
|
|||||||
else
|
else
|
||||||
CURRENT_VERSION="unknown"
|
CURRENT_VERSION="unknown"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Determine installation location
|
||||||
|
GCM_PATH=$(which git-credential-manager)
|
||||||
|
if [[ "$GCM_PATH" == "$HOME/bin"* ]]; then
|
||||||
|
INSTALL_TYPE="user"
|
||||||
|
elif [[ "$GCM_PATH" == "/usr/local/bin"* ]] || [[ "$GCM_PATH" == "/usr/bin"* ]]; then
|
||||||
|
INSTALL_TYPE="system"
|
||||||
|
else
|
||||||
|
INSTALL_TYPE="other"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
CURRENT_VERSION="not_installed"
|
CURRENT_VERSION="not_installed"
|
||||||
|
INSTALL_TYPE="none"
|
||||||
fi
|
fi
|
||||||
echo "$CURRENT_VERSION"
|
echo "$CURRENT_VERSION:$INSTALL_TYPE"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to compare versions (returns 0 if first >= second, 1 if first < second)
|
# Function to compare versions (returns 0 if first >= second, 1 if first < second)
|
||||||
@@ -166,25 +178,27 @@ get_latest_release() {
|
|||||||
|
|
||||||
# Function to check if update is needed
|
# Function to check if update is needed
|
||||||
check_update_needed() {
|
check_update_needed() {
|
||||||
local current_version=$(get_current_version)
|
local current_info=$(get_current_version)
|
||||||
|
local current_version=$(echo "$current_info" | cut -d: -f1)
|
||||||
|
local install_type=$(echo "$current_info" | cut -d: -f2)
|
||||||
local latest_version="$1"
|
local latest_version="$1"
|
||||||
|
|
||||||
print_status "Current version: $current_version"
|
print_status "Current version: $current_version ($install_type)"
|
||||||
print_status "Latest version: $latest_version"
|
print_status "Latest version: $latest_version"
|
||||||
|
|
||||||
if [[ "$current_version" == "not_installed" ]]; then
|
if [[ "$current_version" == "not_installed" ]]; then
|
||||||
print_status "git-credential-manager is not installed"
|
print_status "git-credential-manager is not installed"
|
||||||
return 0 # Need to install
|
return 0 # Need to install
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$current_version" == "unknown" ]]; then
|
if [[ "$current_version" == "unknown" ]]; then
|
||||||
print_warning "Cannot determine current version, proceeding with update"
|
print_warning "Cannot determine current version, proceeding with update"
|
||||||
return 0 # Assume update needed
|
return 0 # Assume update needed
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if compare_versions "$latest_version" "$current_version"; then
|
if compare_versions "$latest_version" "$current_version"; then
|
||||||
if [[ "$latest_version" == "$current_version" ]]; then
|
if [[ "$latest_version" == "$current_version" ]]; then
|
||||||
print_success "You already have the latest version ($current_version)"
|
print_success "You already have the latest version ($current_version) installed at $install_type location"
|
||||||
if [[ "$force_reinstall" == "true" ]]; then
|
if [[ "$force_reinstall" == "true" ]]; then
|
||||||
print_status "Force reinstall requested, proceeding..."
|
print_status "Force reinstall requested, proceeding..."
|
||||||
return 0
|
return 0
|
||||||
@@ -327,9 +341,16 @@ install_from_tarball() {
|
|||||||
cd "$extracted_dir"
|
cd "$extracted_dir"
|
||||||
print_status "Installing binary to $INSTALL_DIR..."
|
print_status "Installing binary to $INSTALL_DIR..."
|
||||||
sudo install -m 755 git-credential-manager "$INSTALL_DIR/git-credential-manager"
|
sudo install -m 755 git-credential-manager "$INSTALL_DIR/git-credential-manager"
|
||||||
|
|
||||||
|
# Verify installation
|
||||||
|
if [[ ! -f "$INSTALL_DIR/git-credential-manager" ]]; then
|
||||||
|
print_error "Failed to install Git Credential Manager binary"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
sudo ln -sf "$INSTALL_DIR/git-credential-manager" "$INSTALL_DIR/git-credential-manager-core"
|
sudo ln -sf "$INSTALL_DIR/git-credential-manager" "$INSTALL_DIR/git-credential-manager-core"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
print_success "Binary installed successfully"
|
print_success "Binary installed successfully"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,6 +472,19 @@ verify_installation() {
|
|||||||
# Check all presets
|
# Check all presets
|
||||||
configure_git_presets
|
configure_git_presets
|
||||||
|
|
||||||
|
# Check for user bin version and offer removal
|
||||||
|
if [[ -f "$USER_BIN_DIR/git-credential-manager" ]]; then
|
||||||
|
print_warning "Found git-credential-manager in user bin directory ($USER_BIN_DIR)"
|
||||||
|
print_status "This might take precedence if $USER_BIN_DIR is in PATH before system paths"
|
||||||
|
echo
|
||||||
|
read -p "Would you like to remove the user bin version? (y/N): " -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
rm -f "$USER_BIN_DIR/git-credential-manager"
|
||||||
|
print_success "Removed user bin version"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
print_error "git-credential-manager installation verification failed"
|
print_error "git-credential-manager installation verification failed"
|
||||||
@@ -476,6 +510,8 @@ show_usage() {
|
|||||||
echo " -h, --help Show this help message"
|
echo " -h, --help Show this help message"
|
||||||
echo " -v, --version Install specific version (default: latest)"
|
echo " -v, --version Install specific version (default: latest)"
|
||||||
echo " -f, --force Force reinstall even if already installed"
|
echo " -f, --force Force reinstall even if already installed"
|
||||||
|
echo " -r, --reinstall Reinstall the current installed version"
|
||||||
|
echo " -l, --local Force installation to user bin directory (~/.bin)"
|
||||||
echo " -p, --package Force installation from package manager"
|
echo " -p, --package Force installation from package manager"
|
||||||
echo " -d, --deb Force installation from DEB package"
|
echo " -d, --deb Force installation from DEB package"
|
||||||
echo " -t, --tarball Force installation from tarball"
|
echo " -t, --tarball Force installation from tarball"
|
||||||
@@ -484,6 +520,8 @@ show_usage() {
|
|||||||
echo "Examples:"
|
echo "Examples:"
|
||||||
echo " $0 # Install latest version using best method"
|
echo " $0 # Install latest version using best method"
|
||||||
echo " $0 -v v2.6.0 # Install specific version"
|
echo " $0 -v v2.6.0 # Install specific version"
|
||||||
|
echo " $0 --reinstall # Reinstall current version"
|
||||||
|
echo " $0 --local # Force installation to user bin"
|
||||||
echo " $0 --package # Force installation from package manager"
|
echo " $0 --package # Force installation from package manager"
|
||||||
echo " $0 --deb # Force installation from DEB package"
|
echo " $0 --deb # Force installation from DEB package"
|
||||||
echo " $0 --checks # Check configuration without installing"
|
echo " $0 --checks # Check configuration without installing"
|
||||||
@@ -519,6 +557,8 @@ run_checks_only() {
|
|||||||
main() {
|
main() {
|
||||||
local target_version=""
|
local target_version=""
|
||||||
local force_reinstall=false
|
local force_reinstall=false
|
||||||
|
local reinstall_current=false
|
||||||
|
local local_install=false
|
||||||
local install_method="auto"
|
local install_method="auto"
|
||||||
local checks_only=false
|
local checks_only=false
|
||||||
|
|
||||||
@@ -537,6 +577,14 @@ main() {
|
|||||||
force_reinstall=true
|
force_reinstall=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-r|--reinstall)
|
||||||
|
reinstall_current=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-l|--local)
|
||||||
|
local_install=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-p|--package)
|
-p|--package)
|
||||||
install_method="package"
|
install_method="package"
|
||||||
shift
|
shift
|
||||||
@@ -566,12 +614,25 @@ main() {
|
|||||||
run_checks_only
|
run_checks_only
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "========================================"
|
echo "========================================"
|
||||||
echo "Git Credential Manager Installer"
|
echo "Git Credential Manager Installer"
|
||||||
echo "========================================"
|
echo "========================================"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
# Handle reinstall current version
|
||||||
|
if [[ "$reinstall_current" == "true" ]]; then
|
||||||
|
local current_info=$(get_current_version)
|
||||||
|
local current_version=$(echo "$current_info" | cut -d: -f1)
|
||||||
|
if [[ "$current_version" == "not_installed" ]]; then
|
||||||
|
print_error "No current version installed to reinstall"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
target_version="$current_version"
|
||||||
|
force_reinstall=true
|
||||||
|
print_status "Reinstalling current version: $target_version"
|
||||||
|
fi
|
||||||
|
|
||||||
# Get latest version if not specified
|
# Get latest version if not specified
|
||||||
if [[ -z "$target_version" ]]; then
|
if [[ -z "$target_version" ]]; then
|
||||||
get_latest_release
|
get_latest_release
|
||||||
@@ -589,13 +650,19 @@ main() {
|
|||||||
# Detect system
|
# Detect system
|
||||||
detect_os
|
detect_os
|
||||||
ARCH=$(get_arch)
|
ARCH=$(get_arch)
|
||||||
|
|
||||||
|
# Check for local installation
|
||||||
|
if [[ "$local_install" == "true" ]]; then
|
||||||
|
print_error "Git Credential Manager requires system installation for proper integration"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Create temporary directory
|
# Create temporary directory
|
||||||
mkdir -p "$TEMP_DIR"
|
mkdir -p "$TEMP_DIR"
|
||||||
|
|
||||||
# Trap cleanup on exit
|
# Trap cleanup on exit
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
# Installation logic based on method
|
# Installation logic based on method
|
||||||
case $install_method in
|
case $install_method in
|
||||||
auto)
|
auto)
|
||||||
@@ -604,7 +671,7 @@ main() {
|
|||||||
verify_installation
|
verify_installation
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fall back to distribution-specific methods
|
# Fall back to distribution-specific methods
|
||||||
case $OS in
|
case $OS in
|
||||||
ubuntu|debian|linuxmint)
|
ubuntu|debian|linuxmint)
|
||||||
@@ -627,6 +694,10 @@ main() {
|
|||||||
tarball)
|
tarball)
|
||||||
install_from_tarball "$ARCH" "$target_version"
|
install_from_tarball "$ARCH" "$target_version"
|
||||||
;;
|
;;
|
||||||
|
*)
|
||||||
|
print_error "Unknown install method: $install_method"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Verify installation
|
# Verify installation
|
||||||
|
|||||||
@@ -154,37 +154,52 @@ check_version_symlink() {
|
|||||||
|
|
||||||
# Function to determine installation strategy
|
# Function to determine installation strategy
|
||||||
determine_install_strategy() {
|
determine_install_strategy() {
|
||||||
|
local local_install="$1"
|
||||||
local current_info=$(get_current_version)
|
local current_info=$(get_current_version)
|
||||||
local current_version=$(echo "$current_info" | cut -d: -f1)
|
local current_version=$(echo "$current_info" | cut -d: -f1)
|
||||||
local install_type=$(echo "$current_info" | cut -d: -f2)
|
local install_type=$(echo "$current_info" | cut -d: -f2)
|
||||||
|
|
||||||
# Strategy 1: Check user bin directory first
|
# Strategy: Check installation type preference
|
||||||
if check_user_bin_setup; then
|
if [[ "$local_install" == "true" ]]; then
|
||||||
print_status "User bin directory is available and in PATH"
|
print_status "Local installation requested"
|
||||||
|
if check_user_bin_setup; then
|
||||||
# Check if tea exists in user bin
|
print_status "User bin directory is available and in PATH"
|
||||||
if [[ -f "$USER_BIN_DIR/tea" ]]; then
|
|
||||||
print_status "Tea CLI found in user bin directory"
|
|
||||||
|
|
||||||
# Check for version symlink
|
|
||||||
if check_version_symlink; then
|
|
||||||
print_status "Version symlink found: $CURRENT_SYMLINK_VERSION"
|
|
||||||
INSTALL_STRATEGY="user_update"
|
|
||||||
TARGET_DIR="$USER_BIN_DIR"
|
|
||||||
else
|
|
||||||
print_status "No version symlink found, will create one"
|
|
||||||
INSTALL_STRATEGY="user_upgrade"
|
|
||||||
TARGET_DIR="$USER_BIN_DIR"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
print_status "Tea CLI not found in user bin, will install there"
|
|
||||||
INSTALL_STRATEGY="user_install"
|
INSTALL_STRATEGY="user_install"
|
||||||
TARGET_DIR="$USER_BIN_DIR"
|
TARGET_DIR="$USER_BIN_DIR"
|
||||||
|
else
|
||||||
|
print_error "User bin directory not available for local installation"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
print_status "User bin directory not available, using system installation"
|
# Prefer system installation for all users
|
||||||
INSTALL_STRATEGY="system_install"
|
if [[ $EUID -eq 0 ]]; then
|
||||||
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
print_status "Running as root, installing system-wide"
|
||||||
|
INSTALL_STRATEGY="system_install"
|
||||||
|
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||||
|
elif sudo -n true 2>/dev/null; then
|
||||||
|
print_status "Passwordless sudo available, installing system-wide"
|
||||||
|
INSTALL_STRATEGY="system_install"
|
||||||
|
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||||
|
elif command_exists sudo; then
|
||||||
|
print_status "Testing sudo access (you may be prompted for password)..."
|
||||||
|
if sudo -v 2>/dev/null; then
|
||||||
|
print_success "Sudo access confirmed, installing system-wide"
|
||||||
|
INSTALL_STRATEGY="system_install"
|
||||||
|
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||||
|
else
|
||||||
|
print_error "Sudo access failed. Use --local to install to user bin directory"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_error "Sudo not available. Use --local to install to user bin directory"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Warn if user bin has tea (only for system installs)
|
||||||
|
if [[ "$INSTALL_STRATEGY" == "system_install" ]] && [[ -f "$USER_BIN_DIR/tea" ]]; then
|
||||||
|
print_warning "Tea CLI found in user bin directory ($USER_BIN_DIR)"
|
||||||
|
print_status "This might take precedence if $USER_BIN_DIR is in PATH before system paths"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
print_status "Installation strategy: $INSTALL_STRATEGY"
|
print_status "Installation strategy: $INSTALL_STRATEGY"
|
||||||
@@ -274,7 +289,7 @@ check_update_needed() {
|
|||||||
|
|
||||||
if compare_versions "$clean_latest" "$clean_current"; then
|
if compare_versions "$clean_latest" "$clean_current"; then
|
||||||
if [[ "$clean_latest" == "$clean_current" ]]; then
|
if [[ "$clean_latest" == "$clean_current" ]]; then
|
||||||
print_success "You already have the latest version ($current_version)"
|
print_success "You already have the latest version ($current_version) installed at $install_type location"
|
||||||
if [[ "$force_reinstall" == "true" ]]; then
|
if [[ "$force_reinstall" == "true" ]]; then
|
||||||
print_status "Force reinstall requested, proceeding..."
|
print_status "Force reinstall requested, proceeding..."
|
||||||
return 0
|
return 0
|
||||||
@@ -317,60 +332,9 @@ download_file() {
|
|||||||
|
|
||||||
# Function to install Tea CLI from package manager
|
# Function to install Tea CLI from package manager
|
||||||
install_tea_from_package_manager() {
|
install_tea_from_package_manager() {
|
||||||
# Package manager installation only works for system-wide installation
|
# Package manager installation is not reliable for Tea CLI, use binary instead
|
||||||
if [[ "$INSTALL_STRATEGY" == user* ]]; then
|
print_warning "Package manager installation not supported for Tea CLI to ensure correct version, using binary instead"
|
||||||
print_status "Skipping package manager for user installation"
|
return 1
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
print_status "Attempting to install Tea CLI from package manager..."
|
|
||||||
|
|
||||||
case $PKG_MANAGER in
|
|
||||||
apt)
|
|
||||||
# Add Gitea repository if not present
|
|
||||||
if ! grep -q "https://dl.gitea.com/gitea/gpg.key" /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null; then
|
|
||||||
print_status "Adding Gitea repository..."
|
|
||||||
curl -fsSL https://dl.gitea.com/gitea/gpg.key | sudo apt-key add -
|
|
||||||
echo "deb https://dl.gitea.com/gitea/ gitea main" | sudo tee /etc/apt/sources.list.d/gitea.list
|
|
||||||
sudo apt update
|
|
||||||
fi
|
|
||||||
|
|
||||||
sudo apt install -y tea
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
yum)
|
|
||||||
# Add Gitea repository
|
|
||||||
print_status "Adding Gitea repository..."
|
|
||||||
sudo yum-config-manager --add-repo https://dl.gitea.com/gitea/RPM/GPG.KEY
|
|
||||||
sudo yum-config-manager --add-repo https://dl.gitea.com/gitea/yum/ gitea
|
|
||||||
sudo yum install -y tea
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
dnf)
|
|
||||||
# Add Gitea repository
|
|
||||||
print_status "Adding Gitea repository..."
|
|
||||||
sudo dnf config-manager --add-repo https://dl.gitea.com/gitea/RPM/GPG.KEY
|
|
||||||
sudo dnf config-manager --add-repo https://dl.gitea.com/gitea/yum/ gitea
|
|
||||||
sudo dnf install -y tea
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
pacman)
|
|
||||||
# Tea CLI is in AUR
|
|
||||||
print_warning "Tea CLI is available in AUR. Consider using 'yay -S tea' or 'pacaur -S tea'"
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
zypper)
|
|
||||||
print_status "Adding Gitea repository..."
|
|
||||||
sudo zypper addrepo -G https://dl.gitea.com/gitea/RPM/GPG.KEY
|
|
||||||
sudo zypper addrepo https://dl.gitea.com/gitea/yum/ gitea
|
|
||||||
sudo zypper install -y tea
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
print_warning "Package manager $PKG_MANAGER not supported for automatic installation"
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to install Tea CLI from binary
|
# Function to install Tea CLI from binary
|
||||||
@@ -397,6 +361,15 @@ install_tea_from_binary() {
|
|||||||
# Install the binary with version suffix
|
# Install the binary with version suffix
|
||||||
$install_cmd "$TEMP_DIR/$binary_name" "$TARGET_DIR/tea-$version"
|
$install_cmd "$TEMP_DIR/$binary_name" "$TARGET_DIR/tea-$version"
|
||||||
|
|
||||||
|
# Verify installation
|
||||||
|
if [[ ! -f "$TARGET_DIR/tea-$version" ]]; then
|
||||||
|
print_error "Failed to install Tea CLI binary"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove any existing tea symlink or file to avoid conflicts
|
||||||
|
rm -f "$TARGET_DIR/tea"
|
||||||
|
|
||||||
# Create/update symlink to point to this version
|
# Create/update symlink to point to this version
|
||||||
$symlink_cmd "$TARGET_DIR/tea-$version" "$TARGET_DIR/tea"
|
$symlink_cmd "$TARGET_DIR/tea-$version" "$TARGET_DIR/tea"
|
||||||
|
|
||||||
@@ -407,10 +380,38 @@ install_tea_from_binary() {
|
|||||||
# Function to verify Tea CLI installation
|
# Function to verify Tea CLI installation
|
||||||
verify_tea_installation() {
|
verify_tea_installation() {
|
||||||
print_status "Verifying Tea CLI installation..."
|
print_status "Verifying Tea CLI installation..."
|
||||||
|
|
||||||
if command_exists tea; then
|
if command_exists tea; then
|
||||||
local version=$(tea --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n 1)
|
local version=$(tea --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n 1)
|
||||||
print_success "Tea CLI installed: $version"
|
print_success "Tea CLI installed: $version"
|
||||||
|
|
||||||
|
# Check for user bin versions and offer removal
|
||||||
|
if [[ -d "$USER_BIN_DIR" ]] && [[ "$TARGET_DIR" == "$SYSTEM_INSTALL_DIR" ]]; then
|
||||||
|
local user_versions=()
|
||||||
|
for file in "$USER_BIN_DIR"/tea*; do
|
||||||
|
if [[ -f "$file" ]]; then
|
||||||
|
user_versions+=("$file")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ${#user_versions[@]} -gt 0 ]]; then
|
||||||
|
print_warning "Found tea binaries in user bin directory:"
|
||||||
|
for file in "${user_versions[@]}"; do
|
||||||
|
echo " $file"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
read -p "Would you like to remove these user bin versions? (y/N): " -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
for file in "${user_versions[@]}"; do
|
||||||
|
rm -f "$file"
|
||||||
|
print_status "Removed $file"
|
||||||
|
done
|
||||||
|
print_success "Removed all user bin versions"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
print_error "Tea CLI installation verification failed"
|
print_error "Tea CLI installation verification failed"
|
||||||
@@ -436,12 +437,16 @@ show_usage() {
|
|||||||
echo " -h, --help Show this help message"
|
echo " -h, --help Show this help message"
|
||||||
echo " -v, --version Install specific version (default: latest)"
|
echo " -v, --version Install specific version (default: latest)"
|
||||||
echo " -f, --force Force reinstall even if up-to-date"
|
echo " -f, --force Force reinstall even if up-to-date"
|
||||||
|
echo " -r, --reinstall Reinstall the current installed version"
|
||||||
|
echo " -l, --local Force installation to user bin directory (~/.bin)"
|
||||||
echo " -p, --package Force installation from package manager"
|
echo " -p, --package Force installation from package manager"
|
||||||
echo " -b, --binary Force installation from binary"
|
echo " -b, --binary Force installation from binary"
|
||||||
echo
|
echo
|
||||||
echo "Examples:"
|
echo "Examples:"
|
||||||
echo " $0 # Install latest version using best method"
|
echo " $0 # Install latest version using best method"
|
||||||
echo " $0 -v v0.10.0 # Install specific version"
|
echo " $0 -v v0.10.0 # Install specific version"
|
||||||
|
echo " $0 --reinstall # Reinstall current version"
|
||||||
|
echo " $0 --local # Force installation to user bin"
|
||||||
echo " $0 --package # Force installation from package manager"
|
echo " $0 --package # Force installation from package manager"
|
||||||
echo " $0 --binary # Force installation from binary"
|
echo " $0 --binary # Force installation from binary"
|
||||||
echo
|
echo
|
||||||
@@ -451,8 +456,10 @@ show_usage() {
|
|||||||
main() {
|
main() {
|
||||||
local target_version=""
|
local target_version=""
|
||||||
local force_reinstall=false
|
local force_reinstall=false
|
||||||
|
local reinstall_current=false
|
||||||
|
local local_install=false
|
||||||
local install_method="auto"
|
local install_method="auto"
|
||||||
|
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
@@ -468,6 +475,14 @@ main() {
|
|||||||
force_reinstall=true
|
force_reinstall=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-r|--reinstall)
|
||||||
|
reinstall_current=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-l|--local)
|
||||||
|
local_install=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-p|--package)
|
-p|--package)
|
||||||
install_method="package"
|
install_method="package"
|
||||||
shift
|
shift
|
||||||
@@ -493,11 +508,24 @@ main() {
|
|||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
print_warning "Not running as root. Some operations may require sudo."
|
print_warning "Not running as root. Some operations may require sudo."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Detect system
|
# Detect system
|
||||||
detect_os
|
detect_os
|
||||||
ARCH=$(get_arch)
|
ARCH=$(get_arch)
|
||||||
|
|
||||||
|
# Handle reinstall current version
|
||||||
|
if [[ "$reinstall_current" == "true" ]]; then
|
||||||
|
local current_info=$(get_current_version)
|
||||||
|
local current_version=$(echo "$current_info" | cut -d: -f1)
|
||||||
|
if [[ "$current_version" == "not_installed" ]]; then
|
||||||
|
print_error "No current version installed to reinstall"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
target_version="$current_version"
|
||||||
|
force_reinstall=true
|
||||||
|
print_status "Reinstalling current version: $target_version"
|
||||||
|
fi
|
||||||
|
|
||||||
# Get latest version if not specified
|
# Get latest version if not specified
|
||||||
if [[ -z "$target_version" ]]; then
|
if [[ -z "$target_version" ]]; then
|
||||||
get_latest_release
|
get_latest_release
|
||||||
@@ -507,7 +535,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Determine installation strategy
|
# Determine installation strategy
|
||||||
determine_install_strategy
|
determine_install_strategy "$local_install"
|
||||||
|
|
||||||
# Check if update is needed
|
# Check if update is needed
|
||||||
if ! check_update_needed "$target_version"; then
|
if ! check_update_needed "$target_version"; then
|
||||||
|
|||||||
Reference in New Issue
Block a user