diff --git a/docs/contribution/AI.md b/docs/contribution/AI.md new file mode 100644 index 000000000..e69de29bb diff --git a/docs/contribution/setup-fork.sh b/docs/contribution/setup-fork.sh index f140babb9..42acc23d6 100644 --- a/docs/contribution/setup-fork.sh +++ b/docs/contribution/setup-fork.sh @@ -8,13 +8,15 @@ # Updates all hardcoded links to point to your fork # # Usage: -# ./setup-fork.sh # Auto-detect from git config -# ./setup-fork.sh YOUR_USERNAME # Specify username -# ./setup-fork.sh YOUR_USERNAME REPO_NAME # Specify both +# ./setup-fork.sh # Auto-detect from git config (updates misc/ only) +# ./setup-fork.sh YOUR_USERNAME # Specify username (updates misc/ only) +# ./setup-fork.sh YOUR_USERNAME REPO_NAME # Specify both (updates misc/ only) +# ./setup-fork.sh --full # Update all files including ct/, install/, vm/, etc. # # Examples: -# ./setup-fork.sh john # Uses john/ProxmoxVE -# ./setup-fork.sh john my-fork # Uses john/my-fork +# ./setup-fork.sh john # Uses john/ProxmoxVE, updates misc/ only +# ./setup-fork.sh john my-fork # Uses john/my-fork, updates misc/ only +# ./setup-fork.sh --full # Auto-detect + update all files ################################################################################ set -e @@ -30,131 +32,136 @@ NC='\033[0m' # No Color REPO_NAME="ProxmoxVE" USERNAME="" AUTO_DETECT=true +UPDATE_ALL=false ################################################################################ # FUNCTIONS ################################################################################ print_header() { - echo -e "\n${BLUE}╔════════════════════════════════════════════════════════════╗${NC}" - echo -e "${BLUE}║${NC} ProxmoxVE Fork Setup Script" - echo -e "${BLUE}║${NC} Configuring for your fork..." - echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}\n" + echo -e "\n${BLUE}╔════════════════════════════════════════════════════════════╗${NC}" + echo -e "${BLUE}║${NC} ProxmoxVE Fork Setup Script" + echo -e "${BLUE}║${NC} Configuring for your fork..." + echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}\n" } print_info() { - echo -e "${BLUE}ℹ${NC} $1" + echo -e "${BLUE}ℹ${NC} $1" } print_success() { - echo -e "${GREEN}✓${NC} $1" + echo -e "${GREEN}✓${NC} $1" } print_warning() { - echo -e "${YELLOW}⚠${NC} $1" + echo -e "${YELLOW}⚠${NC} $1" } print_error() { - echo -e "${RED}✗${NC} $1" + echo -e "${RED}✗${NC} $1" } # Detect username from git remote detect_username() { - local remote_url + local remote_url - # Try to get from origin - if ! remote_url=$(git config --get remote.origin.url 2>/dev/null); then - return 1 - fi + # Try to get from origin + if ! remote_url=$(git config --get remote.origin.url 2>/dev/null); then + return 1 + fi - # Extract username from SSH or HTTPS URL - if [[ $remote_url =~ git@github.com:([^/]+) ]]; then - echo "${BASH_REMATCH[1]}" - elif [[ $remote_url =~ github.com/([^/]+) ]]; then - echo "${BASH_REMATCH[1]}" - else - return 1 - fi + # Extract username from SSH or HTTPS URL + if [[ $remote_url =~ git@github.com:([^/]+) ]]; then + echo "${BASH_REMATCH[1]}" + elif [[ $remote_url =~ github.com/([^/]+) ]]; then + echo "${BASH_REMATCH[1]}" + else + return 1 + fi } # Detect repo name from git remote detect_repo_name() { - local remote_url + local remote_url - if ! remote_url=$(git config --get remote.origin.url 2>/dev/null); then - return 1 - fi + if ! remote_url=$(git config --get remote.origin.url 2>/dev/null); then + return 1 + fi - # Extract repo name (remove .git if present) - if [[ $remote_url =~ /([^/]+?)(.git)?$ ]]; then - local repo="${BASH_REMATCH[1]}" - echo "${repo%.git}" - else - return 1 - fi + # Extract repo name (remove .git if present) + if [[ $remote_url =~ /([^/]+?)(.git)?$ ]]; then + local repo="${BASH_REMATCH[1]}" + echo "${repo%.git}" + else + return 1 + fi } # Ask user for confirmation confirm() { - local prompt="$1" - local response + local prompt="$1" + local response - read -p "$(echo -e ${YELLOW})$prompt (y/n)${NC} " -r response - [[ $response =~ ^[Yy]$ ]] + echo -ne "${YELLOW}${prompt} (y/n)${NC} " + read -r response + [[ $response =~ ^[Yy]$ ]] } # Update links in files update_links() { - local old_repo="community-scripts" - local old_name="ProxmoxVE" - local new_owner="$1" - local new_repo="$2" - local files_updated=0 + local old_repo="community-scripts" + local old_name="ProxmoxVE" + local new_owner="$1" + local new_repo="$2" + local files_updated=0 - print_info "Scanning for hardcoded links..." + print_info "Scanning for hardcoded links..." - # Find all markdown and shell files - local -a files_to_update=( - "docs/DEFAULTS_SYSTEM_GUIDE.md" - "docs/alpine-install.func.md" - "docs/install.func.md" - "docs/APP-install.md" - "docs/APP-ct.md" - "docs/CONTRIBUTION_GUIDE.md" - "docs/INDEX.md" - "docs/README.md" - "docs/EXIT_CODES.md" - "docs/api/README.md" - ) + # Change to repo root + local repo_root=$(git rev-parse --show-toplevel 2>/dev/null || pwd) - echo "" + # Determine search path + local search_path="$repo_root/misc" + if [[ "$UPDATE_ALL" == "true" ]]; then + search_path="$repo_root" + print_info "Searching all files (--full mode)" + else + print_info "Searching misc/ directory only (core functions)" + fi - for file in "${files_to_update[@]}"; do - if [[ -f "$file" ]]; then - # Count occurrences - local count=$(grep -c "github.com/$old_repo/$old_name" "$file" 2>/dev/null || echo 0) + echo "" - if [[ $count -gt 0 ]]; then - # Backup original - cp "$file" "$file.backup" + # Find all files containing the old repo reference + while IFS= read -r file; do + # Count occurrences + local count=$(grep -c "github.com/$old_repo/$old_name" "$file" 2>/dev/null || echo 0) - # Replace links - sed -i "s|github.com/$old_repo/$old_name|github.com/$new_owner/$new_repo|g" "$file" + if [[ $count -gt 0 ]]; then + # Backup original + cp "$file" "$file.backup" - ((files_updated++)) - print_success "Updated $file ($count links)" - fi - fi - done + # Replace links - use different sed syntax for BSD/macOS vs GNU sed + if sed --version &>/dev/null 2>&1; then + # GNU sed + sed -i "s|github.com/$old_repo/$old_name|github.com/$new_owner/$new_repo|g" "$file" + else + # BSD sed (macOS) + sed -i '' "s|github.com/$old_repo/$old_name|github.com/$new_owner/$new_repo|g" "$file" + fi - return $files_updated + ((files_updated++)) + print_success "Updated $file ($count links)" + fi + done < <(find "$search_path" -type f \( -name "*.md" -o -name "*.sh" -o -name "*.func" -o -name "*.json" \) -not -path "*/.git/*" 2>/dev/null | xargs grep -l "github.com/$old_repo/$old_name" 2>/dev/null) + + return $files_updated } # Create user git config setup info create_git_setup_info() { - local username="$1" + local username="$1" - cat >.git-setup-info <<'EOF' + cat >.git-setup-info <<'EOF' # Git Configuration for ProxmoxVE Development ## Recommended Git Configuration @@ -216,7 +223,7 @@ git merge upstream/main For more help, see: docs/CONTRIBUTION_GUIDE.md EOF - print_success "Created .git-setup-info file" + print_success "Created .git-setup-info file" } ################################################################################ @@ -227,65 +234,79 @@ print_header # Parse command line arguments if [[ $# -gt 0 ]]; then + # Check for --full flag + if [[ "$1" == "--full" ]]; then + UPDATE_ALL=true + AUTO_DETECT=true + shift # Remove --full from arguments + fi + + # Process remaining arguments + if [[ $# -gt 0 ]]; then USERNAME="$1" AUTO_DETECT=false if [[ $# -gt 1 ]]; then - REPO_NAME="$2" + REPO_NAME="$2" fi + fi else - # Try auto-detection - if username=$(detect_username); then - USERNAME="$username" - print_success "Detected GitHub username: $USERNAME" - else - print_error "Could not auto-detect GitHub username from git config" - echo -e "${YELLOW}Please run:${NC}" - echo " ./setup-fork.sh YOUR_USERNAME" - exit 1 - fi + # Try auto-detection + if username=$(detect_username); then + USERNAME="$username" + print_success "Detected GitHub username: $USERNAME" + else + print_error "Could not auto-detect GitHub username from git config" + echo -e "${YELLOW}Please run:${NC}" + echo " ./setup-fork.sh YOUR_USERNAME" + exit 1 + fi - if repo_name=$(detect_repo_name); then - REPO_NAME="$repo_name" - if [[ "$REPO_NAME" != "ProxmoxVE" ]]; then - print_info "Detected custom repo name: $REPO_NAME" - else - print_success "Using default repo name: ProxmoxVE" - fi + if repo_name=$(detect_repo_name); then + REPO_NAME="$repo_name" + if [[ "$REPO_NAME" != "ProxmoxVE" ]]; then + print_info "Detected custom repo name: $REPO_NAME" + else + print_success "Using default repo name: ProxmoxVE" fi + fi fi # Validate inputs if [[ -z "$USERNAME" ]]; then - print_error "Username cannot be empty" - exit 1 + print_error "Username cannot be empty" + exit 1 fi if [[ -z "$REPO_NAME" ]]; then - print_error "Repository name cannot be empty" - exit 1 + print_error "Repository name cannot be empty" + exit 1 fi # Show what we'll do echo -e "${BLUE}Configuration Summary:${NC}" echo " Repository URL: https://github.com/$USERNAME/$REPO_NAME" -echo " Files to update: 10 files with documentation" +if [[ "$UPDATE_ALL" == "true" ]]; then + echo " Files to update: ALL files (ct/, install/, vm/, misc/, docs/, etc.)" +else + echo " Files to update: misc/ directory only (core functions)" +fi echo "" # Ask for confirmation if ! confirm "Apply these changes?"; then - print_warning "Setup cancelled" - exit 0 + print_warning "Setup cancelled" + exit 0 fi echo "" # Update all links if update_links "$USERNAME" "$REPO_NAME"; then - links_changed=$? - print_success "Updated $links_changed files" + links_changed=$? + print_success "Updated $links_changed files" else - print_warning "No links needed updating or some files not found" + print_warning "No links needed updating or some files not found" fi # Create git setup info file