Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Functiond used for ensuring that file passed as argument has UNIX EOL
- ensure_unix_eol(){
- local file=$1
- if [[ $# -eq 0 ]]; then
- echo -e "\nERROR: No arguments passed. Script cannot continue. Exiting...\n"
- exit 1
- elif [[ $# -gt 1 ]]; then
- echo -e "\nERROR: This function takes only one argument. Script cannot continue. Exiting...\n"
- exit 1
- fi
- if [[ -f $file ]]; then
- echo -e "\nINFO: '$file' file found.\n"
- file $file | grep -q CRLF
- if [[ $? -eq 0 ]]; then
- echo -e "\nINFO: Windows EOL (CRLF) detected in the '$file' file. Converting it to UNIX EOL (LF)...\n"
- sed -i 's/\r$//g' $file
- file $file | grep -q CRLF
- if [[ $? -eq 1 ]]; then
- echo -e "\nSUCCESS: Windows EOL (CRLF) -> UNIX EOL (LF) conversion on '$file' file successful. Continuuing...\n"
- else
- echo -e "\nINFO: Windows EOL (CRLF) still present in the '$file'. Interrupting installation...\n"
- exit 1
- fi
- else
- echo -e "\nINFO: UNIX EOL (LF) detected in the '$file' file. Continuuing...\n"
- fi
- else
- echo -e "\nERROR: Could not find '$file'. Installation script cannot continue. Interrupting installation...\n"
- exit 1
- fi
- }
Add Comment
Please, Sign In to add comment