You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

loopback.linkmodels.sh 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "$file" "$destination"
  29. echo "Linked '$file' 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. # Example of calling the function on multiple folder pairs
  56. manage_files "./chess-server-lib/common/models" "./cihsr-server/cihsr/models"
  57. manage_files "./chess-server-lib/common/lib/vmodel" "./cihsr-server/cihsr/lib/vmodel"
  58. rm "./cihsr-server/cihsr/models/labrtfresult.js"
  59. rm "./cihsr-server/cihsr/models/dataimport.js"
  60. rm "./cihsr-server/cihsr/models/birthcertificate.js"
  61. rm "./cihsr-server/cihsr/models/alternatemap.js"
  62. rm "./cihsr-server/cihsr/models/labcollection.js"
  63. rm "./cihsr-server/cihsr/models/purchasereturn.js"
  64. rm "./cihsr-server/cihsr/models/purchasereturnitem.js"
  65. rm "./cihsr-server/cihsr/models/journalgroup.js"
  66. rm "./cihsr-server/cihsr/models/sageopbill.js"
  67. rm "./cihsr-server/cihsr/models/elixirlaborder.js"
  68. rm "./cihsr-server/cihsr/models/pacsorderitem.js"