Add credential checks for known Gitea instances https://go-gitea.mywire.org and http://192.168.88.97:3000
This commit is contained in:
@@ -16,6 +16,9 @@ NC='\033[0m' # No Color
|
|||||||
# Configuration file path
|
# Configuration file path
|
||||||
CONFIG_FILE="$(dirname "$0")/config.json"
|
CONFIG_FILE="$(dirname "$0")/config.json"
|
||||||
|
|
||||||
|
# Known Gitea URLs to check credentials for
|
||||||
|
KNOWN_GITEA_URLS=("https://go-gitea.mywire.org" "http://192.168.88.97:3000")
|
||||||
|
|
||||||
# Function to print colored output
|
# Function to print colored output
|
||||||
print_status() {
|
print_status() {
|
||||||
echo -e "${BLUE}[INFO]${NC} $1"
|
echo -e "${BLUE}[INFO]${NC} $1"
|
||||||
@@ -68,6 +71,64 @@ install_tea_cli() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to check and setup credentials for known Gitea instances
|
||||||
|
check_and_setup_known_gitea_credentials() {
|
||||||
|
print_status "Checking credentials for known Gitea instances..."
|
||||||
|
|
||||||
|
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 "Skipping credential setup for known instances"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
for url in "${KNOWN_GITEA_URLS[@]}"; do
|
||||||
|
local domain=$(echo "$url" | sed 's|https://||' | sed 's|http://||')
|
||||||
|
if git config --global credential."https://$domain".helper >/dev/null 2>&1; then
|
||||||
|
print_success "Credentials already configured for $url"
|
||||||
|
else
|
||||||
|
print_status "Configuring credentials for $url"
|
||||||
|
local cmd="git config --global credential.\"https://$domain\".helper \"$credential_helper\""
|
||||||
|
echo "Running: $cmd"
|
||||||
|
eval "$cmd"
|
||||||
|
print_success "Credentials configured for $url"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
# Function to detect and configure credential manager
|
# Function to detect and configure credential manager
|
||||||
setup_credential_manager() {
|
setup_credential_manager() {
|
||||||
print_status "Checking for Git credential managers..."
|
print_status "Checking for Git credential managers..."
|
||||||
@@ -420,6 +481,9 @@ main() {
|
|||||||
print_error "Git is not installed. Please install Git first."
|
print_error "Git is not installed. Please install Git first."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check and setup credentials for known Gitea instances
|
||||||
|
check_and_setup_known_gitea_credentials
|
||||||
|
|
||||||
# Load configuration if available
|
# Load configuration if available
|
||||||
CONFIG_LOADED=false
|
CONFIG_LOADED=false
|
||||||
|
|||||||
Reference in New Issue
Block a user