Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #If a user omits either of the two arguments it displays a helpful message and terminates.
  4. if [ $# -ne 2 ]; then
  5. echo "usage: Phar image_path archive_path"
  6. exit
  7. fi
  8.  
  9. #If the archive directory does not exist the scripts creates it.
  10. if [ ! -d "$2" ]; then
  11. mkdir "$2"
  12. fi
  13.  
  14. #If the image source directory does not exist the script reports this error and terminates.
  15. if [ ! -d "$1" ]; then
  16. echo "source directory does not exist"
  17. exit
  18. fi
  19.  
  20. #Loops through every file in $1 that matches 'IMG_[0-9][0-9][0-9][0-9]\.JPG'.
  21. while in "$(find "$1" -name 'IMG_[0-9][0-9][0-9][0-9]\.JPG')";do
  22. filename=${-12}
  23. echo "lll"
  24.  
  25. #If statement is used to check if there is a file in $2 that matches filename. And if it does not it copies to $2.
  26. #readlink gets the absolute path of the duplicate and sends it duplicate text file.
  27. #if there is already a file with that name but not identical it adds .jpg to avoid overwriting it.
  28. if [ ! -e "${2}"/"${filename}" ];
  29. then cp -- "$" "$2"
  30. echo "$filename is being copied";
  31. else
  32. if cmp "$" "$2"/"$filename"; then
  33. echo "rrrr"
  34. readlink -f "$" >> "$2"/duplicates.txt
  35. else cp "$" "$.JPG"
  36. mv "$".JPG "$2"
  37. fi
  38. fi
  39. done
  40.  
  41. #
  42. if [[ $$ -gt 2 ]]; then
  43. echo "Can not run more than one process at a time"
  44. exit
  45. fi
  46.  
  47.  
  48. if expr match "$1" "$2">/dev/null; then
  49. echo "error"
  50. exit
  51.  
  52. elif expr match "$2" "$1" >/dev/null; then
  53. echo "error"
  54. exit
  55. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement