Guest User

Untitled

a guest
Oct 16th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Functiond used for ensuring that file passed as argument has UNIX EOL
  4. ensure_unix_eol(){
  5. local file=$1
  6.  
  7. if [[ $# -eq 0 ]]; then
  8. echo -e "\nERROR: No arguments passed. Script cannot continue. Exiting...\n"
  9. exit 1
  10. elif [[ $# -gt 1 ]]; then
  11. echo -e "\nERROR: This function takes only one argument. Script cannot continue. Exiting...\n"
  12. exit 1
  13. fi
  14.  
  15. if [[ -f $file ]]; then
  16. echo -e "\nINFO: '$file' file found.\n"
  17. file $file | grep -q CRLF
  18. if [[ $? -eq 0 ]]; then
  19. echo -e "\nINFO: Windows EOL (CRLF) detected in the '$file' file. Converting it to UNIX EOL (LF)...\n"
  20. sed -i 's/\r$//g' $file
  21. file $file | grep -q CRLF
  22. if [[ $? -eq 1 ]]; then
  23. echo -e "\nSUCCESS: Windows EOL (CRLF) -> UNIX EOL (LF) conversion on '$file' file successful. Continuuing...\n"
  24. else
  25. echo -e "\nINFO: Windows EOL (CRLF) still present in the '$file'. Interrupting installation...\n"
  26. exit 1
  27. fi
  28. else
  29. echo -e "\nINFO: UNIX EOL (LF) detected in the '$file' file. Continuuing...\n"
  30. fi
  31. else
  32. echo -e "\nERROR: Could not find '$file'. Installation script cannot continue. Interrupting installation...\n"
  33. exit 1
  34. fi
  35. }
Add Comment
Please, Sign In to add comment