Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

loopback.linkmodels.sh 3.7KB

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