Enhance repository discovery in README and setup script. Implement API access for fetching all accessible repositories, including owned, shared, and public repos. Add fallback method for pattern scanning and improve user feedback during repository selection.
This commit is contained in:
51
README.md
51
README.md
@@ -42,21 +42,31 @@ The script prompts for your git username, which is used to:
|
|||||||
- Displays the public key for copying to your git account
|
- Displays the public key for copying to your git account
|
||||||
|
|
||||||
### 3. Repository Discovery
|
### 3. Repository Discovery
|
||||||
The script automatically checks for common repository patterns:
|
The script discovers ALL accessible repositories through multiple methods:
|
||||||
- `username/dotfiles`
|
|
||||||
- `username/scripts`
|
**Primary Method - API Access:**
|
||||||
- `username/configs`
|
- Attempts to use GitLab/Gitea API to fetch all repositories you have access to
|
||||||
- `username/tools`
|
- Includes both owned and shared repositories
|
||||||
- `username/projects`
|
- Automatically detects read/write permissions
|
||||||
- `username/notes`
|
|
||||||
- `username/backup`
|
**Fallback Method - Pattern Scanning:**
|
||||||
- `username/workspace`
|
- Scans your own repositories: `username/dotfiles`, `username/scripts`, etc.
|
||||||
|
- Checks common shared repositories from users like: `admin`, `shared`, `public`, `team`, `common`, `devops`, `infrastructure`
|
||||||
|
- Discovers additional project repositories: `website`, `api`, `frontend`, `backend`, `database`, `monitoring`, etc.
|
||||||
|
- Tests SSH access to determine if you have read access to each repository
|
||||||
|
|
||||||
|
**Repository Types Discovered:**
|
||||||
|
- **Your repositories**: All repos you own
|
||||||
|
- **Shared repositories**: Repos you have read/write access to
|
||||||
|
- **Public repositories**: Publicly accessible repos on the server
|
||||||
|
- **Team repositories**: Organization/team repos you're a member of
|
||||||
|
|
||||||
### 4. Repository Selection
|
### 4. Repository Selection
|
||||||
Users can:
|
Users can:
|
||||||
- Select from numbered list of discovered repositories
|
- Select from numbered list of all discovered repositories (owned and shared)
|
||||||
- Press Enter to use `username/dotfiles` (if available)
|
- Press Enter to use `username/dotfiles` (if available)
|
||||||
- Type `custom` to enter a custom repository path
|
- Type `custom` to enter a custom repository path
|
||||||
|
- See access type indicators: `(owner)`, `(shared)`, etc.
|
||||||
|
|
||||||
### 5. Cloning and Setup
|
### 5. Cloning and Setup
|
||||||
- Clones the selected repository to the appropriate directory
|
- Clones the selected repository to the appropriate directory
|
||||||
@@ -101,23 +111,26 @@ ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGx... john@example.com
|
|||||||
----------------------------------------
|
----------------------------------------
|
||||||
Press Enter after you've added the key...
|
Press Enter after you've added the key...
|
||||||
|
|
||||||
[+] Fetching available git projects for user: john...
|
[+] Fetching all accessible git projects...
|
||||||
[*] Available repositories:
|
[*] Attempting to fetch repositories via API...
|
||||||
1. john/dotfiles
|
[*] Found repositories via API:
|
||||||
2. john/scripts
|
1. john/dotfiles (owner)
|
||||||
3. john/tools
|
2. john/scripts (owner)
|
||||||
|
3. team/shared-configs (shared)
|
||||||
|
4. admin/common-tools (shared)
|
||||||
|
5. public/templates (shared)
|
||||||
|
|
||||||
[?] Which project would you like to download?
|
[?] Which project would you like to download?
|
||||||
Enter the number of the repository from the list above, or:
|
Enter the number of the repository from the list above, or:
|
||||||
- Press Enter to use john/dotfiles (if available)
|
- Press Enter to use john/dotfiles (if available)
|
||||||
- Type 'custom' to enter a custom repository path
|
- Type 'custom' to enter a custom repository path
|
||||||
|
|
||||||
Enter your choice: 1
|
Enter your choice: 3
|
||||||
[*] Selected repository: git@git.del-c.net:john/dotfiles.git
|
[*] Selected repository: git@git.del-c.net:team/shared-configs.git
|
||||||
[*] Download directory: /Users/john/.dotfiles
|
[*] Download directory: /Users/john/shared-configs
|
||||||
|
|
||||||
[+] Cloning selected repository...
|
[+] Cloning selected repository...
|
||||||
[+] Launching dotfiles setup using Bash...
|
[*] Repository cloned successfully to: /Users/john/shared-configs
|
||||||
```
|
```
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|||||||
93
setup.sh
93
setup.sh
@@ -46,27 +46,106 @@ show_ssh_key() {
|
|||||||
|
|
||||||
### === LIST AVAILABLE GIT PROJECTS === ###
|
### === LIST AVAILABLE GIT PROJECTS === ###
|
||||||
list_git_projects() {
|
list_git_projects() {
|
||||||
echo "[+] Fetching available git projects for user: $USERNAME..."
|
echo "[+] Fetching all accessible git projects..."
|
||||||
|
|
||||||
# Get list of repositories using git ls-remote
|
|
||||||
echo "[*] Available repositories:"
|
|
||||||
|
|
||||||
local repo_count=1
|
local repo_count=1
|
||||||
local found_repos=()
|
local found_repos=()
|
||||||
|
|
||||||
# Check for common repository patterns
|
# Try to use git server API if available (GitLab/Gitea style)
|
||||||
|
if command -v curl &> /dev/null; then
|
||||||
|
echo "[*] Attempting to fetch repositories via API..."
|
||||||
|
|
||||||
|
# Try GitLab API format
|
||||||
|
local gitlab_repos=$(curl -s -H "Authorization: Bearer $(ssh-add -L 2>/dev/null || echo '')" \
|
||||||
|
"https://$GIT_SERVER/api/v4/projects?membership=true&per_page=100" 2>/dev/null | \
|
||||||
|
grep -o '"path_with_namespace":"[^"]*' | cut -d'"' -f4 2>/dev/null || echo "")
|
||||||
|
|
||||||
|
# Try Gitea API format
|
||||||
|
if [ -z "$gitlab_repos" ]; then
|
||||||
|
local gitea_repos=$(curl -s "https://$GIT_SERVER/api/v1/user/repos" 2>/dev/null | \
|
||||||
|
grep -o '"full_name":"[^"]*' | cut -d'"' -f4 2>/dev/null || echo "")
|
||||||
|
gitlab_repos="$gitea_repos"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$gitlab_repos" ]; then
|
||||||
|
echo "[*] Found repositories via API:"
|
||||||
|
while IFS= read -r repo; do
|
||||||
|
if [ -n "$repo" ]; then
|
||||||
|
echo "$repo_count. $repo"
|
||||||
|
found_repos+=("$repo")
|
||||||
|
((repo_count++))
|
||||||
|
fi
|
||||||
|
done <<< "$gitlab_repos"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Fallback: Check common patterns for multiple users and the current user
|
||||||
|
if [ ${#found_repos[@]} -eq 0 ]; then
|
||||||
|
echo "[*] API not available, scanning common repository patterns..."
|
||||||
|
|
||||||
|
# Check user's own repositories first
|
||||||
for repo in "dotfiles" "scripts" "configs" "tools" "projects" "notes" "backup" "workspace"; do
|
for repo in "dotfiles" "scripts" "configs" "tools" "projects" "notes" "backup" "workspace"; do
|
||||||
local full_repo="$USERNAME/$repo"
|
local full_repo="$USERNAME/$repo"
|
||||||
if git ls-remote "git@$GIT_SERVER:$full_repo.git" &>/dev/null; then
|
if git ls-remote "git@$GIT_SERVER:$full_repo.git" &>/dev/null; then
|
||||||
echo "$repo_count. $full_repo"
|
echo "$repo_count. $full_repo (owner)"
|
||||||
found_repos+=("$full_repo")
|
found_repos+=("$full_repo")
|
||||||
((repo_count++))
|
((repo_count++))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Check common shared repositories and other users' public repos
|
||||||
|
local common_users=("admin" "shared" "public" "team" "common" "devops" "infrastructure")
|
||||||
|
local common_repos=("dotfiles" "scripts" "configs" "tools" "projects" "notes" "backup" "workspace" "templates" "shared-configs" "common-tools")
|
||||||
|
|
||||||
|
for user in "${common_users[@]}"; do
|
||||||
|
for repo in "${common_repos[@]}"; do
|
||||||
|
local full_repo="$user/$repo"
|
||||||
|
if [ "$user" != "$USERNAME" ] && git ls-remote "git@$GIT_SERVER:$full_repo.git" &>/dev/null; then
|
||||||
|
echo "$repo_count. $full_repo (shared)"
|
||||||
|
found_repos+=("$full_repo")
|
||||||
|
((repo_count++))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
# Try to discover repositories by checking SSH access to common paths
|
||||||
|
echo "[*] Checking for additional accessible repositories..."
|
||||||
|
|
||||||
|
# This is a more aggressive approach - try common project names
|
||||||
|
local project_names=("website" "api" "frontend" "backend" "database" "monitoring" "deployment" "ci-cd" "documentation")
|
||||||
|
for user in "${common_users[@]}" "$USERNAME"; do
|
||||||
|
for project in "${project_names[@]}"; do
|
||||||
|
local full_repo="$user/$project"
|
||||||
|
if git ls-remote "git@$GIT_SERVER:$full_repo.git" &>/dev/null 2>&1; then
|
||||||
|
# Check if we haven't already added this repo
|
||||||
|
local already_added=false
|
||||||
|
for existing_repo in "${found_repos[@]}"; do
|
||||||
|
if [ "$existing_repo" = "$full_repo" ]; then
|
||||||
|
already_added=true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$already_added" = false ]; then
|
||||||
|
local access_type="shared"
|
||||||
|
if [ "$user" = "$USERNAME" ]; then
|
||||||
|
access_type="owner"
|
||||||
|
fi
|
||||||
|
echo "$repo_count. $full_repo ($access_type)"
|
||||||
|
found_repos+=("$full_repo")
|
||||||
|
((repo_count++))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ${#found_repos[@]} -eq 0 ]; then
|
if [ ${#found_repos[@]} -eq 0 ]; then
|
||||||
echo "[!] No repositories found for user: $USERNAME"
|
echo "[!] No accessible repositories found"
|
||||||
echo "[*] You can still enter a custom repository path."
|
echo "[*] You can still enter a custom repository path."
|
||||||
|
else
|
||||||
|
echo
|
||||||
|
echo "[*] Found ${#found_repos[@]} accessible repositories"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|||||||
Reference in New Issue
Block a user