Add CLI installers for Tea, Borg, and Git Credential Manager, and enhance setup script with improved authentication
This commit is contained in:
@@ -38,6 +38,91 @@ command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Function to install Git Credential Manager if needed
|
||||
install_credential_manager() {
|
||||
local script_dir="$(dirname "$0")"
|
||||
local installer="$script_dir/install-git-credential-manager.sh"
|
||||
|
||||
if [[ -f "$installer" ]]; then
|
||||
print_status "Running Git Credential Manager installer..."
|
||||
"$installer"
|
||||
return $?
|
||||
else
|
||||
print_warning "Git Credential Manager installer not found at $installer"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to install Tea CLI if needed
|
||||
install_tea_cli() {
|
||||
local script_dir="$(dirname "$0")"
|
||||
local installer="$script_dir/install-tea-cli.sh"
|
||||
|
||||
if [[ -f "$installer" ]]; then
|
||||
print_status "Running Tea CLI installer..."
|
||||
"$installer"
|
||||
return $?
|
||||
else
|
||||
print_warning "Tea CLI installer not found at $installer"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to detect and configure credential manager
|
||||
setup_credential_manager() {
|
||||
print_status "Checking for Git credential managers..."
|
||||
|
||||
local credential_helper=""
|
||||
|
||||
# Check for Git Credential Manager (GCM)
|
||||
if command_exists git-credential-manager; then
|
||||
credential_helper="manager"
|
||||
print_success "Found Git Credential Manager"
|
||||
# Check for platform-specific helpers
|
||||
elif [[ "$OSTYPE" == "darwin"* ]] && git config --global --get credential.helper 2>/dev/null | grep -q "osxkeychain"; then
|
||||
credential_helper="osxkeychain"
|
||||
print_success "Found macOS Keychain credential helper"
|
||||
elif [[ "$OSTYPE" == "linux-gnu"* ]] && command_exists gnome-keyring-daemon; then
|
||||
credential_helper="/usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring"
|
||||
print_success "Found GNOME Keyring"
|
||||
# Fallback to generic manager
|
||||
elif git config --global --get credential.helper >/dev/null 2>&1; then
|
||||
credential_helper=$(git config --global --get credential.helper)
|
||||
print_success "Using existing credential helper: $credential_helper"
|
||||
else
|
||||
print_warning "No credential manager found"
|
||||
|
||||
# Offer to install Git Credential Manager
|
||||
echo
|
||||
read -p "Would you like to install Git Credential Manager for secure credential storage? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
if install_credential_manager; then
|
||||
credential_helper="manager"
|
||||
print_success "Git Credential Manager installed successfully"
|
||||
else
|
||||
print_warning "Failed to install Git Credential Manager"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
print_warning "Continuing without credential manager - you will be prompted for credentials"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Configure credential helper for the specific Gitea instance
|
||||
if [[ -n "$GITEA_URL" ]]; then
|
||||
local domain=$(echo "$GITEA_URL" | sed 's|https://||' | sed 's|http://||')
|
||||
git config --global credential."https://$domain".helper "$credential_helper"
|
||||
print_success "Configured credential manager for $domain"
|
||||
else
|
||||
git config --global credential.helper "$credential_helper"
|
||||
print_success "Configured global credential manager"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Function to validate input
|
||||
validate_input() {
|
||||
if [[ -z "$1" ]]; then
|
||||
@@ -113,73 +198,71 @@ setup_ssh_key() {
|
||||
|
||||
# Function to setup tea CLI
|
||||
setup_tea() {
|
||||
print_status "Setting up tea CLI..."
|
||||
|
||||
print_status "Setting up Tea CLI..."
|
||||
|
||||
if ! command_exists tea; then
|
||||
print_status "Installing tea CLI..."
|
||||
|
||||
# Detect OS and install tea
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Linux
|
||||
if command_exists apt; then
|
||||
# Try to install from package manager first
|
||||
sudo apt update && sudo apt install -y tea || {
|
||||
print_warning "tea not available in package manager, installing from binary..."
|
||||
curl -sL https://dl.gitea.com/tea/latest/tea-linux-amd64 -o /tmp/tea
|
||||
chmod +x /tmp/tea
|
||||
sudo mv /tmp/tea /usr/local/bin/tea
|
||||
}
|
||||
elif command_exists yum; then
|
||||
sudo yum install -y tea || {
|
||||
print_warning "tea not available in package manager, installing from binary..."
|
||||
curl -sL https://dl.gitea.com/tea/latest/tea-linux-amd64 -o /tmp/tea
|
||||
chmod +x /tmp/tea
|
||||
sudo mv /tmp/tea /usr/local/bin/tea
|
||||
}
|
||||
elif command_exists pacman; then
|
||||
sudo pacman -S --noconfirm tea || {
|
||||
print_warning "tea not available in package manager, installing from binary..."
|
||||
curl -sL https://dl.gitea.com/tea/latest/tea-linux-amd64 -o /tmp/tea
|
||||
chmod +x /tmp/tea
|
||||
sudo mv /tmp/tea /usr/local/bin/tea
|
||||
}
|
||||
print_warning "Tea CLI is not installed"
|
||||
|
||||
# Offer to install Tea CLI
|
||||
echo
|
||||
read -p "Would you like to install Tea CLI for Gitea repository management? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
if install_tea_cli; then
|
||||
print_success "Tea CLI installed successfully"
|
||||
else
|
||||
# Generic Linux installation
|
||||
curl -sL https://dl.gitea.com/tea/latest/tea-linux-amd64 -o /tmp/tea
|
||||
chmod +x /tmp/tea
|
||||
sudo mv /tmp/tea /usr/local/bin/tea
|
||||
fi
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS
|
||||
if command_exists brew; then
|
||||
brew install tea
|
||||
else
|
||||
print_error "Homebrew not found. Please install Homebrew first."
|
||||
exit 1
|
||||
print_error "Failed to install Tea CLI"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
print_error "Unsupported OS for automatic tea installation"
|
||||
exit 1
|
||||
print_warning "Continuing without Tea CLI - you can install it later with ./install-tea-cli.sh"
|
||||
return 1
|
||||
fi
|
||||
|
||||
print_success "tea CLI installed successfully"
|
||||
else
|
||||
print_success "tea CLI is already installed"
|
||||
print_success "Tea CLI is already installed"
|
||||
fi
|
||||
|
||||
|
||||
# Configure tea login with presets
|
||||
print_status "Configuring tea login..."
|
||||
|
||||
print_status "Configuring Tea CLI login..."
|
||||
|
||||
# Use defaults from config if available
|
||||
local tea_url="${GITEA_URL:-$GITEA_URL}"
|
||||
local tea_method="${LOGIN_METHOD:-token}"
|
||||
local tea_has_token="${HAS_ACCESS_TOKEN:-true}"
|
||||
|
||||
|
||||
echo "Using preset configuration:"
|
||||
echo "- URL: $tea_url"
|
||||
echo "- Method: $tea_method"
|
||||
echo "- Has token: $tea_has_token"
|
||||
echo
|
||||
|
||||
# Check for existing logins
|
||||
print_status "Checking existing Tea CLI logins..."
|
||||
if tea logins 2>/dev/null | grep -q "No logins"; then
|
||||
echo "No existing logins found. Creating new login..."
|
||||
tea login add
|
||||
else
|
||||
echo "Existing logins found:"
|
||||
tea logins
|
||||
echo
|
||||
read -p "Do you want to use an existing login? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
read -p "Enter the name of the existing login to use: " existing_login
|
||||
if tea logins | grep -q "$existing_login"; then
|
||||
print_success "Using existing login: $existing_login"
|
||||
# Set the existing login as default for this session
|
||||
export TEA_LOGIN="$existing_login"
|
||||
else
|
||||
print_warning "Login '$existing_login' not found. Creating new login..."
|
||||
tea login add
|
||||
fi
|
||||
else
|
||||
echo "Creating new login..."
|
||||
tea login add
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Check for existing logins
|
||||
print_status "Checking existing tea logins..."
|
||||
@@ -383,8 +466,8 @@ main() {
|
||||
|
||||
echo
|
||||
echo "Choose authentication method:"
|
||||
echo "1) SSH (recommended - passwordless after setup)"
|
||||
echo "2) HTTPS (may prompt for password/token)"
|
||||
echo "1) SSH (recommended - passwordless after key setup)"
|
||||
echo "2) HTTPS with credential manager (secure, stores tokens)"
|
||||
echo "3) Tea CLI (creates repo via API)"
|
||||
|
||||
# Use default auth method from config if available
|
||||
@@ -410,8 +493,23 @@ main() {
|
||||
2)
|
||||
AUTH_METHOD="https"
|
||||
print_status "HTTPS authentication selected"
|
||||
|
||||
# Setup credential manager for passwordless authentication
|
||||
if setup_credential_manager; then
|
||||
print_success "Credential manager configured for passwordless HTTPS access"
|
||||
echo "You will be prompted for credentials on first use, then they will be stored securely."
|
||||
else
|
||||
print_warning "No credential manager available. You will be prompted for credentials each time."
|
||||
echo "Consider installing git-credential-manager for secure credential storage."
|
||||
fi
|
||||
|
||||
REMOTE_URL="$GITEA_URL/$GITEA_USERNAME/$REPO_NAME.git"
|
||||
print_warning "Make sure you have an access token or will be prompted for credentials"
|
||||
echo
|
||||
echo "HTTPS Authentication Setup:"
|
||||
echo "1. Generate a Personal Access Token in Gitea: User Settings → Applications"
|
||||
echo "2. Use your username and the access token when prompted"
|
||||
echo "3. Credentials will be stored securely by your credential manager"
|
||||
echo
|
||||
;;
|
||||
3)
|
||||
AUTH_METHOD="tea"
|
||||
@@ -454,6 +552,11 @@ main() {
|
||||
echo "SSH setup reminder:"
|
||||
echo "- Make sure your SSH public key is added to your Gitea account"
|
||||
echo "- SSH key location: $HOME/.ssh/id_ed25519.pub"
|
||||
elif [[ "$AUTH_METHOD" == "https" ]]; then
|
||||
echo "HTTPS setup reminder:"
|
||||
echo "- Use your Personal Access Token as password when prompted"
|
||||
echo "- Credentials are stored securely by your credential manager"
|
||||
echo "- Generate tokens at: $GITEA_URL/user/settings/applications"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user