Skip to content
Snippets Groups Projects
Commit 3ddfe98f authored by Montaño Sarria, Andres Felipe's avatar Montaño Sarria, Andres Felipe
Browse files

Add .rosinstall and .repos to substitution options

parent 4ef4fbaa
Branches
No related tags found
No related merge requests found
...@@ -15,6 +15,14 @@ ...@@ -15,6 +15,14 @@
"launch_rviz:=false" "launch_rviz:=false"
], ],
"type": "ros" "type": "ros"
},
{
"type": "bashdb",
"request": "launch",
"name": "Bash simple",
"cwd": "${workspaceFolder}",
"program": "${file}",
"terminalKind": "integrated"
} }
] ]
} }
\ No newline at end of file
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# Updates Git remote URLs by replacing 'tecnalia.com' with 'tecnalia.dev' # Updates URLs by replacing 'tecnalia.com' with 'tecnalia.dev' in:
# recursively in all Git repositories under the current directory # - Git repository remotes
# - .rosinstall files
# - .repos files
# #
set -e pipefail # Keep error handling but remove -u flag # set -e
# set -euo pipefail
# Color definitions for better readability # Color definitions for better readability
readonly GREEN='\033[0;32m' readonly GREEN='\033[0;32m'
...@@ -13,11 +16,15 @@ readonly BLUE='\033[0;34m' ...@@ -13,11 +16,15 @@ readonly BLUE='\033[0;34m'
readonly NC='\033[0m' # No Color readonly NC='\033[0m' # No Color
usage() { usage() {
echo "Usage: $(basename "$0") [-d|--dry-run] [-m|--max-depth N]" echo "Usage: $(basename "$0") [-d|--dry-run] [-m|--max-depth N] [-t|--type TYPE]"
echo "Options:" echo "Options:"
echo " -d, --dry-run Show changes without applying them" echo " -d, --dry-run Show changes without applying them"
echo " -m, --max-depth N Maximum depth for recursive search (default: unlimited)" echo " -m, --max-depth N Maximum depth for recursive search (default: unlimited)"
echo " Use 1 for current directory only" echo " Use 1 for current directory only"
echo " -t, --type TYPE Specify which types of files to process:"
echo " git - only process Git remotes"
echo " repos - only process .rosinstall and .repos files"
echo " all - process all files (default)"
echo " -h, --help Show this help message" echo " -h, --help Show this help message"
exit 1 exit 1
} }
...@@ -25,6 +32,7 @@ usage() { ...@@ -25,6 +32,7 @@ usage() {
# Improved argument processing # Improved argument processing
dry_run=0 dry_run=0
max_depth="" max_depth=""
file_type="all"
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
...@@ -41,6 +49,15 @@ while [[ $# -gt 0 ]]; do ...@@ -41,6 +49,15 @@ while [[ $# -gt 0 ]]; do
usage usage
fi fi
;; ;;
-t|--type)
if [[ "${2:-}" =~ ^(git|repos|all)$ ]]; then
file_type=$2
shift 2
else
echo "Error: --type must be 'git', 'repos', or 'all'"
usage
fi
;;
-h|--help) -h|--help)
usage usage
;; ;;
...@@ -73,42 +90,124 @@ process_repo() { ...@@ -73,42 +90,124 @@ process_repo() {
if [[ ${dry_run} -eq 0 ]]; then if [[ ${dry_run} -eq 0 ]]; then
if git -C "${repo_path}" remote set-url "${remote}" "${new_url}"; then if git -C "${repo_path}" remote set-url "${remote}" "${new_url}"; then
echo -e " ${GREEN}Replacement completed!${NC}" echo -e " ${GREEN}Replacement completed!${NC}"
return 0
else else
echo " Error updating remote URL" >&2 echo " Error updating remote URL" >&2
return 1 return 1
fi fi
fi fi
return 0
fi fi
return 2 # No changes needed
} }
main() { # Function to process .rosinstall and .repos files
local count=0 process_config_file() {
local errors=0 local file=$1
local repos_found=0 local file_type=$2
local changes_made=0
local temp_file
echo -e "${BLUE}Starting recursive search for Git repositories...${NC}" echo -e "${BLUE}Processing ${file_type} file: ${file}${NC}"
# Use process substitution for better handling of spaces in names # Create temporary file in the same directory to preserve permissions
while IFS= read -r -d '' git_folder || [ -n "$git_folder" ]; do temp_file="${file}.tmp"
((repos_found++))
repo_path=$(dirname "$(readlink -f "${git_folder}")")
echo -e "${BLUE}Processing repository: ${repo_path}${NC}"
while IFS= read -r remote || [ -n "$remote" ]; do if [[ -f "$file" ]]; then
if process_repo "${repo_path}" "${remote}"; then if grep -q "tecnalia.com" "$file"; then
((count++)) echo -e "${YELLOW}Found deprecated URLs in: ${file}${NC}"
if [[ ${dry_run} -eq 0 ]]; then
# Create backup
cp "$file" "${file}.bak"
# Replace URLs
sed 's/tecnalia.com/tecnalia.dev/g' "$file" > "$temp_file"
# Show diff
echo "Changes made:"
diff "$file" "$temp_file" || true
# Replace original file
mv "$temp_file" "$file"
echo -e " ${GREEN}Replacement completed!${NC}"
echo " Backup saved as: ${file}.bak"
changes_made=1
else else
((errors++)) echo "Changes that would be made:"
sed 's/tecnalia.com/tecnalia.dev/g' "$file" | diff "$file" - || true
changes_made=1
fi fi
done < <(git -C "${repo_path}" remote 2>/dev/null || echo "") fi
fi
done < <(find . ${max_depth:-} -name '.git' -type d -print0 2>/dev/null || echo "") # Clean up temporary file if it exists
[[ -f "$temp_file" ]] && rm "$temp_file"
return $changes_made
}
main() {
local git_count=0
local rosinstall_count=0
local repos_count=0
local errors=0
local repos_found=0
local config_files_found=0
echo -e "${BLUE}Starting recursive search for specified file types...${NC}"
# Process Git repositories
if [[ $file_type == "git" || $file_type == "all" ]]; then
echo -e "${BLUE}Looking for Git repositories...${NC}"
while IFS= read -r -d '' git_folder || [ -n "$git_folder" ]; do
((repos_found++))
repo_path=$(dirname "$(readlink -f "${git_folder}")")
echo -e "${BLUE}Processing repository: ${repo_path}${NC}"
while IFS= read -r remote || [ -n "$remote" ]; do
result=$(process_repo "${repo_path}" "${remote}")
case $? in
0) ((git_count++));;
1) ((errors++));;
esac
done < <(git -C "${repo_path}" remote 2>/dev/null || echo "")
done < <(find . ${max_depth:-} -name '.git' -type d -print0 2>/dev/null || echo "")
fi
# Process config files
if [[ $file_type == "repos" || $file_type == "all" ]]; then
echo -e "${BLUE}Looking for configuration files...${NC}"
# Process .rosinstall files
while IFS= read -r -d '' rosinstall_file || [ -n "$rosinstall_file" ]; do
((config_files_found++))
if process_config_file "$rosinstall_file" ".rosinstall"; then
((rosinstall_count++))
fi
done < <(find . ${max_depth:-} -name '*.rosinstall' -type f -print0 2>/dev/null || echo "")
# Process .repos files
while IFS= read -r -d '' repos_file || [ -n "$repos_file" ]; do
((config_files_found++))
if process_config_file "$repos_file" ".repos"; then
((repos_count++))
fi
done < <(find . ${max_depth:-} -name '*.repos' -type f -print0 2>/dev/null || echo "")
fi
# Final summary # Final summary
echo echo
echo "Execution summary:" echo "Execution summary:"
echo " Git repositories found: $repos_found" if [[ $file_type == "git" || $file_type == "all" ]]; then
echo " Repositories processed: $count" echo " Git repositories found: $repos_found"
echo " Git remotes updated: $git_count"
fi
if [[ $file_type == "config" || $file_type == "all" ]]; then
echo " Configuration files found: $config_files_found"
echo " .rosinstall files updated: $rosinstall_count"
echo " .repos files updated: $repos_count"
fi
[[ $errors -gt 0 ]] && echo " Errors found: $errors" [[ $errors -gt 0 ]] && echo " Errors found: $errors"
[[ $dry_run -eq 1 ]] && echo " (Dry-run mode: no changes were made)" [[ $dry_run -eq 1 ]] && echo " (Dry-run mode: no changes were made)"
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment