Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support wpa_supplicant.conf.txt, convert DOS line endings to UNIX to keep wpa_supplicant happy #4

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

ghost
Copy link

@ghost ghost commented Sep 18, 2020

Inspired by the variant handling of ssh and ssh.txt, and raspberrypi/documentation#1672, let's make the process of providing a custom wpa_supplicant.conf via the boot filesystem a little easier and support the case where the user has unwittingly created the file as wpa_supplicant.conf.txt.

Tested on Raspberry Pi OS. I also looked up whether the long line would work OK in systemd - there seems to be a 2048 character line length limit, which this unit file is nowhere near.

My rationale is that it is currently somewhat tricky to get the wpa_supplicant.conf file created and working correctly. Taking this, and line wrap conversion out of the hands of the user will remove two of the gotchas. The other gotcha is getting the right incantations in the file for the particular version of wpa_supplicant we are using.

@ghost
Copy link
Author

ghost commented Sep 19, 2020

This would also handle the same issue where the user creates the wpa_supplicant.conf file on macOS, since it also appends .txt to the filename - see raspberrypi/documentation#1672 (comment).

@ghost
Copy link
Author

ghost commented Sep 19, 2020

It should also be fairly easy to convert from DOS newlines to Unix newlines. The solution is probably not dos2unix, since that also does codespace conversion.

@lurch
Copy link

lurch commented Sep 19, 2020

The solution is probably not dos2unix, since that also does codespace conversion.

https://stackoverflow.com/questions/2613800/how-to-convert-dos-windows-newline-crlf-to-unix-newline-lf-in-a-bash-script has lots of different alternatives.
Although I'm not sure how much "magic" it's worth trying to squeeze into the systemd file? I'll leave it up to @XECDesign and @spl237 to decide.

@ghost
Copy link
Author

ghost commented Sep 19, 2020

The solution is probably not dos2unix, since that also does codespace conversion.

https://stackoverflow.com/questions/2613800/how-to-convert-dos-windows-newline-crlf-to-unix-newline-lf-in-a-bash-script has lots of different alternatives.
Although I'm not sure how much "magic" it's worth trying to squeeze into the systemd file? I'll leave it up to @XECDesign and @spl237 to decide.

I was referring to doing automatic linewrap conversion on the wpa_supplicant.conf{,.txt} file when we copy it across from the boot filesystem.

@ghost
Copy link
Author

ghost commented Sep 19, 2020

The solution is probably not dos2unix, since that also does codespace conversion.

https://stackoverflow.com/questions/2613800/how-to-convert-dos-windows-newline-crlf-to-unix-newline-lf-in-a-bash-script has lots of different alternatives.
Although I'm not sure how much "magic" it's worth trying to squeeze into the systemd file? I'll leave it up to @XECDesign and @spl237 to decide.

It doesn't really matter if the shell commands are embedded in the unit file, or whether they are in the form of a separate shell script. I'm not sure which is actually easier, since the code is more readable on multiple lines, but putting it into the unit file saves having to have another file somewhere.

@lurch
Copy link

lurch commented Sep 20, 2020

Just in case you missed my earlier comment: (the way GH auto-hides some comments can be a bit too aggressive IMHO)
I've not tested this modification myself, but do any of the double-quotes need to be escaped? Why are double-quotes-around-filenames used in some places but not others?

@lurch
Copy link

lurch commented Sep 20, 2020

I was referring to doing automatic linewrap conversion on the wpa_supplicant.conf{,.txt} file when we copy it across from the boot filesystem.

Yup, I knew exactly that's what you were referring to 🙂

I'm not sure which is actually easier, since the code is more readable on multiple lines, but putting it into the unit file saves having to have another file somewhere.

And yup, that's exactly the decision I was deferring to Serge or Simon 😀 (since they'll be the ones maintaining this)

@ghost
Copy link
Author

ghost commented Sep 20, 2020

The unit file worked as I have written it - the cut and paste was to get it into github as I'm not running it locally.

@XECDesign
Copy link
Member

Good change and good suggestions. I would separate it out into a secondary script that lives in /usr/lib/raspberrypi-net-mods/, since it's getting a bit too long.

I don't understand the issue with using dos2unix, so I can't really comment on that, but I'm happy with whatever works.

I can make the changes myself later of pull them in if you get to them first.

@ghost
Copy link
Author

ghost commented Sep 21, 2020

I don't understand the issue with using dos2unix, so I can't really comment on that, but I'm happy with whatever works.

It turns out there isn't one - I had misread the docs.

@ghost
Copy link
Author

ghost commented Sep 21, 2020

OK, that's this ready to go. Because of occasional problems I've seen with some Mac users seeing unexpected characters, in the form of specific left and right single quotes, getting inserted in place of single quotation marks, I've asked dos2unix to perform a conversion to 7-bit ASCII. This is just as likely to mangle those characters, but that will at least make it obvious upon inspection that the character should not be there, although if the user can't get onto the machine then of course this won't really be much help.

@ghost
Copy link
Author

ghost commented Sep 21, 2020

Fixed typo in unit file after testing.

@lurch
Copy link

lurch commented Sep 22, 2020

I've asked dos2unix to perform a conversion to 7-bit ASCII

Could that also cause problems if the user has "unusual" characters in their wifi password? 🤷‍♂️

@ghost
Copy link
Author

ghost commented Sep 22, 2020

I've asked dos2unix to perform a conversion to 7-bit ASCII

Could that also cause problems if the user has "unusual" characters in their wifi password? 🤷‍♂️

Good point. From memory wpasupplicant expects the psk to be ASCII, which could be 7 or 8 bit. I shall remove the -7 flag.

@ghost
Copy link
Author

ghost commented Sep 22, 2020

This is now complete, I think, and I have addressed lurch's review comment. I still need to test this as a package. Please do not integrate this until I do.

@ghost ghost changed the title Handle case where user has unwittingly created wpa_supplicant.conf.txt WIP: Handle case where user has unwittingly created wpa_supplicant.conf.txt Sep 22, 2020
@ghost ghost changed the title WIP: Handle case where user has unwittingly created wpa_supplicant.conf.txt WIP: support wpa_supplicant.conf.txt, convert DOS line endings to UNIX to keep wpa_supplicant happy Sep 22, 2020
@ghost
Copy link
Author

ghost commented Sep 22, 2020

Note that this pulls in a new package to the default install of Raspberry Pi OS, namely dos2unix. If this is a problem, I can probably come up with some shell magic, or find an alternative utility that is already installed by default.

@ghost
Copy link
Author

ghost commented Sep 22, 2020

OK, I've tested the package as working on my Pi. It should therefore be safe to integrate.

@ghost ghost changed the title WIP: support wpa_supplicant.conf.txt, convert DOS line endings to UNIX to keep wpa_supplicant happy Support wpa_supplicant.conf.txt, convert DOS line endings to UNIX to keep wpa_supplicant happy Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants