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
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,14 @@
"launch_rviz:=false"
],
"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
#
# Updates Git remote URLs by replacing 'tecnalia.com' with 'tecnalia.dev'
# recursively in all Git repositories under the current directory
# Updates URLs by replacing 'tecnalia.com' with 'tecnalia.dev' in:
# - 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
readonly GREEN='\033[0;32m'
......@@ -13,11 +16,15 @@ readonly BLUE='\033[0;34m'
readonly NC='\033[0m' # No Color
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 " -d, --dry-run Show changes without applying them"
echo " -m, --max-depth N Maximum depth for recursive search (default: unlimited)"
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"
exit 1
}
......@@ -25,6 +32,7 @@ usage() {
# Improved argument processing
dry_run=0
max_depth=""
file_type="all"
while [[ $# -gt 0 ]]; do
case $1 in
......@@ -41,6 +49,15 @@ while [[ $# -gt 0 ]]; do
usage
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)
usage
;;
......@@ -73,42 +90,124 @@ process_repo() {
if [[ ${dry_run} -eq 0 ]]; then
if git -C "${repo_path}" remote set-url "${remote}" "${new_url}"; then
echo -e " ${GREEN}Replacement completed!${NC}"
return 0
else
echo " Error updating remote URL" >&2
return 1
fi
fi
return 0
fi
return 2 # No changes needed
}
main() {
local count=0
local errors=0
local repos_found=0
# Function to process .rosinstall and .repos files
process_config_file() {
local file=$1
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
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}"
# Create temporary file in the same directory to preserve permissions
temp_file="${file}.tmp"
while IFS= read -r remote || [ -n "$remote" ]; do
if process_repo "${repo_path}" "${remote}"; then
((count++))
if [[ -f "$file" ]]; then
if grep -q "tecnalia.com" "$file"; then
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
((errors++))
echo "Changes that would be made:"
sed 's/tecnalia.com/tecnalia.dev/g' "$file" | diff "$file" - || true
changes_made=1
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
echo
echo "Execution summary:"
echo " Git repositories found: $repos_found"
echo " Repositories processed: $count"
if [[ $file_type == "git" || $file_type == "all" ]]; then
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"
[[ $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.
Finish editing this message first!
Please register or to comment