Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

loopback.linkmodels.sh 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/bin/bash
  2. # Function to create symbolic links and copy .js files
  3. manage_files() {
  4. # Define the source (folder a) and destination (folder b)
  5. folder_a="$1"
  6. folder_b="$2"
  7. prefix="$3"
  8. # Ensure both folders exist
  9. if [[ ! -d "$folder_a" ]]; then
  10. echo "Source folder '$folder_a' does not exist!"
  11. return 1
  12. fi
  13. if [[ ! -d "$folder_b" ]]; then
  14. echo "Destination folder '$folder_b' does not exist!"
  15. return 1
  16. fi
  17. # Get the absolute paths of the source and destination folders
  18. abs_folder_a=$(realpath "$folder_a")
  19. abs_folder_b=$(realpath "$folder_b")
  20. # 1. Create symbolic links for files in folder_a to folder_b with absolute paths
  21. for file in "$abs_folder_a"/*; do
  22. # Check if it's a regular file
  23. if [[ -f "$file" ]]; then
  24. filename=$(basename "$file")
  25. destination="$abs_folder_b/$filename"
  26. # Check if the file already exists in folder_b
  27. if [[ ! -e "$destination" ]]; then
  28. # Create a symbolic link in folder_b with absolute paths
  29. ln -s "$3../../node_modules/$1/$filename" "$destination"
  30. echo "Linked '../../node_modules/$1/$filename' to '$destination'"
  31. else
  32. echo "File '$destination' already exists, skipping..."
  33. fi
  34. fi
  35. done
  36. # 2. Remove all symbolic links to .js files in folder_b
  37. find "$abs_folder_b" -type l -name "*.js" -exec rm {} \;
  38. echo "All symbolic links to .js files have been removed."
  39. # 3. Copy missing .js files from folder_a to folder_b
  40. for file in "$abs_folder_a"/*.js; do
  41. # Ensure it is a regular file
  42. if [[ -f "$file" ]]; then
  43. filename=$(basename "$file")
  44. destination="$abs_folder_b/$filename"
  45. # Check if the file already exists in folder_b
  46. if [[ ! -e "$destination" ]]; then
  47. # Copy the .js file from folder_a to folder_b
  48. cp "$file" "$destination"
  49. echo "Copied '$file' to '$destination'"
  50. else
  51. echo "File '$destination' already exists, skipping..."
  52. fi
  53. fi
  54. done
  55. }
  56. find_broken_symlinks() {
  57. local target_dir="${1:-.}"
  58. echo "🔍 Searching for broken symlinks in: $target_dir"
  59. find "$target_dir" -xtype l
  60. }
  61. find_and_delete_broken_symlinks() {
  62. local target_dir="${1:-.}"
  63. echo "🔍 Searching for broken symlinks in: $target_dir"
  64. # Find broken symlinks
  65. local broken_links
  66. broken_links=$(find "$target_dir" -xtype l)
  67. if [[ -z "$broken_links" ]]; then
  68. echo "✅ No broken symlinks found."
  69. return
  70. fi
  71. echo "⚠️ Found the following broken symlinks:"
  72. echo "$broken_links"
  73. echo
  74. # Confirm deletion
  75. read -rp "❓ Do you want to delete these broken symlinks? [y/N] " confirm
  76. if [[ "$confirm" =~ ^[Yy]$ ]]; then
  77. echo "$broken_links" | while read -r link; do
  78. rm "$link" && echo "🗑️ Deleted: $link"
  79. done
  80. else
  81. echo "🚫 Deletion canceled."
  82. fi
  83. }
  84. find_and_delete_broken_symlinks "cihsr-server/cihsr/lib/vmodel"
  85. # Example of calling the function on multiple folder pairs
  86. manage_files "chess-server-lib/common/models" "cihsr-server/cihsr/models" ""
  87. manage_files "chess-server-lib/common/lib/vmodel" "cihsr-server/cihsr/lib/vmodel" "../"
  88. rm "./cihsr-server/cihsr/models/labrtfresult.js"
  89. rm "./cihsr-server/cihsr/models/dataimport.js"
  90. rm "./cihsr-server/cihsr/models/birthcertificate.js"
  91. rm "./cihsr-server/cihsr/models/alternatemap.js"
  92. rm "./cihsr-server/cihsr/models/labcollection.js"
  93. rm "./cihsr-server/cihsr/models/purchasereturn.js"
  94. rm "./cihsr-server/cihsr/models/purchasereturnitem.js"
  95. rm "./cihsr-server/cihsr/models/journalgroup.js"
  96. rm "./cihsr-server/cihsr/models/sageopbill.js"
  97. rm "./cihsr-server/cihsr/models/elixirlaborder.js"
  98. rm "./cihsr-server/cihsr/models/pacsorderitem.js"
  99. # cp "chess-server-lib/common/models/billablepackage.js" "./cihsr-server/cihsr/models/billablepackage.js"