Add --checks option to display detailed credential status for known Gitea instances

This commit is contained in:
kdusek
2025-11-13 17:34:03 +01:00
parent 2519fee6d5
commit 445d8050a6

View File

@@ -19,6 +19,9 @@ CONFIG_FILE="$(dirname "$0")/config.json"
# Known Gitea URLs to check credentials for # Known Gitea URLs to check credentials for
KNOWN_GITEA_URLS=("https://go-gitea.mywire.org" "http://192.168.88.97:3000") KNOWN_GITEA_URLS=("https://go-gitea.mywire.org" "http://192.168.88.97:3000")
# Mode flags
CHECKS_MODE=false
# 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"
@@ -71,6 +74,60 @@ install_tea_cli() {
fi fi
} }
# Function to show detailed credential status for known Gitea instances
show_gitea_credential_status() {
print_status "Checking credential status for known Gitea instances..."
for url in "${KNOWN_GITEA_URLS[@]}"; do
local domain=$(echo "$url" | sed 's|https://||' | sed 's|http://||')
echo
echo "Gitea Instance: $url"
echo "Domain: $domain"
echo "Credential Config Key: credential.https://$domain.helper"
local helper=$(git config --global credential."https://$domain".helper 2>/dev/null)
if [[ -n "$helper" ]]; then
echo "Configured Helper: $helper"
# Check if the helper command exists
case "$helper" in
"manager")
if command_exists git-credential-manager; then
echo "Helper Status: Available (Git Credential Manager)"
else
echo "Helper Status: Configured but not installed"
fi
;;
"osxkeychain")
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "Helper Status: Available (macOS Keychain)"
else
echo "Helper Status: Not applicable on this OS"
fi
;;
"/usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring")
if command_exists gnome-keyring-daemon; then
echo "Helper Status: Available (GNOME Keyring)"
else
echo "Helper Status: Configured but GNOME Keyring not available"
fi
;;
*)
if command_exists "$helper"; then
echo "Helper Status: Available (Custom: $helper)"
else
echo "Helper Status: Configured but command not found: $helper"
fi
;;
esac
print_success "Credentials configured for $url"
else
echo "Configured Helper: None"
echo "Helper Status: Not configured"
print_warning "No credentials configured for $url"
fi
done
}
# Function to check and setup credentials for known Gitea instances # Function to check and setup credentials for known Gitea instances
check_and_setup_known_gitea_credentials() { check_and_setup_known_gitea_credentials() {
print_status "Checking credentials for known Gitea instances..." print_status "Checking credentials for known Gitea instances..."
@@ -469,19 +526,45 @@ prompt_with_default() {
eval "$var_name='$input'" eval "$var_name='$input'"
} }
# Function to parse command line arguments
parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
--checks)
CHECKS_MODE=true
shift
;;
*)
print_error "Unknown option: $1"
echo "Usage: $0 [--checks]"
exit 1
;;
esac
done
}
# Main script # Main script
main() { main() {
echo "========================================" echo "========================================"
echo "Git Repository Setup Script for Gitea" echo "Git Repository Setup Script for Gitea"
echo "========================================" echo "========================================"
echo echo
# Parse command line arguments
parse_args "$@"
# Check if git is installed # Check if git is installed
if ! command_exists git; then if ! command_exists git; then
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
# If checks mode, show status and exit
if [[ "$CHECKS_MODE" == "true" ]]; then
show_gitea_credential_status
exit 0
fi
# Check and setup credentials for known Gitea instances # Check and setup credentials for known Gitea instances
check_and_setup_known_gitea_credentials check_and_setup_known_gitea_credentials