sync-libs-symlinks.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/bash
  2. # Root gradle directory containing the original libs.versions.toml
  3. root_gradle_dir="gradle"
  4. root_libs_versions_file="${root_gradle_dir}/libs.versions.toml"
  5. # Check if the root libs.versions.toml file exists
  6. if [ ! -f "$root_libs_versions_file" ]; then
  7. echo "Root libs.versions.toml file not found in ${root_gradle_dir}. Exiting."
  8. exit 1
  9. fi
  10. # Find all subdirectories named "gradle"
  11. find . -type d -name "gradle" | while read -r gradle_dir; do
  12. # Skip the root gradle directory
  13. if [ "$gradle_dir" != "./$root_gradle_dir" ]; then
  14. # Target file in the subdirectory
  15. target_file="${gradle_dir}/libs.versions.toml"
  16. # Remove the target file if it already exists
  17. if [ -f "$target_file" ] || [ -L "$target_file" ]; then
  18. rm -f "$target_file"
  19. fi
  20. # Calculate the relative path from the subdirectory to the root libs.versions.toml
  21. relative_path=$(realpath --relative-to="$gradle_dir" "$root_libs_versions_file")
  22. # Create a symbolic link
  23. ln -s "$relative_path" "$target_file"
  24. echo "Created symlink: ${target_file} -> ${relative_path}"
  25. fi
  26. done