al-caughey / YAMon-v4

Official repository for YAMon v4
https://usage-monitoring.com
64 stars 21 forks source link

Carriage returns in .sh files when unzipped on Windows machines #35

Open beneix opened 3 years ago

beneix commented 3 years ago

I was unable to get the install to work on my DD-WRT router. Trying to execute the setup script just rendered "not found". Eventually, I figured out (by looking at the file through vi) that there were extraneous carriage returns ("^M") at the end of every line. I removed these using sed -i 's/\r//g' *.sh and everything worked fine after this. I assume the carriage returns had been generated when I unzipped the file on my Windows machine, before using PSCP to transfer it to the router.

Unless my setup somehow is weird, perhaps it would be worth including something about this in the installation instructions?

pkerney commented 3 years ago

Not just Windows. I thought that too so I redid it all on Ubuntu Linux. The files in the manual install are ALL windows format. I installed tofrolinux and ran them all through fromdos. I couldn't get the latest installer script to work at all. All the downloads have redirect HTML in them so had to go to manual mode.

electricmessiah commented 2 years ago

I ran into the same issues, and copied the manual install files. I can't get the setup4.0.7.sh to work either on OpenWRT. It returns a bunch of errors. Any tips?

pkerney commented 2 years ago

Wasn't working so I had another crack at it a few days ago. I downloaded the manual install zip, unzipped on the router, wrote a script in the router to put all the files through a ^M removal process (below, 'tr' command stolen from a website, or use the 'sed' command above from beneix) and then ran the setup4.0.7.sh. Some files were Unix format, some were Windows format, so I just did them all anyway. I had to install into /tmp/mnt/sda1/YAMon4 (due to automount requirements) and made sure "/tmp/mnt/sda1/YAMon4/start.sh 'reboot'" was added to Administration->Commands->Startup in DD-WRT. It's running now, but I haven't rebooted the router yet. Should be OK.

#!/bin/bash
for f in $( find YAMon4 -type f ); do
        echo $f
        tr -d '\15\32' < $f > unixfile.txt
        rm -f $f
        mv unixfile.txt $f
done
AmateurCoder105 commented 1 year ago

Whenever you extract a zip archive containing UNIX formatted text files onto a Windows system, Windows inserts carriage returns into them, effectively corrupting the scripts. I was able to fix this problem using the dos2unix utility which is available on sourceforge (https://sourceforge.net/projects/dos2unix/). I downloaded and extracted the zip archive on my laptop -- I had to use this method because wget wasn't working for me. You run this on Windows (it also supports MAC) and you want to run it to recursively convert all text files. Then I used winscp to copy the entire file structure to the USB drive while it was connected to my router. Afterwards, I was able to run the setup program.